rbtools.testing.transport¶
Transport subclass used for unit testing.
- Deprecated::
3.1: Replaced with
rbtools.testing.api.transport.URLMapTransport.
Classes
|
Mocked subclass of Transport used for unit tests. |
- class rbtools.testing.transport.TestTransport(url, list_payload={'links': {'create': {'href': 'http://localhost:8080/api/', 'method': 'POST'}, 'other_link': {'href': 'http://localhost:8080/api/', 'method': 'GET'}, 'self': {'href': 'http://localhost:8080/api/', 'method': 'GET'}}, 'resource_token': [{'field1': 1, 'field2': 2, 'links': {'self': {'href': 'http://localhost:8080/api/', 'method': 'GET'}}, 'name': 'testname1', 'path': 'testpath1', 'tool': 'Git'}, {'field1': 1, 'field2': 2, 'links': {'self': {'href': 'http://localhost:8080/api/', 'method': 'GET'}}, 'name': 'testname2', 'path': 'testpath2', 'tool': 'Git'}], 'stat': 'ok', 'total_results': 10}, root_payload={'links': {'groups': {'href': 'http://localhost:8080/api/groups', 'method': 'GET'}, 'repositories': {'href': 'http://localhost:8080/api/repositories/', 'method': 'GET'}, 'self': {'href': 'http://localhost:8080/api/', 'method': 'GET'}}, 'stat': 'ok', 'uri_templates': {'reviews': 'http://localhost:8080/api/review-requests/{review_request_id}/reviews/'}})[source]¶
Bases:
Transport
Mocked subclass of Transport used for unit tests.
This is mainly used to test functionality that requires interacting with and reading data from a Review Board server. Unlike the original implementation of its parent class, custom payloads can be passed in to force return a specific subclass of
rbtools.api.resource.Resource
.- Deprecated::
3.1: Replaced with
rbtools.testing.api.transport.URLMapTransport.
- __init__(url, list_payload={'links': {'create': {'href': 'http://localhost:8080/api/', 'method': 'POST'}, 'other_link': {'href': 'http://localhost:8080/api/', 'method': 'GET'}, 'self': {'href': 'http://localhost:8080/api/', 'method': 'GET'}}, 'resource_token': [{'field1': 1, 'field2': 2, 'links': {'self': {'href': 'http://localhost:8080/api/', 'method': 'GET'}}, 'name': 'testname1', 'path': 'testpath1', 'tool': 'Git'}, {'field1': 1, 'field2': 2, 'links': {'self': {'href': 'http://localhost:8080/api/', 'method': 'GET'}}, 'name': 'testname2', 'path': 'testpath2', 'tool': 'Git'}], 'stat': 'ok', 'total_results': 10}, root_payload={'links': {'groups': {'href': 'http://localhost:8080/api/groups', 'method': 'GET'}, 'repositories': {'href': 'http://localhost:8080/api/repositories/', 'method': 'GET'}, 'self': {'href': 'http://localhost:8080/api/', 'method': 'GET'}}, 'stat': 'ok', 'uri_templates': {'reviews': 'http://localhost:8080/api/review-requests/{review_request_id}/reviews/'}})[source]¶
Initialize an instance of TestTransport.
- Parameters:
list_payload (
dict
, optional) – Dictionary of key-pair values representing the payload for arbtools.api.resource.ItemResource
instance. Default value is a payload defined in rbtools.api.tests.base.TestWithPayloads.root_payload (
dict
, optional) – Dictionary of key-pair values representing the payload for arbtools.api.resource.RootResource
. Default value is a payload defined in rbtools.api.tests.base.TestWithPayloads.
- execute_request_method(method, *args, **kwargs)[source]¶
Return an instance of ItemResource.
Instead of executing
execute_request_method()
and carrying out an instance ofrbtools.api.request.HttpRequest
, it returns an instance of:py:class:rbtools.api.resource.ItemResource. The type of metadata this instance contains depends on the type oflist_payload
passed in.- Parameters:
method (
callable
) – A function that acts as a method to be executed and returns arbtools.api.request.HttpRequest
instance.*args – Variable arguments used for running the passed in method.
**kwargs – Keyword arguments used for running the passed in method.
- Returns:
An instance of
rbtools.api.resource.ItemResource
if the executed method is an instance ofrbtools.api.request.HttpRequest
.- Return type:
- get_root()[source]¶
Return an instance of RootResource
Instead of calling
get_root()
and returning an instance ofrbtools.api.request.HttpRequest
, an instance ofrbtools.api.resource.RootResource
is simply returned. The type of metadata this instance contains depends on the type ofroot_payload
passed in.- Returns:
An instance of
rbtools.api.request.RootResource
.- Return type:
- enable_cache(cache_location: Optional[str] = None, in_memory: bool = False) None [source]¶
Enable caching for all future HTTP requests.
The cache will be created at the default location if none is provided.
If the in_memory parameter is True, the cache will be created in memory instead of on disk. This overrides the cache_location parameter.