arjuna.tpi.httpauto.http module

class arjuna.tpi.httpauto.http.Http

Bases: object

The Facade class for HTTP Automation.

class auth

Bases: object

HTTP Authentication Builder

classmethod basic(*, user, pwd)

Create an HTTP Basic Authentication object.

classmethod digest(*, user, pwd)

Create an HTTP Basic Authentication object.

class content

Bases: object

classmethod blank(content='')

Send empty content. Content-Type is sent as “text/html”

classmethod bytes(content='')

Send bytes string. Content-Type is sent as “text/html”

classmethod custom(content, *, type)

Send content with a custom content type.

classmethod file(field_name, file_name, *, content_type='text/plain', headers=None)

Upload a file and send as multipart data. Content-Type is sent as the content type got from multipart encoding.

classmethod get_content_type(handler_method)
classmethod html(content='')

Send HTML content. Content-Type is sent as “text/html”

classmethod json(content='')

Send a dictionary of key-values as JSON. Content-Type is sent as “application/json”

classmethod multipart(*fields)

Send the provided HTTP fields as multipart data. Content-Type is sent as the content type got from multipart encoding.

classmethod text(content='')

Send HTML content. Content-Type is sent as “text/html”

classmethod urlencoded(content='')

Send a dictionary of key-values in URL encoded format. Content-Type is sent as “application/x-www-form-urlencoded”

classmethod utf8(content='')

Send UTF-8 string. Content-Type is sent as “text/html”

classmethod xml(content='')

Send an XML string as XML. Content-Type is sent as “application/xml

classmethod delete(route, label=None, xcodes=None, strict=False, headers=None, cookies=None, allow_redirects=True, auth=None, timeout: float = None, pretty_url=False, query_params=None, **named_query_params) → arjuna.tpi.httpauto.response.HttpResponse

Sends an HTTP DELETE request.

Parameters:

route – Absolute or relative URL. If relative, then url of this session object is pre-fixed.

Keyword Arguments:
 
  • label – Label for this request. If available, it is used in reports and logs.
  • xcodes – Expected HTTP response code(s).
  • strict – If True in case of unexpected status code, an AssertionError is raised, else HttpUnexpectedStatusCodeError is raised.
  • headers – Mapping of additional HTTP headers to be sent with this request.
  • cookies – Python dict of cookies to send with request.
  • allow_redirects – If True, redirections are allowed for the HTTP message. Default is True.
  • auth – HTTP Authentication object: Basic/Digest.
  • timeout – How long to wait for the server to send data before giving up.
  • pretty_url – If True, the query params are formatted using pretty URL format instead of usual query string which is the default.
  • query_params – A mapping of key-values to be included in query string.
  • **named_query_params – Arbitrary key/value pairs. These are appended to the query string of URL for this request.

Note

query_params and named_query_params have the same goal. In case of duplicates, named_query_params override query_params.

classmethod field(name, value, is_file=False, content_type='text/plain', headers=None)
classmethod get(route, label=None, xcodes=None, strict=False, headers=None, cookies=None, allow_redirects=True, auth=None, timeout: float = None, pretty_url=False, query_params=None, **named_query_params) → arjuna.tpi.httpauto.response.HttpResponse

Sends an HTTP GET request.

Parameters:

route – Absolute or relative URL. If relative, then url of this session object is pre-fixed.

Keyword Arguments:
 
  • label – Label for this request. If available, it is used in reports and logs.
  • xcodes – Expected HTTP response code(s).
  • strict – If True in case of unexpected status code, an AssertionError is raised, else HttpUnexpectedStatusCodeError is raised.
  • headers – Mapping of additional HTTP headers to be sent with this request.
  • cookies – Python dict of cookies to send with request.
  • allow_redirects – If True, redirections are allowed for the HTTP message. Default is True.
  • auth – HTTP Authentication object: Basic/Digest.
  • timeout – How long to wait for the server to send data before giving up.
  • pretty_url – If True, the query params are formatted using pretty URL format instead of usual query string which is the default.
  • query_params – A mapping of key-values to be included in query string.
  • **named_query_params – Arbitrary key/value pairs. These are appended to the query string of URL for this request.

Note

query_params and named_query_params have the same goal. In case of duplicates, named_query_params override query_params.

classmethod head(route, label=None, xcodes=None, strict=False, headers=None, cookies=None, allow_redirects=True, auth=None, timeout: float = None, pretty_url=False, query_params=None, **named_query_params) → arjuna.tpi.httpauto.response.HttpResponse

Sends an HTTP HEAD request.

Parameters:

route – Absolute or relative URL. If relative, then url of this session object is pre-fixed.

