5
5
6
6
MOCK_IP_ADDRESS = "localhost"
7
7
MOCK_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
9
13
10
14
MOCK_BYTES = b"Test"
11
15
MOCK_API_KEY = "mock_api_key"
12
16
MOCK_TIMEOUT = 8
13
17
18
+ MOCK_SCENE_RESPONSE = {"success" : True , "label" : "street" , "confidence" : 0.86745402 }
19
+
14
20
MOCK_OBJECT_DETECTION_RESPONSE = {
15
21
"success" : True ,
16
22
"predictions" : [
41
47
],
42
48
}
43
49
50
+ MOCK_OBJECT_PREDICTIONS = MOCK_OBJECT_DETECTION_RESPONSE ["predictions" ]
51
+ MOCK_OBJECT_CONFIDENCES = [0.6998661 , 0.7996547 ]
52
+
53
+
44
54
MOCK_FACE_RECOGNITION_RESPONSE = {
45
55
"success" : True ,
46
56
"predictions" : [
63
73
],
64
74
}
65
75
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
+
69
90
MOCK_RECOGNISED_FACES = {"Idris Elba" : 75.0 }
70
91
71
92
72
93
def test_DeepstackObject_detect ():
73
94
"""Test a good response from server."""
74
95
with requests_mock .Mocker () as mock_req :
75
96
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
77
98
)
78
99
79
100
dsobject = ds .DeepstackObject (MOCK_IP_ADDRESS , MOCK_PORT )
@@ -85,13 +106,37 @@ def test_DeepstackObject_detect_timeout():
85
106
"""Test a timeout. THIS SHOULD FAIL"""
86
107
with pytest .raises (ds .DeepstackException ) as excinfo :
87
108
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 )
89
110
dsobject = ds .DeepstackObject (MOCK_IP_ADDRESS , MOCK_PORT )
90
111
dsobject .detect (MOCK_BYTES )
91
112
assert False
92
113
assert "SHOULD FAIL" in str (excinfo .value )
93
114
94
115
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
+
95
140
def test_get_objects ():
96
141
"""Cant always be sure order of returned list items."""
97
142
objects = ds .get_objects (MOCK_OBJECT_PREDICTIONS )
0 commit comments