Reference¶
noseapp_requests.base module¶
- class noseapp_requests.base.Endpoint(config)[source]¶
Represents an API endpoint.
Parameters: config (Config) – endpoint config
- class noseapp_requests.base.RequestsEx(*configs)[source]¶
Extension initializer.
Usage:
>>> requests_ex = RequestsEx(ENDPOINT1_CONFIG, ENDPOINT2_CONFIG, ...)
Each endpoint config represents an API endpoint (basically, a base URL) that you need access to in tests. So, for example, if you need to call your app’s API at http://yourapp.test/api/v1/ and also get data from some external source at http://databank.test:6847/, you’ll provide two configs to the extension::
app_config = make_config() app_config.configure(base_url='http://yourapp.test/api/v1/') databank_config = make_config() databank_config.configure(base_url='http://databank.test:6847/') requests_ex = RequestsEx(app_config, databank_config)
Each config can be provided a key that will be used to refer to it. By default, base_url is used as key.
- get_endpoint_session(endpoint_key, **kwargs)[source]¶
Get API session for endpoint endpoint_key. Any additional kwargs will be passed to Endpoint.get_session().
- name = 'requests'¶
- class noseapp_requests.base.Session(base_url=None, url_builder=None, always_return_json=False, raise_on_http_error=False, **session_kwargs)[source]¶
Represents an API/requests session. Actual interface is dependent on the url_builder provided; by default it mimics requests interface.
Parameters: - base_url – Base URL for endpoint; if provided, default URL builder will prepend it to all URLs provided in method calls.
- url_builder – A custom URL builder callable. See noseapp_requests.urlbuilder documentation for details.
- always_return_json (bool) – Parse all responses to JSON if set.
- raise_on_http_error (bool) – Raise HTTPError if response status code >= 400.
All other keyword arguments are set directly on requests.Session.
Default interface:
- get(url, **params)¶
- post(url, json_object=None, **params)¶
- put(url, json_object=None, **params)¶
- delete(url, **params)¶
All keyword parameters for get go into query string, for other methods they are urlencoded into request body.
noseapp_requests.config module¶
- class noseapp_requests.config.Config[source]¶
Extension configuration.