55
66MOCK_IP_ADDRESS = "localhost"
77MOCK_PORT = 5000
8- MOCK_URL = "http://{}:{}/v1/vision/detection" .format (MOCK_IP_ADDRESS , MOCK_PORT )
8+ OBJ_URL = "http://{}:{}/v1/vision/detection" .format (MOCK_IP_ADDRESS , MOCK_PORT )
9+ SCENE_URL = "http://{}:{}/v1/vision/scene" .format (MOCK_IP_ADDRESS , MOCK_PORT )
10+ FACE_DETECTION_URL = "http://{}:{}/v1/vision/face" .format (MOCK_IP_ADDRESS , MOCK_PORT )
11+
12+ CONFIDENCE_THRESHOLD = 0.7
913
1014MOCK_BYTES = b"Test"
1115MOCK_API_KEY = "mock_api_key"
1216MOCK_TIMEOUT = 8
1317
18+ MOCK_SCENE_RESPONSE = {"success" : True , "label" : "street" , "confidence" : 0.86745402 }
19+
1420MOCK_OBJECT_DETECTION_RESPONSE = {
1521 "success" : True ,
1622 "predictions" : [
4147 ],
4248}
4349
50+ MOCK_OBJECT_PREDICTIONS = MOCK_OBJECT_DETECTION_RESPONSE ["predictions" ]
51+ MOCK_OBJECT_CONFIDENCES = [0.6998661 , 0.7996547 ]
52+
53+
4454MOCK_FACE_RECOGNITION_RESPONSE = {
4555 "success" : True ,
4656 "predictions" : [
6373 ],
6474}
6575
66- MOCK_OBJECT_PREDICTIONS = MOCK_OBJECT_DETECTION_RESPONSE ["predictions" ]
67- MOCK_OBJECT_CONFIDENCES = [0.6998661 , 0.7996547 ]
68- CONFIDENCE_THRESHOLD = 0.7
76+ MOCK_FACE_DETECTION_RESPONSE = {
77+ "success" : True ,
78+ "predictions" : [
79+ {
80+ "confidence" : 0.9999999 ,
81+ "y_min" : 173 ,
82+ "x_min" : 203 ,
83+ "y_max" : 834 ,
84+ "x_max" : 667 ,
85+ }
86+ ],
87+ }
88+
89+
6990MOCK_RECOGNISED_FACES = {"Idris Elba" : 75.0 }
7091
7192
7293def test_DeepstackObject_detect ():
7394 """Test a good response from server."""
7495 with requests_mock .Mocker () as mock_req :
7596 mock_req .post (
76- MOCK_URL , status_code = ds .HTTP_OK , json = MOCK_OBJECT_DETECTION_RESPONSE
97+ OBJ_URL , status_code = ds .HTTP_OK , json = MOCK_OBJECT_DETECTION_RESPONSE
7798 )
7899
79100 dsobject = ds .DeepstackObject (MOCK_IP_ADDRESS , MOCK_PORT )
@@ -85,13 +106,37 @@ def test_DeepstackObject_detect_timeout():
85106 """Test a timeout. THIS SHOULD FAIL"""
86107 with pytest .raises (ds .DeepstackException ) as excinfo :
87108 with requests_mock .Mocker () as mock_req :
88- mock_req .post (MOCK_URL , exc = requests .exceptions .ConnectTimeout )
109+ mock_req .post (OBJ_URL , exc = requests .exceptions .ConnectTimeout )
89110 dsobject = ds .DeepstackObject (MOCK_IP_ADDRESS , MOCK_PORT )
90111 dsobject .detect (MOCK_BYTES )
91112 assert False
92113 assert "SHOULD FAIL" in str (excinfo .value )
93114
94115
116+ def test_DeepstackScene ():
117+ """Test a good response from server."""
118+ with requests_mock .Mocker () as mock_req :
119+ mock_req .post (SCENE_URL , status_code = ds .HTTP_OK , json = MOCK_SCENE_RESPONSE )
120+
121+ dsscene = ds .DeepstackScene (MOCK_IP_ADDRESS , MOCK_PORT )
122+ dsscene .detect (MOCK_BYTES )
123+ assert dsscene .predictions == MOCK_SCENE_RESPONSE
124+
125+
126+ def test_DeepstackFace ():
127+ """Test a good response from server."""
128+ with requests_mock .Mocker () as mock_req :
129+ mock_req .post (
130+ FACE_DETECTION_URL ,
131+ status_code = ds .HTTP_OK ,
132+ json = MOCK_FACE_DETECTION_RESPONSE ,
133+ )
134+
135+ dsface = ds .DeepstackFace (MOCK_IP_ADDRESS , MOCK_PORT )
136+ dsface .detect (MOCK_BYTES )
137+ assert dsface .predictions == MOCK_FACE_DETECTION_RESPONSE ["predictions" ]
138+
139+
95140def test_get_objects ():
96141 """Cant always be sure order of returned list items."""
97142 objects = ds .get_objects (MOCK_OBJECT_PREDICTIONS )
0 commit comments