From c111a7be5189cf2a015e52c03a9adcdaa451a580 Mon Sep 17 00:00:00 2001 From: Tim Huff Date: Mon, 7 Aug 2023 16:00:35 -0700 Subject: [PATCH] adding some tests --- test/integration/test_groundlight.py | 67 +++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/test/integration/test_groundlight.py b/test/integration/test_groundlight.py index 27b7505a..647022cc 100644 --- a/test/integration/test_groundlight.py +++ b/test/integration/test_groundlight.py @@ -13,6 +13,8 @@ from groundlight.status_codes import is_user_error from model import ClassificationResult, Detector, ImageQuery, PaginatedDetectorList, PaginatedImageQueryList +from internalapi import InternalApiError + DEFAULT_CONFIDENCE_THRESHOLD = 0.9 @@ -59,7 +61,6 @@ def fixture_image_query_no(gl: Groundlight, detector: Detector) -> ImageQuery: iq = gl.submit_image_query(detector=detector.id, image="test/assets/cat.jpeg") return iq - def test_create_detector(gl: Groundlight): name = f"Test {datetime.utcnow()}" # Need a unique name query = "Is there a dog?" @@ -410,3 +411,67 @@ def submit_noisy_image(image, label=None): return assert False, "The detector performance has not improved after two minutes" + +def test_start_inspection(gl: Groundlight): + inspection_id = gl.start_inspection() + + assert isinstance(inspection_id, str) + assert 'inspect_' in inspection_id + +def test_update_inspection_metadata_successful(gl: Groundlight): + """Starts an inspection and adds a couple pieces of metadata to it. + This should succeed. If there are any errors, an exception will be raised. + """ + inspection_id = gl.start_inspection() + + user_provided_key = 'Inspector' + user_provided_value = 'Bob' + gl.update_inspection_metadata(inspection_id, user_provided_key, user_provided_value) + + user_provided_key = 'Engine ID' + user_provided_value = '1234' + gl.update_inspection_metadata(inspection_id, user_provided_key, user_provided_value) + +def test_update_inspection_metadata_invalid_inspection_id(gl: Groundlight): + """Attempt to update metadata for an inspection that doesn't exist. + Should raise an InternalApiError. + """ + + # The URCap might submit an empty string if an inspection hasn't started. + # An InternalApiError should be raised in this case. + inspection_id = '' + user_provided_key = 'Operator' + user_provided_value = 'Bob' + + with pytest.raises(InternalApiError): + gl.update_inspection_metadata(inspection_id, user_provided_key, user_provided_value) + +def test_stop_inspection_pass(gl: Groundlight, detector: Detector): + """Starts an inspection, submits a query that should pass, stops + the inspection, checks the result. + """ + inspection_id = gl.start_inspection() + + _ = gl.submit_image_query(detector=detector, + image="test/assets/dog.jpeg", + inspection_id=inspection_id) + + assert gl.stop_inspection(inspection_id) == "PASS" + +def test_stop_inspection_fail(gl: Groundlight, detector: Detector): + """Starts an inspection, submits a query that should fail, stops + the inspection, checks the result. + """ + inspection_id = gl.start_inspection() + + _ = gl.submit_image_query(detector=detector, + image="test/assets/cat.jpeg", + inspection_id=inspection_id) + + assert gl.stop_inspection(inspection_id) == "FAIL" + +def test_stop_inspection_with_invalid_id(gl: Groundlight): + inspection_id = 'some_invalid_inspection_id' + + with pytest.raises(InternalApiError): + gl.stop_inspection(inspection_id)