From 7b9e52d2b355cbf8197c1a129ccac4c2f01b0e79 Mon Sep 17 00:00:00 2001 From: Andrea Orlandi Date: Fri, 22 Sep 2023 16:38:05 +0200 Subject: [PATCH] Add functions to retrieve a single detector or vector layer --- src/picterra/client.py | 36 ++++++++++++++++++++++++++++++++++++ tests/test_client.py | 22 +++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/picterra/client.py b/src/picterra/client.py index 4ba645e..ce1aaf9 100644 --- a/src/picterra/client.py +++ b/src/picterra/client.py @@ -598,6 +598,24 @@ def list_detectors( data["is_shared"] = is_shared return self._paginate_through_list("detectors", data) + def get_detector(self, detector_id: str): + """ + Get detector information + + Args: + detector_id: id of the detector + + Raises: + APIError: There was an error while getting the detector information + + Returns: + dict: Dictionary of the information + """ + resp = self.sess.get(self._api_url("detectors/%s/" % detector_id)) + if not resp.ok: + raise APIError(resp.text) + return resp.json() + def edit_detector( self, detector_id: str, @@ -953,6 +971,24 @@ def edit_vector_layer( if not resp.ok: raise APIError(resp.text) + def get_vector_layer(self, vector_layer_id: str): + """ + Get vector layer information + + Args: + vector_layer_id: id of the detector + + Raises: + APIError: There was an error while getting the vector layer information + + Returns: + dict: Dictionary of the information + """ + resp = self.sess.get(self._api_url("vector_layers/%s/" % vector_layer_id)) + if not resp.ok: + raise APIError(resp.text) + return resp.json() + def delete_vector_layer(self, vector_layer_id: str): """ Removes a vector layer diff --git a/tests/test_client.py b/tests/test_client.py index ad151db..4937f9a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -770,6 +770,16 @@ def test_list_detectors(): assert len(responses.calls) == 6 +@responses.activate +def test_get_detector(): + """Test the detector information""" + DETECTOR_ID = "foobar" + client = _client() + _add_api_response("detectors/%s/" % DETECTOR_ID, json={}, status=200) + client.get_detector(DETECTOR_ID) + assert len(responses.calls) == 1 + + @responses.activate def test_delete_detector(): DETECTOR_ID = "foobar" @@ -930,6 +940,16 @@ def test_delete_vector_layer(): assert len(responses.calls) == 1 +@responses.activate +def test_get_vector_layer(): + """Test the vector layer information""" + LAYER_ID = "foobar" + client = _client() + _add_api_response("vector_layers/%s/" % LAYER_ID, json={}, status=200) + client.get_vector_layer(LAYER_ID) + assert len(responses.calls) == 1 + + @responses.activate def test_edit_vector_layer(): LAYER_ID = "foobar" @@ -963,7 +983,7 @@ def test_list_raster_markers(): @responses.activate -def test_list_raster_markers(): +def test_create_marker(): client = _client() add_mock_marker_creation_response("spam", "foo", "bar", [12.34, 56.78], "foobar") marker = client.create_marker("foo", "bar", 12.34, 56.78, "foobar")