@@ -39,20 +39,27 @@ def test_create_env():
39
39
}
40
40
mock_create_env .assert_called_once_with (Env (latitude = 0 , longitude = 0 ))
41
41
42
+
42
43
def test_create_env_invalid_input ():
43
- response = client .post ("/environments/" , json = {"latitude" : "foo" , "longitude" : "bar" })
44
+ response = client .post (
45
+ "/environments/" , json = {"latitude" : "foo" , "longitude" : "bar" }
46
+ )
44
47
assert response .status_code == 422
45
48
49
+
46
50
def test_create_env_server_error ():
47
51
with patch .object (
48
52
EnvController , "create_env" , side_effect = Exception ("error" )
49
- ) as mock_create_env :
53
+ ):
50
54
with pytest .raises (Exception ):
51
55
response = client .post (
52
56
"/environments/" , json = {"latitude" : 0 , "longitude" : 0 }
53
57
)
54
58
assert response .status_code == 500
55
- assert response .json () == {"detail" : "Failed to create environment: error" }
59
+ assert response .json () == {
60
+ "detail" : "Failed to create environment: error"
61
+ }
62
+
56
63
57
64
def test_read_env (stub_env ):
58
65
with patch .object (
@@ -65,23 +72,32 @@ def test_read_env(stub_env):
65
72
assert response .json () == expected_content
66
73
mock_read_env .assert_called_once_with ("123" )
67
74
75
+
68
76
def test_read_env_not_found ():
69
77
with patch .object (
70
- EnvController , "get_env_by_id" , side_effect = HTTPException (status_code = 404 , detail = "Environment not found" )
78
+ EnvController ,
79
+ "get_env_by_id" ,
80
+ side_effect = HTTPException (
81
+ status_code = 404 , detail = "Environment not found"
82
+ ),
71
83
) as mock_read_env :
72
84
response = client .get ("/environments/123" )
73
85
assert response .status_code == 404
74
86
assert response .json () == {"detail" : "Environment not found" }
75
87
mock_read_env .assert_called_once_with ("123" )
76
88
89
+
77
90
def test_read_env_server_error ():
78
91
with patch .object (
79
92
EnvController , "get_env_by_id" , side_effect = Exception ("error" )
80
- ) as mock_read_env :
93
+ ):
81
94
with pytest .raises (Exception ):
82
95
response = client .get ("/environments/123" )
83
96
assert response .status_code == 500
84
- assert response .json () == {"detail" : "Failed to read environment: error" }
97
+ assert response .json () == {
98
+ "detail" : "Failed to read environment: error"
99
+ }
100
+
85
101
86
102
def test_update_env ():
87
103
with patch .object (
@@ -101,15 +117,21 @@ def test_update_env():
101
117
"123" , Env (latitude = 1 , longitude = 1 )
102
118
)
103
119
120
+
104
121
def test_update_env_invalid_input ():
105
- response = client .put ("/environments/123" , json = {"latitude" : "foo" , "longitude" : "bar" })
122
+ response = client .put (
123
+ "/environments/123" , json = {"latitude" : "foo" , "longitude" : "bar" }
124
+ )
106
125
assert response .status_code == 422
107
126
127
+
108
128
def test_update_env_not_found ():
109
129
with patch .object (
110
130
EnvController ,
111
131
"update_env_by_id" ,
112
- side_effect = HTTPException (status_code = 404 , detail = "Environment not found" ),
132
+ side_effect = HTTPException (
133
+ status_code = 404 , detail = "Environment not found"
134
+ ),
113
135
) as mock_update_env :
114
136
response = client .put (
115
137
"/environments/123" , json = {"longitude" : 1 , "latitude" : 1 }
@@ -120,18 +142,22 @@ def test_update_env_not_found():
120
142
"123" , Env (latitude = 1 , longitude = 1 )
121
143
)
122
144
145
+
123
146
def test_update_env_server_error ():
124
147
with patch .object (
125
148
EnvController ,
126
149
"update_env_by_id" ,
127
150
side_effect = Exception ("error" ),
128
- ) as mock_update_env :
151
+ ):
129
152
with pytest .raises (Exception ):
130
153
response = client .put (
131
154
"/environments/123" , json = {"longitude" : 1 , "latitude" : 1 }
132
155
)
133
156
assert response .status_code == 500
134
- assert response .json () == {"detail" : "Failed to update environment: error" }
157
+ assert response .json () == {
158
+ "detail" : "Failed to update environment: error"
159
+ }
160
+
135
161
136
162
def test_delete_env ():
137
163
with patch .object (
@@ -147,6 +173,7 @@ def test_delete_env():
147
173
}
148
174
mock_delete_env .assert_called_once_with ("123" )
149
175
176
+
150
177
def test_delete_env_not_found ():
151
178
with patch .object (
152
179
EnvController ,
@@ -161,16 +188,20 @@ def test_delete_env_not_found():
161
188
}
162
189
mock_delete_env .assert_called_once_with ("123" )
163
190
191
+
164
192
def test_delete_env_server_error ():
165
193
with patch .object (
166
194
EnvController ,
167
195
"delete_env_by_id" ,
168
196
side_effect = Exception ("error" ),
169
- ) as mock_delete_env :
197
+ ):
170
198
with pytest .raises (Exception ):
171
199
response = client .delete ("/environments/123" )
172
200
assert response .status_code == 500
173
- assert response .json () == {"detail" : "Failed to delete environment: error" }
201
+ assert response .json () == {
202
+ "detail" : "Failed to delete environment: error"
203
+ }
204
+
174
205
175
206
def test_simulate_env (stub_env_summary ):
176
207
with patch .object (
@@ -189,27 +220,34 @@ def test_simulate_env(stub_env_summary):
189
220
assert response .json () == expected_content
190
221
mock_simulate_env .assert_called_once_with ("123" )
191
222
223
+
192
224
def test_simulate_env_not_found ():
193
225
with patch .object (
194
226
EnvController ,
195
227
"simulate_env" ,
196
- side_effect = HTTPException (status_code = 404 , detail = "Environment not found" ),
228
+ side_effect = HTTPException (
229
+ status_code = 404 , detail = "Environment not found"
230
+ ),
197
231
) as mock_simulate_env :
198
232
response = client .get ("/environments/123/summary" )
199
233
assert response .status_code == 404
200
234
assert response .json () == {"detail" : "Environment not found" }
201
235
mock_simulate_env .assert_called_once_with ("123" )
202
236
237
+
203
238
def test_simulate_env_server_error ():
204
239
with patch .object (
205
240
EnvController ,
206
241
"simulate_env" ,
207
242
side_effect = Exception ("error" ),
208
- ) as mock_simulate_env :
243
+ ):
209
244
with pytest .raises (Exception ):
210
245
response = client .get ("/environments/123/summary" )
211
246
assert response .status_code == 500
212
- assert response .json () == {"detail" : "Failed to simulate environment: error" }
247
+ assert response .json () == {
248
+ "detail" : "Failed to simulate environment: error"
249
+ }
250
+
213
251
214
252
def test_read_rocketpy_env ():
215
253
with patch .object (
@@ -221,24 +259,30 @@ def test_read_rocketpy_env():
221
259
assert response .headers ["content-type" ] == "application/octet-stream"
222
260
mock_read_rocketpy_env .assert_called_once_with ("123" )
223
261
262
+
224
263
def test_read_rocketpy_env_not_found ():
225
264
with patch .object (
226
265
EnvController ,
227
266
"get_rocketpy_env_binary" ,
228
- side_effect = HTTPException (status_code = 404 , detail = "Environment not found" ),
267
+ side_effect = HTTPException (
268
+ status_code = 404 , detail = "Environment not found"
269
+ ),
229
270
) as mock_read_rocketpy_env :
230
271
response = client .get ("/environments/123/rocketpy" )
231
272
assert response .status_code == 404
232
273
assert response .json () == {"detail" : "Environment not found" }
233
274
mock_read_rocketpy_env .assert_called_once_with ("123" )
234
275
276
+
235
277
def test_read_rocketpy_env_server_error ():
236
278
with patch .object (
237
279
EnvController ,
238
280
"get_rocketpy_env_binary" ,
239
281
side_effect = Exception ("error" ),
240
- ) as mock_read_rocketpy_env :
282
+ ):
241
283
with pytest .raises (Exception ):
242
284
response = client .get ("/environments/123/rocketpy" )
243
285
assert response .status_code == 500
244
- assert response .json () == {"detail" : "Failed to read rocketpy environment: error" }
286
+ assert response .json () == {
287
+ "detail" : "Failed to read rocketpy environment: error"
288
+ }
0 commit comments