Skip to content

Commit e49954f

Browse files
committed
Fix issues with mock responses in tests
- They included bodies in HTTP 204 responses (not RFC2626 compatible). - They were not formatted consistently. While the formatting may be up to taste, the RFC2626 compatibiliity is enforced by newer releases of the `responses` library.
1 parent b2b96b3 commit e49954f

11 files changed

Lines changed: 181 additions & 54 deletions

tests/test_custom_image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def test_custom_images_delete():
111111
status=200,
112112
)
113113
responses.add(
114-
responses.DELETE, CLOUDSCALE_API_URL + "/custom-images/" + uuid, status=204
114+
responses.DELETE,
115+
CLOUDSCALE_API_URL + "/custom-images/" + uuid,
116+
status=204,
115117
)
116118

117119
runner = CliRunner()
@@ -255,7 +257,6 @@ def test_custom_images_update():
255257
responses.add(
256258
responses.PATCH,
257259
CLOUDSCALE_API_URL + "/custom-images/" + uuid,
258-
json=CUSTOM_IMAGE_RESP,
259260
status=204,
260261
)
261262
responses.add(

tests/test_flavor.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@
1515
@responses.activate
1616
def test_flavor_get_all():
1717
responses.add(
18-
responses.GET, CLOUDSCALE_API_URL + "/flavors", json=[FLAVOR_RESP], status=200
18+
responses.GET,
19+
CLOUDSCALE_API_URL + "/flavors",
20+
json=[FLAVOR_RESP],
21+
status=200,
22+
)
23+
responses.add(
24+
responses.GET,
25+
CLOUDSCALE_API_URL + "/flavors",
26+
json={},
27+
status=500,
1928
)
20-
responses.add(responses.GET, CLOUDSCALE_API_URL + "/flavors", json={}, status=500)
2129

2230
runner = CliRunner()
2331
result = runner.invoke(

tests/test_floating_ip.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ def test_floating_ip_get_all():
3030
status=200,
3131
)
3232
responses.add(
33-
responses.GET, CLOUDSCALE_API_URL + "/floating-ips", json={}, status=500
33+
responses.GET,
34+
CLOUDSCALE_API_URL + "/floating-ips",
35+
json={},
36+
status=500,
3437
)
3538

3639
runner = CliRunner()
@@ -105,7 +108,9 @@ def test_floating_ip_delete():
105108
status=200,
106109
)
107110
responses.add(
108-
responses.DELETE, CLOUDSCALE_API_URL + "/floating-ips/" + network_id, status=204
111+
responses.DELETE,
112+
CLOUDSCALE_API_URL + "/floating-ips/" + network_id,
113+
status=204,
109114
)
110115
responses.add(
111116
responses.DELETE,
@@ -222,7 +227,6 @@ def test_floating_ip_update():
222227
responses.add(
223228
responses.PATCH,
224229
CLOUDSCALE_API_URL + "/floating-ips/" + network_id,
225-
json=FLOATING_IP_RESP,
226230
status=204,
227231
)
228232
responses.add(

tests/test_image.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@
1515
@responses.activate
1616
def test_image_get_all():
1717
responses.add(
18-
responses.GET, CLOUDSCALE_API_URL + "/images", json=[IMAGE_RESP], status=200
18+
responses.GET,
19+
CLOUDSCALE_API_URL + "/images",
20+
json=[IMAGE_RESP],
21+
status=200,
22+
)
23+
responses.add(
24+
responses.GET,
25+
CLOUDSCALE_API_URL + "/images",
26+
json={},
27+
status=500,
1928
)
20-
responses.add(responses.GET, CLOUDSCALE_API_URL + "/images", json={}, status=500)
2129

2230
runner = CliRunner()
2331
result = runner.invoke(

tests/test_network.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@
2424
@responses.activate
2525
def test_network_get_all():
2626
responses.add(
27-
responses.GET, CLOUDSCALE_API_URL + "/networks", json=[NETWORK_RESP], status=200
27+
responses.GET,
28+
CLOUDSCALE_API_URL + "/networks",
29+
json=[NETWORK_RESP],
30+
status=200,
31+
)
32+
responses.add(
33+
responses.GET,
34+
CLOUDSCALE_API_URL + "/networks",
35+
json={},
36+
status=500,
2837
)
29-
responses.add(responses.GET, CLOUDSCALE_API_URL + "/networks", json={}, status=500)
3038

3139
runner = CliRunner()
3240
result = runner.invoke(
@@ -61,7 +69,10 @@ def test_network_get_by_uuid():
6169
status=200,
6270
)
6371
responses.add(
64-
responses.GET, CLOUDSCALE_API_URL + "/networks/" + uuid, json={}, status=500
72+
responses.GET,
73+
CLOUDSCALE_API_URL + "/networks/" + uuid,
74+
json={},
75+
status=500,
6576
)
6677

6778
runner = CliRunner()
@@ -105,7 +116,9 @@ def test_network_delete():
105116
status=200,
106117
)
107118
responses.add(
108-
responses.DELETE, CLOUDSCALE_API_URL + "/networks/" + uuid, status=204
119+
responses.DELETE,
120+
CLOUDSCALE_API_URL + "/networks/" + uuid,
121+
status=204,
109122
)
110123
responses.add(
111124
responses.DELETE,
@@ -158,9 +171,17 @@ def test_network_create():
158171
name = "my-network-name"
159172

160173
responses.add(
161-
responses.POST, CLOUDSCALE_API_URL + "/networks", json=NETWORK_RESP, status=201
174+
responses.POST,
175+
CLOUDSCALE_API_URL + "/networks",
176+
json=NETWORK_RESP,
177+
status=201,
178+
)
179+
responses.add(
180+
responses.POST,
181+
CLOUDSCALE_API_URL + "/networks",
182+
json={},
183+
status=500,
162184
)
163-
responses.add(responses.POST, CLOUDSCALE_API_URL + "/networks", json={}, status=500)
164185

165186
runner = CliRunner()
166187
result = runner.invoke(
@@ -196,7 +217,6 @@ def test_network_update():
196217
responses.add(
197218
responses.PATCH,
198219
CLOUDSCALE_API_URL + "/networks/" + uuid,
199-
json=NETWORK_RESP,
200220
status=204,
201221
)
202222
responses.add(
@@ -206,7 +226,9 @@ def test_network_update():
206226
status=200,
207227
)
208228
responses.add(
209-
responses.PATCH, CLOUDSCALE_API_URL + "/networks/" + uuid, json={}, status=500
229+
responses.PATCH,
230+
CLOUDSCALE_API_URL + "/networks/" + uuid,
231+
status=500,
210232
)
211233

212234
runner = CliRunner()

tests/test_objects_user.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def test_objects_user_get_all():
3232
status=200,
3333
)
3434
responses.add(
35-
responses.GET, CLOUDSCALE_API_URL + "/objects-users", json={}, status=500
35+
responses.GET,
36+
CLOUDSCALE_API_URL + "/objects-users",
37+
json={},
38+
status=500,
3639
)
3740

3841
runner = CliRunner()
@@ -128,7 +131,9 @@ def test_objects_user_delete():
128131
status=200,
129132
)
130133
responses.add(
131-
responses.DELETE, CLOUDSCALE_API_URL + "/objects-users/" + uuid, status=204
134+
responses.DELETE,
135+
CLOUDSCALE_API_URL + "/objects-users/" + uuid,
136+
status=204,
132137
)
133138
responses.add(
134139
responses.DELETE,
@@ -186,7 +191,10 @@ def test_objects_user_create():
186191
status=201,
187192
)
188193
responses.add(
189-
responses.POST, CLOUDSCALE_API_URL + "/objects-users", json={}, status=500
194+
responses.POST,
195+
CLOUDSCALE_API_URL + "/objects-users",
196+
json={},
197+
status=500,
190198
)
191199
responses.add(
192200
responses.POST,
@@ -195,7 +203,10 @@ def test_objects_user_create():
195203
status=201,
196204
)
197205
responses.add(
198-
responses.POST, CLOUDSCALE_API_URL + "/objects-users", json={}, status=500
206+
responses.POST,
207+
CLOUDSCALE_API_URL + "/objects-users",
208+
json={},
209+
status=500,
199210
)
200211

201212
runner = CliRunner()
@@ -232,7 +243,6 @@ def test_objects_user_update():
232243
responses.add(
233244
responses.PATCH,
234245
CLOUDSCALE_API_URL + "/objects-users/" + uuid,
235-
json=OBJECTS_USER_RESP,
236246
status=204,
237247
)
238248
responses.add(
@@ -244,7 +254,6 @@ def test_objects_user_update():
244254
responses.add(
245255
responses.PATCH,
246256
CLOUDSCALE_API_URL + "/objects-users/unknown",
247-
json={},
248257
status=404,
249258
)
250259

tests/test_region.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99
@responses.activate
1010
def test_region_get_all():
1111
responses.add(
12-
responses.GET, CLOUDSCALE_API_URL + "/regions", json=[REGION_RESP], status=200
12+
responses.GET,
13+
CLOUDSCALE_API_URL + "/regions",
14+
json=[REGION_RESP],
15+
status=200,
16+
)
17+
responses.add(
18+
responses.GET,
19+
CLOUDSCALE_API_URL + "/regions",
20+
json={},
21+
status=500,
1322
)
14-
responses.add(responses.GET, CLOUDSCALE_API_URL + "/regions", json={}, status=500)
1523

1624
runner = CliRunner()
1725
result = runner.invoke(

tests/test_server.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
@responses.activate
2424
def test_server_get_all():
2525
responses.add(
26-
responses.GET, CLOUDSCALE_API_URL + "/servers", json=[SERVER_RESP], status=200
26+
responses.GET,
27+
CLOUDSCALE_API_URL + "/servers",
28+
json=[SERVER_RESP],
29+
status=200,
2730
)
2831
responses.add(
2932
responses.GET,
@@ -58,7 +61,10 @@ def test_server_get_all():
5861
@responses.activate
5962
def test_server_get_all_fitlered():
6063
responses.add(
61-
responses.GET, CLOUDSCALE_API_URL + "/servers", json=[SERVER_RESP], status=200
64+
responses.GET,
65+
CLOUDSCALE_API_URL + "/servers",
66+
json=[SERVER_RESP],
67+
status=200,
6268
)
6369

6470
runner = CliRunner()
@@ -128,7 +134,11 @@ def test_server_delete():
128134
json=SERVER_RESP,
129135
status=200,
130136
)
131-
responses.add(responses.DELETE, CLOUDSCALE_API_URL + "/servers/" + uuid, status=204)
137+
responses.add(
138+
responses.DELETE,
139+
CLOUDSCALE_API_URL + "/servers/" + uuid,
140+
status=204,
141+
)
132142
responses.add(
133143
responses.DELETE,
134144
CLOUDSCALE_API_URL + "/servers/unknown",
@@ -194,7 +204,10 @@ def test_server_create():
194204
image = "debian9"
195205

196206
responses.add(
197-
responses.POST, CLOUDSCALE_API_URL + "/servers", json=SERVER_RESP, status=201
207+
responses.POST,
208+
CLOUDSCALE_API_URL + "/servers",
209+
json=SERVER_RESP,
210+
status=201,
198211
)
199212
responses.add(
200213
responses.POST,
@@ -245,7 +258,6 @@ def test_server_update():
245258
responses.add(
246259
responses.PATCH,
247260
CLOUDSCALE_API_URL + "/servers/" + uuid,
248-
json=SERVER_RESP,
249261
status=204,
250262
)
251263
responses.add(
@@ -298,7 +310,9 @@ def test_server_update():
298310
def test_server_start():
299311
uuid = "47cec963-fcd2-482f-bdb6-24461b2d47b1"
300312
responses.add(
301-
responses.POST, CLOUDSCALE_API_URL + "/servers/" + uuid + "/start", status=204
313+
responses.POST,
314+
CLOUDSCALE_API_URL + "/servers/" + uuid + "/start",
315+
status=204,
302316
)
303317
responses.add(
304318
responses.GET,
@@ -342,7 +356,9 @@ def test_server_start():
342356
def test_server_stop():
343357
uuid = "47cec963-fcd2-482f-bdb6-24461b2d47b1"
344358
responses.add(
345-
responses.POST, CLOUDSCALE_API_URL + "/servers/" + uuid + "/stop", status=204
359+
responses.POST,
360+
CLOUDSCALE_API_URL + "/servers/" + uuid + "/stop",
361+
status=204,
346362
)
347363
responses.add(
348364
responses.GET,
@@ -386,7 +402,9 @@ def test_server_stop():
386402
def test_server_reboot():
387403
uuid = "47cec963-fcd2-482f-bdb6-24461b2d47b1"
388404
responses.add(
389-
responses.POST, CLOUDSCALE_API_URL + "/servers/" + uuid + "/reboot", status=204
405+
responses.POST,
406+
CLOUDSCALE_API_URL + "/servers/" + uuid + "/reboot",
407+
status=204,
390408
)
391409
responses.add(
392410
responses.GET,

tests/test_server_group.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def test_server_groups_get_all():
3434
status=200,
3535
)
3636
responses.add(
37-
responses.GET, CLOUDSCALE_API_URL + "/server-groups", json={}, status=500
37+
responses.GET,
38+
CLOUDSCALE_API_URL + "/server-groups",
39+
status=500,
3840
)
3941

4042
runner = CliRunner()
@@ -121,7 +123,9 @@ def test_server_groups_delete():
121123
status=200,
122124
)
123125
responses.add(
124-
responses.DELETE, CLOUDSCALE_API_URL + "/server-groups/" + uuid, status=204
126+
responses.DELETE,
127+
CLOUDSCALE_API_URL + "/server-groups/" + uuid,
128+
status=204,
125129
)
126130
responses.add(
127131
responses.DELETE,
@@ -218,7 +222,6 @@ def test_server_groups_update():
218222
responses.add(
219223
responses.PATCH,
220224
CLOUDSCALE_API_URL + "/server-groups/" + uuid,
221-
json=SERVER_GROUP_RESP,
222225
status=204,
223226
)
224227
responses.add(
@@ -343,7 +346,6 @@ def test_invalid_tags_update():
343346
responses.add(
344347
responses.PATCH,
345348
CLOUDSCALE_API_URL + "/server-groups/" + uuid,
346-
json=SERVER_GROUP_RESP,
347349
status=204,
348350
)
349351
responses.add(

0 commit comments

Comments
 (0)