Keyword Arguments:
 
  • label – Label for this request. If available, it is used in reports and logs.
  • xcodes – Expected HTTP response code(s).
  • strict – If True in case of unexpected status code, an AssertionError is raised, else HttpUnexpectedStatusCodeError is raised.
  • headers – Mapping of additional HTTP headers to be sent with this request.
  • cookies – Python dict of cookies to send with request.
  • allow_redirects – If True, redirections are allowed for the HTTP message. Default is True.
  • auth – HTTP Authentication object: Basic/Digest.
  • timeout – How long to wait for the server to send data before giving up.
  • pretty_url – If True, the query params are formatted using pretty URL format instead of usual query string which is the default.
  • query_params – A mapping of key-values to be included in query string.
  • **named_query_params – Arbitrary key/value pairs. These are appended to the query string of URL for this request.

Note

query_params and named_query_params have the same goal. In case of duplicates, named_query_params override query_params.

classmethod oauth_client_grant_session(*, url, client_id, client_secret, token_url)

Create OAuthClientGrantSession object.

Creates token using OAuth’s Resource Owner Client Credentials Grant Type. Uses BackendApplicationClient from requests_oauthlib.

Keyword Arguments:
 
  • url – Base URL for this HTTP session. If relative path is used as a route in sender methods like .get, then this URL is prefixed to their provided routes.
  • client_id – Client ID
  • client_secret – Client Secret
  • token_url – Token URL
classmethod oauth_implicit_grant_session(*, url, client_id, scope, redirect_uri=None, auth_url, auth_handler=None, **auth_args)

Create OAuthImplicitGrantSession object.

Creates token using OAuth’s Implicit Code Grant Type. Uses MobileApplicationClient from requests_oauthlib.

Keyword Arguments:
 
  • url – Base URL for this HTTP session. If relative path is used as a route in sender methods like .get, then this URL is prefixed to their provided routes.
  • client_id – Client ID
  • scope – Scope
  • redirect_uri – Redirect URI
  • auth_url – Authorization URL
  • auth_handler – A callback function to handle custom authroization logic. It will be called by providing session object, authorization URL and auth_args.
  • **auth_args – Arbitray key-value pairs to be passed as arguments to the auth_handler callback.

Note

Some sample auth_handler signatures:

auth_handler_1(oauth_session, auth_url, **kwargs)
auth_handler_2(oauth_session, auth_url, some_arg=None, another_arg="some_def_value")
classmethod options(route, *, content, label=None, xcodes=None, strict=False, headers=None, cookies=None, allow_redirects=True, auth=None, timeout: float = None, pretty_url=False, query_params=None, **named_query_params) → arjuna.tpi.httpauto.response.HttpResponse

Sends an HTTP PUT request.

Parameters:

route – Absolute or relative URL. If relative, then url of this session object is pre-fixed.

Keyword Arguments:
 
  • label – Label for this request. If available, it is used in reports and logs.
  • content – Content to be sent in this HTTP request. If passed as string, then content-type set in session is used using the content request handler. It can also be a dictionary with keys - ‘content’ and ‘type’.
  • xcodes – Expected HTTP response code(s).
  • strict – If True in case of unexpected status code, an AssertionError is raised, else HttpUnexpectedStatusCodeError is raised.
  • headers – Mapping of additional HTTP headers to be sent with this request.
  • cookies – Python dict of cookies to send with request.
  • allow_redirects – If True, redirections are allowed for the HTTP message. Default is True.
  • auth – HTTP Authentication object: Basic/Digest.
  • timeout – How long to wait for the server to send data before giving up.
  • pretty_url – If True, the query params are formatted using pretty URL format instead of usual query string which is the default.
  • query_params – A mapping of key-values to be included in query string.
  • **named_query_params – Arbitrary key/value pairs. These are appended to the query string of URL for this request.

Note

query_params and named_query_params have the same goal. In case of duplicates, named_query_params override query_params.

classmethod patch(route, *, content, label=None, xcodes=None, strict=False, headers=None, cookies=None, allow_redirects=True, auth=None, timeout: float = None, pretty_url=False, query_params=None, **named_query_params) → arjuna.tpi.httpauto.response.HttpResponse

Sends an HTTP PUT request.

Parameters:

route – Absolute or relative URL. If relative, then url of this session object is pre-fixed.

