1
1
import httpx
2
2
import pytest
3
- import pytest_asyncio # noqa: F401
4
- from munch import Munch
3
+ import pytest_asyncio
5
4
from asyncmock import AsyncMock
6
5
7
- from tests .data .mock_data import configtree_body # noqa: F401
8
- from tests .utils .fixtures import async_client as client # noqa: F401
6
+ # ruff: noqa: F811, F401
7
+ from tests .data .mock_data import configtree_body
8
+ from tests .utils .fixtures import async_client
9
9
10
10
11
11
@pytest .mark .asyncio
12
- async def test_list_configtrees_success (client , mocker : AsyncMock ): # noqa: F811
12
+ async def test_list_configtrees_success (async_client , mocker : AsyncMock ):
13
13
# Mock the httpx.AsyncClient.get method
14
14
mock_get = mocker .patch ("httpx.AsyncClient.get" )
15
15
@@ -23,17 +23,16 @@ async def test_list_configtrees_success(client, mocker: AsyncMock): # noqa: F81
23
23
)
24
24
25
25
# Call the list_configtrees method
26
- response = await client .list_configtrees ()
26
+ response = await async_client .list_configtrees ()
27
27
28
28
# Validate the response
29
- assert isinstance (response , Munch )
30
29
assert response ["items" ] == [
31
30
{"name" : "test-configtree" , "guid" : "mock_configtree_guid" }
32
31
]
33
32
34
33
35
34
@pytest .mark .asyncio
36
- async def test_list_configtrees_bad_gateway (client , mocker : AsyncMock ): # noqa: F811
35
+ async def test_list_configtrees_bad_gateway (async_client , mocker : AsyncMock ):
37
36
# Mock the httpx.AsyncClient.get method
38
37
mock_get = mocker .patch ("httpx.AsyncClient.get" )
39
38
@@ -45,13 +44,13 @@ async def test_list_configtrees_bad_gateway(client, mocker: AsyncMock): # noqa:
45
44
46
45
# Call the list_configtrees method
47
46
with pytest .raises (Exception ) as exc :
48
- await client .list_configtrees ()
47
+ await async_client .list_configtrees ()
49
48
50
49
assert str (exc .value ) == "bad gateway"
51
50
52
51
53
52
@pytest .mark .asyncio
54
- async def test_create_configtree_success (client , mocker : AsyncMock ): # noqa: F811
53
+ async def test_create_configtree_success (async_client , mocker : AsyncMock ):
55
54
# Mock the httpx.AsyncClient.post method
56
55
mock_post = mocker .patch ("httpx.AsyncClient.post" )
57
56
@@ -64,15 +63,14 @@ async def test_create_configtree_success(client, mocker: AsyncMock): # noqa: F8
64
63
)
65
64
66
65
# Call the create_configtree method
67
- response = await client .create_configtree (configtree_body )
66
+ response = await async_client .create_configtree (configtree_body )
68
67
69
68
# Validate the response
70
- assert isinstance (response , Munch )
71
69
assert response ["metadata" ]["guid" ] == "test_configtree_guid"
72
70
73
71
74
72
@pytest .mark .asyncio
75
- async def test_create_configtree_service_unavailable (client , mocker : AsyncMock ): # noqa: F811
73
+ async def test_create_configtree_service_unavailable (async_client , mocker : AsyncMock ):
76
74
# Mock the httpx.AsyncClient.post method
77
75
mock_post = mocker .patch ("httpx.AsyncClient.post" )
78
76
@@ -84,13 +82,13 @@ async def test_create_configtree_service_unavailable(client, mocker: AsyncMock):
84
82
85
83
# Call the create_configtree method
86
84
with pytest .raises (Exception ) as exc :
87
- await client .create_configtree (configtree_body )
85
+ await async_client .create_configtree (configtree_body )
88
86
89
87
assert str (exc .value ) == "service unavailable"
90
88
91
89
92
90
@pytest .mark .asyncio
93
- async def test_get_configtree_success (client , mocker : AsyncMock ): # noqa: F811
91
+ async def test_get_configtree_success (async_client , mocker : AsyncMock ):
94
92
# Mock the httpx.AsyncClient.get method
95
93
mock_get = mocker .patch ("httpx.AsyncClient.get" )
96
94
@@ -103,16 +101,15 @@ async def test_get_configtree_success(client, mocker: AsyncMock): # noqa: F811
103
101
)
104
102
105
103
# Call the get_configtree method
106
- response = await client .get_configtree (name = "mock_configtree_name" )
104
+ response = await async_client .get_configtree (name = "mock_configtree_name" )
107
105
108
106
# Validate the response
109
- assert isinstance (response , Munch )
110
- assert response .metadata .guid == "test_configtree_guid"
111
- assert response .metadata .name == "test_configtree"
107
+ assert response ["metadata" ]["guid" ] == "test_configtree_guid"
108
+ assert response ["metadata" ]["name" ] == "test_configtree"
112
109
113
110
114
111
@pytest .mark .asyncio
115
- async def test_set_configtree_revision_success (client , mocker : AsyncMock ): # noqa: F811
112
+ async def test_set_configtree_revision_success (async_client , mocker : AsyncMock ):
116
113
# Mock the httpx.AsyncClient.put method
117
114
mock_put = mocker .patch ("httpx.AsyncClient.put" )
118
115
@@ -125,42 +122,34 @@ async def test_set_configtree_revision_success(client, mocker: AsyncMock): # no
125
122
)
126
123
127
124
# Call the set_configtree_revision method
128
- response = await client .set_configtree_revision (
125
+ response = await async_client .set_configtree_revision (
129
126
name = "mock_configtree_name" , configtree = configtree_body
130
127
)
131
128
132
129
# Validate the response
133
- assert isinstance (response , Munch )
134
- assert response .metadata .guid == "test_configtree_guid"
135
- assert response .metadata .name == "test_configtree"
130
+ assert response ["metadata" ]["guid" ] == "test_configtree_guid"
131
+ assert response ["metadata" ]["name" ] == "test_configtree"
136
132
137
133
138
134
@pytest .mark .asyncio
139
- async def test_update_configtree_success (client , mocker : AsyncMock ): # noqa: F811
135
+ async def test_update_configtree_success (async_client , mocker : AsyncMock ):
140
136
# Mock the httpx.AsyncClient.put method
141
137
mock_put = mocker .patch ("httpx.AsyncClient.put" )
142
-
143
- # Set up the mock response
144
138
mock_put .return_value = httpx .Response (
145
139
status_code = 200 ,
146
140
json = {
147
141
"metadata" : {"guid" : "test_configtree_guid" , "name" : "test_configtree" },
148
142
},
149
143
)
150
-
151
- # Call the update_configtree method
152
- response = await client .update_configtree (
144
+ response = await async_client .update_configtree (
153
145
name = "mock_configtree_name" , body = configtree_body
154
146
)
155
-
156
- # Validate the response
157
- assert isinstance (response , Munch )
158
- assert response .metadata .guid == "test_configtree_guid"
159
- assert response .metadata .name == "test_configtree"
147
+ assert response ["metadata" ]["guid" ] == "test_configtree_guid"
148
+ assert response ["metadata" ]["name" ] == "test_configtree"
160
149
161
150
162
151
@pytest .mark .asyncio
163
- async def test_delete_configtree_success (client , mocker : AsyncMock ): # noqa: F811
152
+ async def test_delete_configtree_success (async_client , mocker : AsyncMock ):
164
153
# Mock the httpx.AsyncClient.delete method
165
154
mock_delete = mocker .patch ("httpx.AsyncClient.delete" )
166
155
@@ -171,14 +160,14 @@ async def test_delete_configtree_success(client, mocker: AsyncMock): # noqa: F8
171
160
)
172
161
173
162
# Call the delete_configtree method
174
- response = await client .delete_configtree (name = "mock_configtree_name" )
163
+ response = await async_client .delete_configtree (name = "mock_configtree_name" )
175
164
176
165
# Validate the response
177
- assert response [ "success" ] is True
166
+ assert response is None
178
167
179
168
180
169
@pytest .mark .asyncio
181
- async def test_list_revisions_success (client , mocker : AsyncMock ): # noqa: F811
170
+ async def test_list_revisions_success (async_client , mocker : AsyncMock ):
182
171
# Mock the httpx.AsyncClient.get method
183
172
mock_get = mocker .patch ("httpx.AsyncClient.get" )
184
173
@@ -192,17 +181,16 @@ async def test_list_revisions_success(client, mocker: AsyncMock): # noqa: F811
192
181
)
193
182
194
183
# Call the list_revisions method
195
- response = await client .list_revisions (tree_name = "mock_configtree_name" )
184
+ response = await async_client .list_revisions (tree_name = "mock_configtree_name" )
196
185
197
186
# Validate the response
198
- assert isinstance (response , Munch )
199
187
assert response ["items" ] == [
200
188
{"name" : "test-configtree" , "guid" : "mock_configtree_guid" }
201
189
]
202
190
203
191
204
192
@pytest .mark .asyncio
205
- async def test_create_revision_success (client , mocker : AsyncMock ): # noqa: F811
193
+ async def test_create_revision_success (async_client , mocker : AsyncMock ):
206
194
# Mock the httpx.AsyncClient.post method
207
195
mock_post = mocker .patch ("httpx.AsyncClient.post" )
208
196
@@ -215,17 +203,16 @@ async def test_create_revision_success(client, mocker: AsyncMock): # noqa: F811
215
203
)
216
204
217
205
# Call the create_revision method
218
- response = await client .create_revision (
206
+ response = await async_client .create_revision (
219
207
name = "mock_configtree_name" , body = configtree_body
220
208
)
221
209
222
210
# Validate the response
223
- assert isinstance (response , Munch )
224
211
assert response ["metadata" ]["guid" ] == "test_revision_guid"
225
212
226
213
227
214
@pytest .mark .asyncio
228
- async def test_put_keys_in_revision_success (client , mocker : AsyncMock ): # noqa: F811
215
+ async def test_put_keys_in_revision_success (async_client , mocker : AsyncMock ):
229
216
# Mock the httpx.AsyncClient.put method
230
217
mock_put = mocker .patch ("httpx.AsyncClient.put" )
231
218
@@ -238,20 +225,19 @@ async def test_put_keys_in_revision_success(client, mocker: AsyncMock): # noqa:
238
225
)
239
226
240
227
# Call the put_keys_in_revision method
241
- response = await client .put_keys_in_revision (
228
+ response = await async_client .put_keys_in_revision (
242
229
name = "mock_configtree_name" ,
243
230
revision_id = "mock_revision_id" ,
244
231
config_values = ["mock_value1" , "mock_value2" ],
245
232
)
246
233
247
234
# Validate the response
248
- assert isinstance (response , Munch )
249
- assert response .metadata .guid == "test_revision_guid"
250
- assert response .metadata .name == "test_revision"
235
+ assert response ["metadata" ]["guid" ] == "test_revision_guid"
236
+ assert response ["metadata" ]["name" ] == "test_revision"
251
237
252
238
253
239
@pytest .mark .asyncio
254
- async def test_commit_revision_success (client , mocker : AsyncMock ): # noqa: F811
240
+ async def test_commit_revision_success (async_client , mocker : AsyncMock ):
255
241
# Mock the httpx.AsyncClient.put method
256
242
mock_patch = mocker .patch ("httpx.AsyncClient.patch" )
257
243
@@ -264,19 +250,18 @@ async def test_commit_revision_success(client, mocker: AsyncMock): # noqa: F811
264
250
)
265
251
266
252
# Call the commit_revision method
267
- response = await client .commit_revision (
253
+ response = await async_client .commit_revision (
268
254
tree_name = "mock_configtree_name" ,
269
255
revision_id = "mock_revision_id" ,
270
256
)
271
257
272
258
# Validate the response
273
- assert isinstance (response , Munch )
274
- assert response .metadata .guid == "test_revision_guid"
275
- assert response .metadata .name == "test_revision"
259
+ assert response ["metadata" ]["guid" ] == "test_revision_guid"
260
+ assert response ["metadata" ]["name" ] == "test_revision"
276
261
277
262
278
263
@pytest .mark .asyncio
279
- async def test_get_key_in_revision (client , mocker : AsyncMock ): # noqa: F811
264
+ async def test_get_key_in_revision (async_client , mocker : AsyncMock ):
280
265
# Mock the httpx.AsyncClient.get method
281
266
mock_get = mocker .patch ("httpx.AsyncClient.get" )
282
267
@@ -289,18 +274,17 @@ async def test_get_key_in_revision(client, mocker: AsyncMock): # noqa: F811
289
274
)
290
275
291
276
# Call the get_key_in_revision method
292
- response = await client .get_key_in_revision (
277
+ response = await async_client .get_key_in_revision (
293
278
tree_name = "mock_configtree_name" , revision_id = "mock_revision_id" , key = "mock_key"
294
279
)
295
280
296
281
# Validate the response
297
- assert isinstance (response , Munch )
298
- assert response .metadata .guid == "test_revision_guid"
299
- assert response .metadata .name == "test_revision"
282
+ assert response ["metadata" ]["guid" ] == "test_revision_guid"
283
+ assert response ["metadata" ]["name" ] == "test_revision"
300
284
301
285
302
286
@pytest .mark .asyncio
303
- async def test_put_key_in_revision_success (client , mocker : AsyncMock ): # noqa: F811
287
+ async def test_put_key_in_revision_success (async_client , mocker : AsyncMock ):
304
288
# Mock the httpx.AsyncClient.put method
305
289
mock_put = mocker .patch ("httpx.AsyncClient.put" )
306
290
@@ -313,34 +297,33 @@ async def test_put_key_in_revision_success(client, mocker: AsyncMock): # noqa:
313
297
)
314
298
315
299
# Call the put_key_in_revision method
316
- response = await client .put_key_in_revision (
300
+ response = await async_client .put_key_in_revision (
317
301
tree_name = "mock_configtree_name" , revision_id = "mock_revision_id" , key = "mock_key"
318
302
)
319
303
320
304
# Validate the response
321
- assert isinstance (response , Munch )
322
- assert response .metadata .guid == "test_revision_guid"
323
- assert response .metadata .name == "test_revision"
305
+ assert response ["metadata" ]["guid" ] == "test_revision_guid"
306
+ assert response ["metadata" ]["name" ] == "test_revision"
324
307
325
308
326
309
@pytest .mark .asyncio
327
- async def test_delete_key_in_revision_success (client , mocker : AsyncMock ): # noqa: F811
310
+ async def test_delete_key_in_revision_success (async_client , mocker : AsyncMock ):
328
311
mock_delete = mocker .patch ("httpx.AsyncClient.delete" )
329
312
330
313
mock_delete .return_value = httpx .Response (
331
314
status_code = 204 ,
332
315
json = {"success" : True },
333
316
)
334
317
335
- response = await client .delete_key_in_revision (
318
+ response = await async_client .delete_key_in_revision (
336
319
tree_name = "mock_configtree_name" , revision_id = "mock_revision_id" , key = "mock_key"
337
320
)
338
321
339
- assert response [ "success" ] is True
322
+ assert response is None
340
323
341
324
342
325
@pytest .mark .asyncio
343
- async def test_rename_key_in_revision_success (client , mocker : AsyncMock ): # noqa: F811
326
+ async def test_rename_key_in_revision_success (async_client , mocker : AsyncMock ):
344
327
mock_patch = mocker .patch ("httpx.AsyncClient.patch" )
345
328
346
329
mock_patch .return_value = httpx .Response (
@@ -350,13 +333,13 @@ async def test_rename_key_in_revision_success(client, mocker: AsyncMock): # noq
350
333
},
351
334
)
352
335
353
- response = await client .rename_key_in_revision (
336
+ response = await async_client .rename_key_in_revision (
354
337
tree_name = "mock_configtree_name" ,
355
338
revision_id = "mock_revision_id" ,
356
339
key = "mock_key" ,
357
340
config_key_rename = {"metadata" : {"name" : "test_key" }},
358
341
)
359
342
360
- assert isinstance (response , Munch )
361
- assert response . metadata . guid == "test_revision_guid"
362
- assert response . metadata . name == "test_revision"
343
+ assert isinstance (response , dict )
344
+ assert response [ " metadata" ][ " guid" ] == "test_revision_guid"
345
+ assert response [ " metadata" ][ " name" ] == "test_revision"
0 commit comments