arjuna.tpi.httpauto.session module¶
-
class
arjuna.tpi.httpauto.session.
HttpSession
(*, url=None, oauth_token=None, request_content_handler=None, headers=None, max_redirects=None, auth=None, proxy=None, _auto_session=True)¶ Bases:
object
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.
Add cookies to the session.
-
auth
¶ HTTP Authentication object.
All current cookies in this session object.
-
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.
-
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.
-
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.
-
headers
¶ Request headers.
-
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.
-
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.
-
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.
-
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.
-
request_content_handler
¶ Request content handler for content formatting.
-
send
(request) → arjuna.tpi.httpauto.response.HttpResponse¶ Send the provided HttpRequest to server.
In case of ConnectionError, retries the connection 5 times at a gap of 1 second. Currently, not configurable.
- Returns
- HttpResponse object. In case of redirections, this is the last HttpResponse object, which encapsulates all redirections which can be retrieved from it.
-
url
¶ Base URL for this session.