Keyword Arguments:
 
  • label – Label for this request. If available, it is used in reports and logs.
  • content – Content to be sent in this HTTP request. If passed as string, then content-type set in session is used using the content request handler. It can also be a dictionary with keys - ‘content’ and ‘type’.
  • xcodes – Expected HTTP response code(s).
  • strict – If True in case of unexpected status code, an AssertionError is raised, else HttpUnexpectedStatusCodeError is raised.
  • headers – Mapping of additional HTTP headers to be sent with this request.
  • cookies – Python dict of cookies to send with request.
  • allow_redirects – If True, redirections are allowed for the HTTP message. Default is True.
  • auth – HTTP Authentication object: Basic/Digest.
  • timeout – How long to wait for the server to send data before giving up.
  • pretty_url – If True, the query params are formatted using pretty URL format instead of usual query string which is the default.
  • query_params – A mapping of key-values to be included in query string.
  • **named_query_params – Arbitrary key/value pairs. These are appended to the query string of URL for this request.

Note

query_params and named_query_params have the same goal. In case of duplicates, named_query_params override query_params.

classmethod post(route, *, content, label=None, xcodes=None, strict=False, headers=None, cookies=None, allow_redirects=True, auth=None, timeout: float = None, pretty_url=False, query_params=None, **named_query_params) → arjuna.tpi.httpauto.response.HttpResponse

Sends an HTTP POST request.

Parameters:

route – Absolute or relative URL. If relative, then url of this session object is pre-fixed.

Keyword Arguments:
 
  • label – Label for this request. If available, it is used in reports and logs.
  • content – Content to be sent in this HTTP request. If passed as string, then content-type set in session is used using the content request handler. It can also be a dictionary with keys - ‘content’ and ‘type’.
  • xcodes – Expected HTTP response code(s).
  • strict – If True in case of unexpected status code, an AssertionError is raised, else HttpUnexpectedStatusCodeError is raised.
  • headers – Mapping of additional HTTP headers to be sent with this request.
  • cookies – Python dict of cookies to send with request.
  • allow_redirects – If True, redirections are allowed for the HTTP message. Default is True.
  • auth – HTTP Authentication object: Basic/Digest.
  • timeout – How long to wait for the server to send data before giving up.
  • pretty_url – If True, the query params are formatted using pretty URL format instead of usual query string which is the default.
  • query_params – A mapping of key-values to be included in query string.
  • **named_query_params – Arbitrary key/value pairs. These are appended to the query string of URL for this request.

Note

query_params and named_query_params have the same goal. In case of duplicates, named_query_params override query_params.

classmethod proxy(url)

Create a proxy dict.

classmethod put(route, *, content, label=None, xcodes=None, strict=False, headers=None, cookies=None, allow_redirects=True, auth=None, timeout: float = None, pretty_url=False, query_params=None, **named_query_params) → arjuna.tpi.httpauto.response.HttpResponse

Sends an HTTP PUT request.

Parameters:

route – Absolute or relative URL. If relative, then url of this session object is pre-fixed.

Keyword Arguments:
 
  • label – Label for this request. If available, it is used in reports and logs.
  • content – Content to be sent in this HTTP request. If passed as string, then content-type set in session is used using the content request handler. It can also be a dictionary with keys - ‘content’ and ‘type’.
  • xcodes – Expected HTTP response code(s).
  • strict – If True in case of unexpected status code, an AssertionError is raised, else HttpUnexpectedStatusCodeError is raised.
  • headers – Mapping of additional HTTP headers to be sent with this request.
  • cookies – Python dict of cookies to send with request.
  • allow_redirects – If True, redirections are allowed for the HTTP message. Default is True.
  • auth – HTTP Authentication object: Basic/Digest.
  • timeout – How long to wait for the server to send data before giving up.
  • pretty_url – If True, the query params are formatted using pretty URL format instead of usual query string which is the default.
  • query_params – A mapping of key-values to be included in query string.
  • **named_query_params – Arbitrary key/value pairs. These are appended to the query string of URL for this request.

Note

query_params and named_query_params have the same goal. In case of duplicates, named_query_params override query_params.

classmethod session(*, url=None, oauth_token=None, request_content_handler=None, headers=None, max_redirects=None, auth=None, proxy=None)

Create an HTTP Session. Does automatic cookie management.

Keyword Arguments:
 
  • url – Base URL for this HTTP session. If relative path is used as a route in sender methods like .get, then this URL is prefixed to their provided routes.
  • oauth_token – OAuth 2.0 Bearer token for this session.
  • request_content_handler – Default content type handler for requests sent in this session. Overridable in individual sender methods. Default is Http.content.urlencoded.
  • headers – HTTP headers to be added to request headers made by this session.
  • max_redirects – Maximum number of redirects allowed for a request. Default is 30.
  • auth – HTTP Authentication object: Basic/Digest.
  • proxy – Proxies dict to be associated with this session.