Skip to content

caveclient.tools.testing

Functions:

Name Description
CAVEclientMock

Created a mocked CAVEclient function for testing using the responses library to mock

get_materialiation_info

Get the materialization versions and version metadata for the materialization service.

get_server_versions

Get the server versions for the services used in testing.

get_server_information

Generate the datastack name and server locations used in testing.

get_api_versions

Get the API versions for the services used in testing.

default_info

Generate a info service info file for testing

CAVEclientMock(datastack_name=None, global_server=None, local_server=None, info_file=None, chunkedgraph=False, chunkedgraph_server_version=DEFAULT_CHUNKEDGRAPH_SERVER_VERSION, chunkedgraph_api_versions=None, materialization=False, materialization_server_version=DEFAULT_MATERIALIZATION_SERVER_VERSON, materialization_api_versions=None, available_materialization_versions=None, set_version=None, set_version_metadata=None, json_service=False, json_service_server_version=DEFAULT_JSON_SERVICE_SERVER_VERSION, skeleton_service=False, skeleton_service_server_version=DEFAULT_SKELETON_SERVICE_SERVER_VERSION, schema_api_versions=None, l2cache=False, l2cache_disabled=False, global_only=False)

Created a mocked CAVEclient function for testing using the responses library to mock the server responses. This function returns a drop-in replacement for the CAVEclient function that will be able to initialize itself and selected individual service clients with the selected options.

Note that the test configuration is intended to be purely for pytest purposes and should not actually result in calls to active endpoints.

Parameters:

Name Type Description Default
datastack_name str

Name of the test datastack, by default None

None
global_server str

Test global server address, by default None

None
local_server str

Test local server address, by default None

None
info_file dictionary

Info service dictionary for the datastack, by default None

None
chunkedgraph bool

If True, configures the client to initialize a chunkedgraph subclient, by default False

False
chunkedgraph_server_version str

Sets the value of the chunkedgraph server version as a three-element semanatic version (e.g "2.3.4"), by default the value in DEFAULT_CHUNKEDGRAPH_SERVER_VERSION.

DEFAULT_CHUNKEDGRAPH_SERVER_VERSION
chunkedgraph_api_versions list

List of chunkedgraph API versions that the chunkedgraph client thinks exists, by default None. If None, returns the value in CHUNKEDGRAPH_API_VERSIONS.

None
materialization bool

If True, configures the client to initalize a materialization subclient, by default False Note that materialization being set to True will also configure the chunkedgraph client.

False
materialization_server_version str

Sets the value of the materialization server version as a three-element semanatic version (e.g "2.3.4"), by default the value in DEFAULT_MATERIALIZATION_SERVER_VERSON.

DEFAULT_MATERIALIZATION_SERVER_VERSON
available_materialization_versions list

List of materialization database versions that the materialization client thinks exists, by default None. If None, returns the value in DEFAULT_MATERIALIZATION_VERSONS.

None
materialization_api_versions list

List of materialization API versions that the materialization client thinks exists, by default None. If None, returns the value in MATERIALIZATION_API_VERSIONS.

None
set_version Optional[int]

If set, will set the version of the materialization server to the value of set_version, by default None. To work, this version must be in the list of available materialization versions.

None
set_version_metadata Optional[dict]

If set, will set the version metadata of the materialization server to the value of set_version_metadata. Default value is in DEFAULT_MATERIALIZATION_VERSION_METADATA.

None
json_service bool

If True, configures the client to initalize a materialization subclient, by default False

False
json_service_server_version _type_

Sets the value of the json state server version as a three-element semanatic version (e.g "2.3.4"), by default the value in DEFAULT_JSON_SERVICE_SERVER_VERSION.

DEFAULT_JSON_SERVICE_SERVER_VERSION
skeleton_service bool

If True, configures the client to initalize a skeleton service subclient, by default False

False
skeleton_service_server_version _type_

Sets the value of the skeleton service version as a three-element semanatic version (e.g "2.3.4"), by default the value in DEFAULT_SKELETON_SERVICE_SERVER_VERSION.

DEFAULT_SKELETON_SERVICE_SERVER_VERSION
l2cache bool

If True, configures the client to initialize an l2cache subclient, by default False Note that l2cache being set to True will also configure the chunkedgraph client.

False
l2cache_disabled bool

If True, allows a subclient to be initialized, but emulates a situation without an L2 cache, by default False Only used if l2cache is True.

False
global_only bool

If True, only initializes the global services and does not use a datastack, by default False.

False

Returns:

Type Description
CAVEclient

A mocked and initialized CAVEclient object for testing

Examples:

To make a basic pytest fixture to test chunkedgraph features with an initialized CAVEclient object in your pytest conftest.py file:

import pytest
from caveclient.tools.testing import CAVEclientMock

test_datastack = "test_stack"
test_global_server = "https://test.cave.com"
test_local_server = "https://local.cave.com"

