Skip to content

Commit 8de6bc1

Browse files
committed
Add functions to retrieve a single detector or vector layer
1 parent 50d72ce commit 8de6bc1

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/picterra/client.py

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

585+
def get_detector(self, detector_id: str):
586+
"""
587+
Get detector information
588+
589+
Args:
590+
detector_id: id of the detector
591+
592+
Raises:
593+
APIError: There was an error while getting the detector information
594+
595+
Returns:
596+
dict: Dictionary of the information
597+
"""
598+
resp = self.sess.get(self._api_url("detectors/%s/" % detector_id))
599+
if not resp.ok:
600+
raise APIError(resp.text)
601+
return resp.json()
602+
585603
def edit_detector(
586604
self,
587605
detector_id: str,
@@ -943,6 +961,24 @@ def edit_vector_layer(
943961
if not resp.ok:
944962
raise APIError(resp.text)
945963

964+
def get_vector_layer(self, vector_layer_id: str):
965+
"""
966+
Get vector layer information
967+
968+
Args:
969+
vector_layer_id: id of the detector
970+
971+
Raises:
972+
APIError: There was an error while getting the vector layer information
973+
974+
Returns:
975+
dict: Dictionary of the information
976+
"""
977+
resp = self.sess.get(self._api_url("vector_layers/%s/" % vector_layer_id))
978+
if not resp.ok:
979+
raise APIError(resp.text)
980+
return resp.json()
981+
946982
def delete_vector_layer(self, vector_layer_id: UUID):
947983
"""
948984
Removes a vector layer

tests/test_client.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,16 @@ def test_list_detectors():
750750
assert len(responses.calls) == 6
751751

752752

753+
@responses.activate
754+
def test_get_detector():
755+
"""Test the detector information"""
756+
DETECTOR_ID = "foobar"
757+
client = _client()
758+
_add_api_response("detectors/%s/" % DETECTOR_ID, json={}, status=200)
759+
client.get_detector(DETECTOR_ID)
760+
assert len(responses.calls) == 1
761+
762+
753763
@responses.activate
754764
def test_delete_detector():
755765
DETECTOR_ID = "foobar"
@@ -871,7 +881,7 @@ def test_train_detector():
871881
"training_annotations_count": 3,
872882
"validation_annotations_count": 1,
873883
},
874-
}
884+
},
875885
)
876886
client = _client()
877887
op = client.train_detector(1)
@@ -912,6 +922,16 @@ def test_delete_vector_layer():
912922
assert len(responses.calls) == 1
913923

914924

925+
@responses.activate
926+
def test_get_vector_layer():
927+
"""Test the vector layer information"""
928+
LAYER_ID = "foobar"
929+
client = _client()
930+
_add_api_response("vector_layers/%s/" % LAYER_ID, json={}, status=200)
931+
client.get_vector_layer(LAYER_ID)
932+
assert len(responses.calls) == 1
933+
934+
915935
@responses.activate
916936
def test_edit_vector_layer():
917937
LAYER_ID = "foobar"
@@ -945,7 +965,7 @@ def test_list_raster_markers():
945965

946966

947967
@responses.activate
948-
def test_list_raster_markers():
968+
def test_create_marker():
949969
client = _client()
950970
add_mock_marker_creation_response("spam", "foo", "bar", [12.34, 56.78], "foobar")
951971
marker = client.create_marker("foo", "bar", 12.34, 56.78, "foobar")

0 commit comments

Comments
 (0)