|
14 | 14 | from groundlight.internalapi import ApiException, InternalApiError, NotFoundError |
15 | 15 | from groundlight.optional_imports import * |
16 | 16 | from groundlight.status_codes import is_user_error |
| 17 | +from groundlight_openapi_client.exceptions import NotFoundException |
17 | 18 | from ksuid import KsuidMs |
18 | 19 | from model import ( |
19 | 20 | BinaryClassificationResult, |
@@ -848,3 +849,42 @@ def test_multiclass_detector(gl: Groundlight): |
848 | 849 | mc_iq = gl.submit_image_query(created_detector, "test/assets/dog.jpeg") |
849 | 850 | assert mc_iq.result.label is not None |
850 | 851 | assert mc_iq.result.label in class_names |
| 852 | + |
| 853 | + |
| 854 | +def test_delete_detector(gl: Groundlight): |
| 855 | + """ |
| 856 | + Test deleting a detector by both ID and object, and verify proper error handling. |
| 857 | + """ |
| 858 | + # Create a detector to delete |
| 859 | + name = f"Test delete detector {datetime.utcnow()}" |
| 860 | + query = "Is there a dog to delete?" |
| 861 | + pipeline_config = "never-review" |
| 862 | + detector = gl.create_detector(name=name, query=query, pipeline_config=pipeline_config) |
| 863 | + |
| 864 | + # Delete using detector object |
| 865 | + gl.delete_detector(detector) |
| 866 | + |
| 867 | + # Verify the detector is actually deleted |
| 868 | + with pytest.raises(NotFoundError): |
| 869 | + gl.get_detector(detector.id) |
| 870 | + |
| 871 | + # Create another detector to test deletion by ID string and that an attached image query is deleted |
| 872 | + name2 = f"Test delete detector 2 {datetime.utcnow()}" |
| 873 | + detector2 = gl.create_detector(name=name2, query=query, pipeline_config=pipeline_config) |
| 874 | + gl.submit_image_query(detector2, "test/assets/dog.jpeg") |
| 875 | + |
| 876 | + # Delete using detector ID string |
| 877 | + gl.delete_detector(detector2.id) |
| 878 | + |
| 879 | + # Verify the second detector is also deleted |
| 880 | + with pytest.raises(NotFoundError): |
| 881 | + gl.get_detector(detector2.id) |
| 882 | + |
| 883 | + # Verify the image query is also deleted |
| 884 | + with pytest.raises(NotFoundException): |
| 885 | + gl.get_image_query(detector2.id) |
| 886 | + |
| 887 | + # Test deleting a non-existent detector raises NotFoundError |
| 888 | + fake_detector_id = "det_fake123456789" |
| 889 | + with pytest.raises(NotFoundError): |
| 890 | + gl.delete_detector(fake_detector_id) # type: ignore |
0 commit comments