Skip to content

Commit

Permalink
add get_version endpoint (#249)
Browse files Browse the repository at this point in the history
* add get_version endpoint

* fix most tests

* format

* fix client api mocking

* change version for mat clients

---------

Co-authored-by: Ben Pedigo <benjamindpedigo@gmail.com>
  • Loading branch information
fcollman and bdpedigo authored Oct 15, 2024
1 parent cc1d9cf commit f2924e5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
3 changes: 2 additions & 1 deletion caveclient/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
# -------------------------------

materialization_common = {
"get_api_versions": "{me_server_address}/materialize/api/versions"
"get_api_versions": "{me_server_address}/materialize/api/versions",
"get_version": "{me_server_address}/materialize/version",
}
mat_v2_api = "{me_server_address}/materialize/api/v2"
mat_v3_api = "{me_server_address}/materialize/api/v3"
Expand Down
40 changes: 20 additions & 20 deletions caveclient/materializationengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,10 @@ def _resolve_merge_reference(

@_check_version_compatibility(
kwarg_use_constraints={
"filter_greater_dict": ">=4.34.0",
"filter_less_dict": ">=4.34.0",
"filter_greater_equal_dict": ">=4.34.0",
"filter_less_equal_dict": ">=4.34.0",
"filter_greater_dict": ">=4.34.3",
"filter_less_dict": ">=4.34.3",
"filter_greater_equal_dict": ">=4.34.3",
"filter_less_equal_dict": ">=4.34.3",
}
)
def query_table(
Expand Down Expand Up @@ -866,10 +866,10 @@ def query_table(

@_check_version_compatibility(
kwarg_use_constraints={
"filter_greater_dict": ">=4.34.0",
"filter_less_dict": ">=4.34.0",
"filter_greater_equal_dict": ">=4.34.0",
"filter_less_equal_dict": ">=4.34.0",
"filter_greater_dict": ">=4.34.3",
"filter_less_dict": ">=4.34.3",
"filter_greater_equal_dict": ">=4.34.3",
"filter_less_equal_dict": ">=4.34.3",
}
)
def join_query(
Expand Down Expand Up @@ -1279,10 +1279,10 @@ def lookup_supervoxel_ids(

@_check_version_compatibility(
kwarg_use_constraints={
"filter_greater_dict": ">=4.34.0",
"filter_less_dict": ">=4.34.0",
"filter_greater_equal_dict": ">=4.34.0",
"filter_less_equal_dict": ">=4.34.0",
"filter_greater_dict": ">=4.34.3",
"filter_less_dict": ">=4.34.3",
"filter_greater_equal_dict": ">=4.34.3",
"filter_less_equal_dict": ">=4.34.3",
}
)
def live_query(
Expand Down Expand Up @@ -1901,10 +1901,10 @@ def get_tables_metadata(

@_check_version_compatibility(
kwarg_use_constraints={
"filter_greater_dict": ">=4.34.0",
"filter_less_dict": ">=4.34.0",
"filter_greater_equal_dict": ">=4.34.0",
"filter_less_equal_dict": ">=4.34.0",
"filter_greater_dict": ">=4.34.3",
"filter_less_dict": ">=4.34.3",
"filter_greater_equal_dict": ">=4.34.3",
"filter_less_equal_dict": ">=4.34.3",
},
kwarg_use_api_constraints={
"filter_regex_dict": ">=3.0.0",
Expand Down Expand Up @@ -2347,10 +2347,10 @@ def get_view_schemas(
@_check_version_compatibility(
method_api_constraint=">=3.0.0",
kwarg_use_constraints={
"filter_greater_dict": ">=4.34.0",
"filter_less_dict": ">=4.34.0",
"filter_greater_equal_dict": ">=4.34.0",
"filter_less_equal_dict": ">=4.34.0",
"filter_greater_dict": ">=4.34.3",
"filter_less_dict": ">=4.34.3",
"filter_greater_equal_dict": ">=4.34.3",
"filter_less_equal_dict": ">=4.34.3",
},
)
def query_view(
Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ def myclient():
# narrowly scoped to this function
version_url = f"{TEST_LOCAL_SERVER}/segmentation/api/version"
responses.add(responses.GET, version_url, json="2.15.0", status=200)

client.chunkedgraph # this will trigger the version check

mat_version_url = f"{TEST_LOCAL_SERVER}/materialize/version"
responses.add(responses.GET, mat_version_url, json="4.30.1", status=200)
client.materialize

return client


Expand Down
10 changes: 7 additions & 3 deletions tests/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ def test_create_versioned_client(self):
endpoint_mapping = self.default_mapping
endpoint_mapping["emas_server_address"] = TEST_GLOBAL_SERVER

print(endpoints.chunkedgraph_endpoints_common.keys())
api_versions_url = endpoints.chunkedgraph_endpoints_common[
"get_api_versions"
].format_map(endpoint_mapping)
responses.add(responses.GET, url=api_versions_url, json=[0, 1], status=200)

version_url = endpoints.chunkedgraph_endpoints_common["get_version"].format_map(
cg_version_url = endpoints.chunkedgraph_endpoints_common[
"get_version"
].format_map(endpoint_mapping)
responses.add(responses.GET, cg_version_url, json="2.15.0", status=200)

mat_version_url = endpoints.materialization_common["get_version"].format_map(
endpoint_mapping
)
responses.add(responses.GET, version_url, json="2.15.0", status=200)
responses.add(responses.GET, mat_version_url, json="4.30.1", status=200)

responses.add(
responses.GET,
Expand Down
15 changes: 12 additions & 3 deletions tests/test_materialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,15 @@ class TestMatclient:
@responses.activate
def test_matclient_v3_tableinterface(self, myclient, mocker):
myclient = copy.deepcopy(myclient)
myclient._materialize = None
endpoint_mapping = self.default_mapping
endpoint_mapping["emas_server_address"] = TEST_GLOBAL_SERVER

mat_version_url = materialization_common["get_version"].format_map(
endpoint_mapping
)
responses.add(responses.GET, mat_version_url, json="4.30.1", status=200)

api_versions_url = chunkedgraph_endpoints_common["get_api_versions"].format_map(
endpoint_mapping
)
Expand All @@ -333,6 +339,7 @@ def test_matclient_v3_tableinterface(self, myclient, mocker):
json=[3],
status=200,
)
myclient.materialize # done here to trigger version check

versionurl = materialization_endpoints_v3["versions"].format_map(
endpoint_mapping
Expand Down Expand Up @@ -379,7 +386,7 @@ def test_matclient_v3_tableinterface(self, myclient, mocker):
responses.add(
responses.GET, url=get_views_schema_url, json=self.views_schema, status=200
)

print(len(myclient.materialize.tables))
assert len(myclient.materialize.tables) == 2
qry = myclient.materialize.tables.allen_column_mtypes_v2(
pt_root_id=[123, 456], target_id=271700
Expand Down Expand Up @@ -800,8 +807,10 @@ def mock_get_root_timestamps(self, root_ids):
new_xyz = np.vstack(df.ctr_pt_position.values)
assert np.all(new_xyz == orig_xyz * [4, 4, 40])

myclient._materialize = None
myclient.desired_resolution = [1, 1, 1]
# NOTE: this messed up the mock on the version endpoint
# myclient._materialize = None
# myclient.desired_resolution = [1, 1, 1]
myclient._materialize.desired_resolution = [1, 1, 1]
df = myclient.materialize.query_table(
test_info["synapse_table"],
filter_in_dict={"pre_pt_root_id": [500]},
Expand Down

0 comments on commit f2924e5

Please sign in to comment.