From dcece34d932495c1a854299041ed4b9371a0376f Mon Sep 17 00:00:00 2001 From: Forrest Collman Date: Sun, 15 Dec 2024 20:14:01 -0800 Subject: [PATCH] improving tests --- tests/test_jsonclient.py | 2 +- tests/test_materialization.py | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/test_jsonclient.py b/tests/test_jsonclient.py index 629914be..0fbd8577 100644 --- a/tests/test_jsonclient.py +++ b/tests/test_jsonclient.py @@ -55,7 +55,7 @@ def test_upload_state_json(myclient): state_id = myclient.state.upload_state_json(json_state) assert state_id == 1234 - ## test the get_state_json method + # test the get_state_json method url = f"{global_server}/nglstate/api/v1/{state_id}" responses.add(responses.GET, url=url, json=json_state, status=200) state = myclient.state.get_state_json(state_id) diff --git a/tests/test_materialization.py b/tests/test_materialization.py index cfab787b..601849dd 100644 --- a/tests/test_materialization.py +++ b/tests/test_materialization.py @@ -851,3 +851,46 @@ 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]) + + +@responses.activate +def test_get_view_metadata(myclient): + datastack_name = "test_datastack" + view_name = "test_view" + materialization_version = 1 + + url = f"{datastack_dict['local_server']}/materialize/api/v3/datastack/{datastack_name}/version/{materialization_version}/views/{view_name}/metadata" + # Mock the response + mock_response = {"metadata_key": "metadata_value"} + responses.add(responses.GET, url=url, json=mock_response, status=200) + + # Call the method + result = myclient.materialize.get_view_metadata( + view_name, materialization_version, datastack_name + ) + + # Verify the result + assert result == mock_response + assert "metadata_key" in result + assert result["metadata_key"] == "metadata_value" + + +@responses.activate +def test_get_unique_string_values(myclient): + datastack_name = "test_datastack" + table_name = "test_table" + + url = f"{datastack_dict['local_server']}/materialize/api/v3/datastack/{datastack_name}/table/{table_name}/unique_string_values" + # Mock the response + mock_response = {"column1": ["value1", "value2"], "column2": ["value3", "value4"]} + responses.add(responses.GET, url=url, json=mock_response, status=200) + + # Call the method + result = myclient.materialize.get_unique_string_values(table_name, datastack_name) + + # Verify the result + assert result == mock_response + assert "column1" in result + assert "column2" in result + assert result["column1"] == ["value1", "value2"] + assert result["column2"] == ["value3", "value4"]