@pytest.fixture()
def test_client():
    return CAVEclientMock(
        datastack_name=test_datastack,
        global_server=test_global_server,
        local_server=test_local_server,
        chunkedgraph=True,
    )

You can also create more complex fixtures with multiple services initialized and specific server versions:

```python
@pytest.fixture()
def fancier_test_client():
    return CAVEclientMock(
        datastack_name=test_datastack,
        global_server=test_global_server,
        local_server=test_local_server,
        chunkedgraph=True,
        chunkedgraph_server_version="3.0.2",
        materialization=True,
        materialization_server_version="4.21.4",
        l2cache=True,
    )

get_materialiation_info(materialization_versions=DEFAULT_MATERIALIZATION_VERSONS, version_metadata=DEFAULT_MATERIALIZATION_VERSION_METADATA)

Get the materialization versions and version metadata for the materialization service.

Parameters:

Name Type Description Default
materialization_versions list

List of materialization database versions that the materialization client thinks exists, by default DEFAULT_MATERIALIZATION_VERSONS.

DEFAULT_MATERIALIZATION_VERSONS
version_metadata dict

Version metadata for the materialization service, by default DEFAULT_MATERIALIZATION_VERSION_METADATA.

DEFAULT_MATERIALIZATION_VERSION_METADATA

Returns:

Type Description
dict

Dictionary with keys: "materialization_versions", "version_metadata".

get_server_versions(chunkedgraph_version=DEFAULT_CHUNKEDGRAPH_SERVER_VERSION, materialization_version=DEFAULT_MATERIALIZATION_SERVER_VERSON, skeleton_service_version=DEFAULT_SKELETON_SERVICE_SERVER_VERSION, json_service_version=DEFAULT_JSON_SERVICE_SERVER_VERSION)

Get the server versions for the services used in testing.

Parameters:

Name Type Description Default
chunkedgraph_version str

Version of the chunkedgraph server, by default DEFAULT_CHUNKEDGRAPH_SERVER_VERSION.

DEFAULT_CHUNKEDGRAPH_SERVER_VERSION
materialization_version str

Version of the materialization server, by default DEFAULT_MATERIALIZATION_SERVER_VERSON.

DEFAULT_MATERIALIZATION_SERVER_VERSON
skeleton_service_version str

Version of the skeleton service server, by default DEFAULT_SKELETON_SERVICE_SERVER_VERSION.

DEFAULT_SKELETON_SERVICE_SERVER_VERSION
json_service_version str

Version of the json service server, by default DEFAULT_JSON_SERVICE_SERVER_VERSION.

DEFAULT_JSON_SERVICE_SERVER_VERSION

Returns:

Type Description
dict

Dictionary with keys: "chunkedgraph_version", "materialization_version", "skeleton_service_version", "json_service_version". Values are Version objects from packaging.versions.

get_server_information(datastack_name=TEST_DATASTACK, global_server=TEST_GLOBAL_SERVER, local_server=TEST_LOCAL_SERVER)

Generate the datastack name and server locations used in testing.

Parameters:

Name Type Description Default
datastack_name str

Datastack value, by default the value in TEST_DATASTACK.

TEST_DATASTACK
global_server str

Server for global services, by default TEST_GLOBAL_SERVER.

TEST_GLOBAL_SERVER
local_server str

Server for local services, by default TEST_LOCAL_SERVER.

TEST_LOCAL_SERVER

Returns:

Type Description
dict

Dictionary with keys: "datastack_name", "local_server", "global_server".

get_api_versions(chunkedgraph_api_versions=CHUNKEDGRAPH_API_VERSIONS, materialization_api_versions=MATERIALIZATION_API_VERSIONS, schema_api_versions=SCHEMA_API_VERSIONS)

Get the API versions for the services used in testing.

Parameters:

Name Type Description Default
chunkedgraph_api_versions list

List of chunkedgraph API versions that the chunkedgraph client thinks exists, by default CHUNKEDGRAPH_API_VERSIONS.

CHUNKEDGRAPH_API_VERSIONS
materialization_api_versions list

List of materialization API versions that the materialization client thinks exists, by default MATERIALIZATION_API_VERSIONS.

MATERIALIZATION_API_VERSIONS
schema_api_versions list

List of schema API versions that the schema client thinks exists, by default SCHEMA_API_VERSIONS.

SCHEMA_API_VERSIONS

Returns:

Type Description
dict

Dictionary with keys: "chunkedgraph_api_versions", "materialization_api_versions", "schema_api_versions".

default_info(local_server=TEST_LOCAL_SERVER)

Generate a info service info file for testing

Parameters:

Name Type Description Default
local_server str

Name of the local service, by default the value in TEST_LOCAL_SERVER.

TEST_LOCAL_SERVER

Returns:

Type Description
dict

Info file for the datastack.