Skip to content

Commit 7b9e52d

Browse files
committed
Add functions to retrieve a single detector or vector layer
1 parent 902ecff commit 7b9e52d

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/picterra/client.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,24 @@ def list_detectors(
598598
data["is_shared"] = is_shared
599599
return self._paginate_through_list("detectors", data)
600600

601+
def get_detector(self, detector_id: str):
602+
"""
603+
Get detector information
604+
605+
Args:
606+
detector_id: id of the detector
607+
608+
Raises:
609+
APIError: There was an error while getting the detector information
610+
611+
Returns:
612+
dict: Dictionary of the information
613+
"""
614+
resp = self.sess.get(self._api_url("detectors/%s/" % detector_id))
615+
if not resp.ok:
616+
raise APIError(resp.text)
617+
return resp.json()
618+
601619
def edit_detector(
602620
self,
603621
detector_id: str,
@@ -953,6 +971,24 @@ def edit_vector_layer(
953971
if not resp.ok:
954972
raise APIError(resp.text)
955973

974+
def get_vector_layer(self, vector_layer_id: str):
975+
"""
976+
Get vector layer information
977+
978+
Args:
979+
vector_layer_id: id of the detector
980+
981+
Raises:
982+
APIError: There was an error while getting the vector layer information
983+
984+
Returns:
985+
dict: Dictionary of the information
986+
"""
987+
resp = self.sess.get(self._api_url("vector_layers/%s/" % vector_layer_id))
988+
if not resp.ok:
989+
raise APIError(resp.text)
990+
return resp.json()
991+
956992
def delete_vector_layer(self, vector_layer_id: str):
957993
"""
958994
Removes a vector layer

tests/test_client.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,16 @@ def test_list_detectors():
770770
assert len(responses.calls) == 6
771771

772772

773+
@responses.activate
774+
def test_get_detector():
775+
"""Test the detector information"""
776+
DETECTOR_ID = "foobar"
777+
client = _client()
778+
_add_api_response("detectors/%s/" % DETECTOR_ID, json={}, status=200)
779+
client.get_detector(DETECTOR_ID)
780+
assert len(responses.calls) == 1
781+
782+
773783
@responses.activate
774784
def test_delete_detector():
775785
DETECTOR_ID = "foobar"
@@ -930,6 +940,16 @@ def test_delete_vector_layer():
930940
assert len(responses.calls) == 1
931941

932942

943+
@responses.activate
944+
def test_get_vector_layer():
945+
"""Test the vector layer information"""
946+
LAYER_ID = "foobar"
947+
client = _client()
948+
_add_api_response("vector_layers/%s/" % LAYER_ID, json={}, status=200)
949+
client.get_vector_layer(LAYER_ID)
950+
assert len(responses.calls) == 1
951+
952+
933953
@responses.activate
934954
def test_edit_vector_layer():
935955
LAYER_ID = "foobar"
@@ -963,7 +983,7 @@ def test_list_raster_markers():
963983

964984

965985
@responses.activate
966-
def test_list_raster_markers():
986+
def test_create_marker():
967987
client = _client()
968988
add_mock_marker_creation_response("spam", "foo", "bar", [12.34, 56.78], "foobar")
969989
marker = client.create_marker("foo", "bar", 12.34, 56.78, "foobar")

0 commit comments

Comments
 (0)