API References

This part of the documentation covers all the interfaces of Maritest. Only written to the most important part

Http Client

class maritest.client.Http(method: str, url: str, logger: bool = True, event_hooks: bool = False, retry: bool = True, headers: Optional[dict] = None, allow_redirects: Optional[bool] = None, suppress_warning: Optional[bool] = None, proxy: Optional[dict] = None, data: Optional[dict] = None, params: Optional[dict] = None, files: Optional[dict] = None, auth: Optional[Tuple] = None, json: Optional[dict] = None, timeout: Optional[float] = None)

This is a base class for HTTP client. Constructor for request HTTP target, with several parameter to construct it :

Parameters:
  • method – HTTP method verb, string type. such as: “GET”, “POST”, and other supported HTTP method

  • url – base url for HTTP target, string type

  • headers – HTTP content headers, by default always set to dict object

  • allow_redirects – Enable redirection to other HTTP target if previous one wasn’t respond it. set None

  • logger – Logger stream handler with formatted output of message, by default set True

  • event_hooks – Given valid response, by default set to False

  • retry – Enable retry mechanism with default total attempts up-to 3, by default set to True

  • suppress_warning – Verification of SSL certificate, if set False, will suppressed warning message

  • proxy – HTTP proxies configuration, by default always set to None, and must be configured in HTTPS

  • auth – Authentication configuration for using HTTP client, by default set to None

  • data – Append file like object in the request body, set to None or optional.

  • files – Append file like object with defining content-type of that file. set to None or optional

  • params – Append query string when request in url, set to None or optional.

  • auth – arguments for doing authentication request to the HTTP target. Support common HTTP auth, and by default set to None.

  • json – argument for sending a request in HTTP body with JSON-format. By default set to None or optional

  • timeout – parameter to setup timeout argument whenever request is failed, the initial duration of timeout is random values, by default set to None or optional

Returned as HTTP response object

static default_headers()

Given default HTTP headers for maritest if headers argument wasn’t set at the first time

property get_content: bytes

Property method to return content response from server

property get_cookies: RequestsCookieJar

Property method to return cookies jar response

property get_duration: float

Property method to return total of duration after send request in seconds

property get_headers: CaseInsensitiveDict

Property method to return response headers in dict format

property get_history: list

Property method to return HTTP redirection history

property get_json: Any

Property method to return response in JSON format

property get_status_code: int

Property method to return response in integer of status code

property get_text: str

Property method to return content response in unicode

property get_url: str

Property method to return full-path of URL

http_log_request()

Log HTTP information when send request

http_log_response()

Log HTTP response information after send request

static random_timeout() float

Internal method to generate random timeout in 1-4 seconds of interval and returned as floating number

Http Response

class maritest.response.Response(method: str, url: str, logger: bool = True, event_hooks: bool = False, retry: bool = True, headers: Optional[dict] = None, allow_redirects: Optional[bool] = None, suppress_warning: Optional[bool] = None, proxy: Optional[dict] = None, data: Optional[dict] = None, params: Optional[dict] = None, files: Optional[dict] = None, auth: Optional[Tuple] = None, json: Optional[dict] = None, timeout: Optional[float] = None)

Formatted HTTP response and returned as either dict, text or binary response. An inheritance class that sub-classing from Http Client in maritest.client module

history_response()

Formatted string output for url redirection history

http_response()

Formatted HTTP response as raw format (text)

retriever(fmt: str = 'json')

Collective method to retrieve HTTP response and returned as related argument ex: json, content and text

Parameters:

fmt – Parameter for choose what kind of response that want to returned, by default set as JSON

Returned formatted HTTP response

Http Authentication

class maritest.custom_auth.ApiKeyAuth(key: Optional[str], value: Optional[str], add_to: str = 'headers', header_name: Optional[str] = None)

Custom API key auth that will append into HTTP headers. this one is influenced by Postman QueryApiKey authorization

Parameters:
  • key – set API key if present, string type

  • value – set API value for related key if present, string type

  • add_to – mandatory argument to describes what kind of method that wants to be add. Support add to HTTP headers and add url with given by query params.

  • header_name – give valid HTTP header name to related field, If its not set the header name, then by default will be directed into X-API-KEY field

class maritest.custom_auth.BasicAuth(username, password)

this only inherit from requests module, and wrapped it into new method.

class maritest.custom_auth.BasicAuthToken(token: str)

Custom basic auth with token, its differ with requests BasicAuth

class maritest.custom_auth.BearerAuth(token: str)

Custom bearer authentication that sub-classes from requests module

class maritest.custom_auth.DigestAuth(username, password)

this only inherit from requests module, and wrapped it into new method

Http Assertion

Deprecation Utils

maritest.utils.deprecation.deprecated(message: str, version: Optional[str] = None) Any

Decorator utility to raise and given user warning about deprecated method or class in all maritest modules

Parameters:
  • message – required argument, message for identifying what method or classes has been deprecated. string type

  • version – optional argument, what versioning numbers that going deprecated. string type but optional to set

Returned as WarningMessage about related deprecation method/class

Factory Utils

class maritest.utils.factory.HttpHandler(url: str, method: str, disabled: bool = False)
emit(record)

Sub-classes from logging.Handler that emitted url response based on relevant HTTP method. It will receive as record from HTTP target and formatted (if any)

class maritest.utils.factory.LogEnum(value)

Enum class that represent for Log level

class maritest.utils.factory.Logger

Private class for logger factory

Dictionary Utils

maritest.utils.dict_lookups.keys_in_dict(lookup: dict, keys=None) Union[bool, dict]

Function to searching whether in any JSON response contains expected keys based on argument. This method can be used for searching keys in nested dict or only in single dict

Parameters:
  • lookup – argument for set dictionary object

  • keys – expected keys that want to be check

JSON Serializer

class maritest.serializable.JsonSerializer(object)

Simple JSON-serializable class that only inherited from dict type built-ins. Most likely will works for all basic data representation (not) a complex one.

Parameters:

json_object – Any object that which want to be formatted into JSON object

Returned as a pair of key-value like JSON-type, empty argument will resulted as empty JSON