|
1 | 1 | import json |
2 | 2 | import pytest |
| 3 | +from unittest.mock import patch |
3 | 4 |
|
4 | 5 | from nypl_py_utils.classes.avro_client import ( |
5 | | - AvroClientError, AvroDecoder, AvroEncoder) |
| 6 | + AvroClient, AvroClientError, AvroDecoder, AvroEncoder) |
| 7 | +from requests import session |
6 | 8 | from requests.exceptions import ConnectTimeout |
7 | 9 |
|
8 | 10 | _TEST_SCHEMA = {'data': {'schema': json.dumps({ |
@@ -36,15 +38,23 @@ def test_avro_decoder_instance(self, requests_mock): |
36 | 38 |
|
37 | 39 | def test_get_json_schema_success(self, test_avro_encoder_instance, |
38 | 40 | test_avro_decoder_instance): |
39 | | - assert test_avro_encoder_instance.schema == _TEST_SCHEMA['data'][ |
40 | | - 'schema'] |
41 | | - assert test_avro_decoder_instance.schema == _TEST_SCHEMA['data'][ |
42 | | - 'schema'] |
| 41 | + assert test_avro_encoder_instance.schema == _TEST_SCHEMA["data"][ |
| 42 | + "schema"] |
| 43 | + assert test_avro_decoder_instance.schema == _TEST_SCHEMA["data"][ |
| 44 | + "schema"] |
43 | 45 |
|
44 | | - def test_request_error(self, requests_mock): |
45 | | - requests_mock.get('https://test_schema_url', exc=ConnectTimeout) |
| 46 | + def test_get_json_schema_error(self, requests_mock): |
| 47 | + requests_mock.get("https://test_schema_url", exc=ConnectTimeout) |
46 | 48 | with pytest.raises(AvroClientError): |
47 | | - AvroEncoder('https://test_schema_url') |
| 49 | + AvroEncoder("https://test_schema_url") |
| 50 | + |
| 51 | + def test_get_json_schema_success_on_retry(self, requests_mock): |
| 52 | + requests_mock.get("https://test_schema_url", |
| 53 | + [{"exc": ConnectionError}, |
| 54 | + {"text": str(_TEST_SCHEMA), "status_code": 200}]) |
| 55 | + |
| 56 | + test_avro_client = AvroClient("https://test_schema_url") |
| 57 | + assert test_avro_client.get_json_schema == _TEST_SCHEMA["data"]["schema"] |
48 | 58 |
|
49 | 59 | def test_bad_json_error(self, requests_mock): |
50 | 60 | requests_mock.get( |
|
0 commit comments