d1_test.mock_api package¶
Subpackages¶
- d1_test.mock_api.tests package
- Submodules
- d1_test.mock_api.tests.test_catch_all module
- d1_test.mock_api.tests.test_create module
- d1_test.mock_api.tests.test_d1_exception module
- d1_test.mock_api.tests.test_describe module
- d1_test.mock_api.tests.test_generate_identifier module
- d1_test.mock_api.tests.test_get module
- d1_test.mock_api.tests.test_get_capabilities module
- d1_test.mock_api.tests.test_get_format module
- d1_test.mock_api.tests.test_get_log_records module
- d1_test.mock_api.tests.test_get_query_engine_description module
- d1_test.mock_api.tests.test_get_system_metadata module
- d1_test.mock_api.tests.test_is_authorized module
- d1_test.mock_api.tests.test_list_formats module
- d1_test.mock_api.tests.test_list_nodes module
- d1_test.mock_api.tests.test_list_objects module
- d1_test.mock_api.tests.test_ping module
- d1_test.mock_api.tests.test_post module
- d1_test.mock_api.tests.test_query module
- d1_test.mock_api.tests.test_resolve module
- d1_test.mock_api.tests.test_solr_search module
- d1_test.mock_api.tests.test_util module
Submodules¶
d1_test.mock_api.catch_all module¶
d1_test.mock_api.create module¶
Mock a generic POST request by echoing the posted body.
A DataONEException can be triggered by adding a custom header. See d1_exception.py
-
d1_test.mock_api.create.
add_callback
(base_url)¶
-
d1_test.mock_api.create.
pack_echo_header
(body_bytes, headers, url_obj)¶
-
d1_test.mock_api.create.
unpack_echo_header
(header_dict)¶
d1_test.mock_api.d1_exception module¶
Mock DataONEException.
A DataONEException can be triggered in any of the mock APIs by adding a custom header named “trigger” with the status code of the error to trigger, using the vendorSpecific parameter.
E.g.:
client.create(…, vendorSpecific={‘trigger’: ‘401’})
-
d1_test.mock_api.d1_exception.
trigger_by_pid
(request, pid)¶
-
d1_test.mock_api.d1_exception.
trigger_by_header
(request)¶
-
d1_test.mock_api.d1_exception.
trigger_by_status_code
(request, status_code_int)¶
-
d1_test.mock_api.d1_exception.
create_regular_d1_exception
(status_code_int)¶
-
d1_test.mock_api.d1_exception.
create_header_d1_exception
(status_code_int)¶
d1_test.mock_api.describe module¶
d1_test.mock_api.django_client module¶
Mock Requests to issue requests through the Django test client.
Django includes a test framework with a test client that provides an interface that’s similar to that of an HTTP client, but calls Django internals directly. The client enables testing of most functionality of a Django app without actually starting the app as a network service.
For testing GMN’s D1 REST interfaces, we want to issue the test requests via the D1 MN client. Without going through the D1 MN client, we would have to reimplement much of what the client does, related to formatting and parsing D1 REST requests.
This module is typically used in tests running under django.test.TestCase and requires an active Django context, such as the one provided by ./manage.py test.
Usage:
import d1_test.mock_api.django_client as mock_django_client
@responses.activate def test_1000(self):
mock_django_client.add_callback(MOCK_MN_BASE_URL) d1_client = d1_client.mnclient_2_0.MemberNodeClient_2_0(MOCK_MN_BASE_URL) node_pyxb = d1_client.getCapabilities()
-
d1_test.mock_api.django_client.
add_callback
(base_url)¶
d1_test.mock_api.echo_credentials module¶
d1_test.mock_api.generate_identifier module¶
Mock:
CNCore.generateIdentifier(session, scheme[, fragment]) → Identifier https://releases.dataone.org/online/api-documentation-v2.0.1/apis/CN_APIs.html#CNCore.generateIdentifier MNStorage.generateIdentifier(session, scheme[, fragment]) → Identifier https://releases.dataone.org/online/api-documentation-v2.0.1/apis/MN_APIs.html#MNStorage.generateIdentifier
A DataONEException can be triggered by adding a custom header. See d1_exception.py
-
d1_test.mock_api.generate_identifier.
add_callback
(base_url)¶
d1_test.mock_api.get module¶
d1_test.mock_api.get_capabilities module¶
d1_test.mock_api.get_format module¶
d1_test.mock_api.get_log_records module¶
d1_test.mock_api.get_system_metadata module¶
d1_test.mock_api.is_authorized module¶
d1_test.mock_api.list_formats module¶
d1_test.mock_api.list_nodes module¶
d1_test.mock_api.list_objects module¶
d1_test.mock_api.ping module¶
Mock a ping response.
CNCore.ping() → null https://releases.dataone.org/online/api-documentation-v2.0.1/apis/CN_APIs.html#CNCore.ping MNRead.ping() → null https://releases.dataone.org/online/api-documentation-v2.0.1/apis/MN_APIs.html#MNCore.ping
A DataONEException can be triggered by adding a custom header. See d1_exception.py
-
d1_test.mock_api.ping.
add_callback
(base_url)¶
d1_test.mock_api.post module¶
Mock a generic POST request by echoing the posted body.
A DataONEException can be triggered by adding a custom header. See d1_exception.py
-
d1_test.mock_api.post.
add_callback
(base_url)¶