Skip to content

Commit 3af327d

Browse files
committed
test: update responses stream usage
1 parent a7f02a8 commit 3af327d

File tree

1 file changed

+26
-45
lines changed

1 file changed

+26
-45
lines changed

test/unit/test_cloudant_base_error_augment.py

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class MockResponse(TypedDict):
2727
body: Union[dict[str,Any], str, bytes, None]
2828
headers: dict[str, str]
2929
status: int
30-
stream: bool
3130

3231
class ExpectedResponse(TypedDict, total=False):
3332
body: Union[dict[str,Any], str, bytes, None]
@@ -85,10 +84,10 @@ def _run_test(
8584
mock_response: MockResponse = {
8685
'body': _error_reason_body,
8786
'headers': _default_mock_headers,
88-
'status': 444,
89-
'stream': False
87+
'status': 444
9088
},
91-
expected_response: ExpectedResponse = None
89+
expected_response: ExpectedResponse = None,
90+
stream=False
9291
) -> Union[Exception, None]:
9392

9493
if expected_response is None:
@@ -122,7 +121,7 @@ def _run_test(
122121
)
123122
if expect_raises:
124123
with self.assertRaisesRegex(ApiException, expected_response['message']) as e_ctx:
125-
self._make_request(method, mock_response['stream'])
124+
self._make_request(method, stream)
126125
caught_exception = e_ctx.exception
127126
actual_status_code = caught_exception.status_code
128127
actual_headers = caught_exception.http_response.headers
@@ -139,7 +138,7 @@ def _run_test(
139138
actual_body = caught_exception.http_response.text
140139
else:
141140
try:
142-
service_response = self._make_request(method, mock_response['stream'])
141+
service_response = self._make_request(method, stream)
143142
actual_status_code = service_response.get_status_code()
144143
actual_headers = service_response.get_headers()
145144
actual_body = service_response.get_result()
@@ -189,8 +188,7 @@ def test_augment_error(self):
189188
mock_response={
190189
'body': self._error_only_body,
191190
'headers': self._content_type_header,
192-
'status': 444,
193-
'stream': False
191+
'status': 444
194192
},
195193
expected_response={
196194
'body': self._error_only_body | self._errors_error_only
@@ -202,8 +200,7 @@ def test_augment_error_with_trace(self):
202200
mock_response={
203201
'body': self._error_only_body,
204202
'headers': self._default_mock_headers,
205-
'status': 444,
206-
'stream': False
203+
'status': 444
207204
},
208205
expected_response={
209206
'body': self._error_only_body | self._errors_error_only | self._trace
@@ -215,8 +212,7 @@ def test_augment_error_reason(self):
215212
mock_response={
216213
'body': self._error_reason_body,
217214
'headers': self._content_type_header,
218-
'status': 444,
219-
'stream': False
215+
'status': 444
220216
},
221217
expected_response={
222218
'body': self._error_reason_body | self._errors_error_reason
@@ -228,8 +224,7 @@ def test_augment_error_reason_with_trace(self):
228224
mock_response={
229225
'body': self._error_reason_body,
230226
'headers': self._default_mock_headers,
231-
'status': 444,
232-
'stream': False
227+
'status': 444
233228
},
234229
expected_response={
235230
'body': self._error_reason_body | self._errors_error_reason | self._trace
@@ -241,21 +236,20 @@ def test_augment_error_reason_stream(self):
241236
mock_response={
242237
'body': self._error_reason_body,
243238
'headers': self._default_mock_headers,
244-
'status': 444,
245-
'stream': True
239+
'status': 444
246240
},
247241
expected_response={
248242
'body': self._error_reason_body | self._errors_error_reason | self._trace
249-
}
243+
},
244+
stream = True
250245
)
251246

252247
def test_augment_json_charset(self):
253248
self._run_test(
254249
mock_response={
255250
'body': self._error_reason_body,
256251
'headers': self._request_id_header | {'content-type': 'application/json; charset=utf-8'},
257-
'status': 444,
258-
'stream': False
252+
'status': 444
259253
},
260254
expected_response={
261255
'body': self._error_reason_body | self._errors_error_reason | self._trace
@@ -267,8 +261,7 @@ def test_augment_no_header(self):
267261
mock_response={
268262
'body': self._error_reason_body,
269263
'headers': self._content_type_header,
270-
'status': 444,
271-
'stream': False
264+
'status': 444
272265
},
273266
expected_response={
274267
'body': self._error_reason_body | self._errors_error_reason
@@ -280,8 +273,7 @@ def test_no_augment_success(self):
280273
mock_response={
281274
'body': {'_id': self._doc_id, '_rev': '1-abc', 'foo': 'bar'},
282275
'headers': self._default_mock_headers,
283-
'status': 200,
284-
'stream': False
276+
'status': 200
285277
}
286278
)
287279

@@ -291,8 +283,7 @@ def test_no_augment_head(self):
291283
mock_response={
292284
'body': None,
293285
'headers': self._default_mock_headers,
294-
'status': 444,
295-
'stream': False
286+
'status': 444
296287
},
297288
expected_response={
298289
'body': b'', # no body content for HEAD
@@ -305,8 +296,7 @@ def test_no_augment_id_only(self):
305296
mock_response={
306297
'body': {},
307298
'headers': self._default_mock_headers,
308-
'status': 444,
309-
'stream': False
299+
'status': 444
310300
},
311301
expected_response={
312302
'body': {},
@@ -324,8 +314,7 @@ def test_no_augment_existing_trace(self):
324314
mock_response={
325315
'body': test_body,
326316
'headers': self._default_mock_headers,
327-
'status': 429,
328-
'stream': False
317+
'status': 429
329318
},
330319
expected_response={
331320
'body': test_body,
@@ -347,8 +336,7 @@ def test_no_augment_existing_errors_no_id(self):
347336
mock_response={
348337
'body': test_body,
349338
'headers': self._content_type_header,
350-
'status': 403,
351-
'stream': False
339+
'status': 403
352340
},
353341
expected_response={
354342
'body': test_body,
@@ -369,8 +357,7 @@ def test_augment_trace_existing_errors(self):
369357
mock_response={
370358
'body': test_body,
371359
'headers': self._default_mock_headers,
372-
'status': 403,
373-
'stream': False
360+
'status': 403
374361
},
375362
expected_response={
376363
'body': test_body | self._trace
@@ -383,8 +370,7 @@ def test_no_augment_non_json(self):
383370
mock_response={
384371
'body': test_body,
385372
'headers': self._request_id_header | {'content-type': 'text/plain'},
386-
'status': 400,
387-
'stream': False
373+
'status': 400
388374
},
389375
expected_response={
390376
'body': test_body,
@@ -398,8 +384,7 @@ def test_no_augment_no_content_type(self):
398384
mock_response={
399385
'body': test_body,
400386
'headers': self._request_id_header,
401-
'status': 444,
402-
'stream': False
387+
'status': 444
403388
},
404389
expected_response={
405390
'body': test_body,
@@ -413,8 +398,7 @@ def test_no_augment_no_error(self):
413398
mock_response={
414399
'body': test_body,
415400
'headers': self._default_mock_headers,
416-
'status': 400,
417-
'stream': False
401+
'status': 400
418402
},
419403
expected_response={
420404
'body': test_body,
@@ -428,8 +412,7 @@ def test_no_augment_no_error_no_header(self):
428412
mock_response={
429413
'body': test_body,
430414
'headers': self._content_type_header,
431-
'status': 400,
432-
'stream': False
415+
'status': 400
433416
},
434417
expected_response={
435418
'body': test_body,
@@ -443,8 +426,7 @@ def test_no_augment_invalid_json(self):
443426
mock_response={
444427
'body': test_body,
445428
'headers': self._content_type_header,
446-
'status': 400,
447-
'stream': False
429+
'status': 400
448430
},
449431
expected_response={
450432
'body': test_body,
@@ -460,8 +442,7 @@ def test_augment_error_empty_reason_with_trace(self):
460442
mock_response={
461443
'body': test_body,
462444
'headers': self._default_mock_headers,
463-
'status': 444,
464-
'stream': False
445+
'status': 444
465446
},
466447
expected_response={
467448
'body': test_body | self._errors_error_only | self._trace,

0 commit comments

Comments
 (0)