11import json
22import pytest
33
4- from nypl_py_utils .classes .avro_client import AvroDecoder , AvroEncoder , AvroClientError
4+ from nypl_py_utils .classes .avro_client import (
5+ AvroDecoder , AvroEncoder , AvroClientError )
56from requests .exceptions import ConnectTimeout
67
78_TEST_SCHEMA = {'data' : {'schema' : json .dumps ({
1920 ]
2021})}}
2122
23+
2224class TestAvroClient :
2325
2426 @pytest .fixture
@@ -33,9 +35,12 @@ def test_avro_decoder_instance(self, requests_mock):
3335 'https://test_schema_url' , text = json .dumps (_TEST_SCHEMA ))
3436 return AvroDecoder ('https://test_schema_url' )
3537
36- def test_get_json_schema (self , test_avro_encoder_instance , test_avro_decoder_instance ):
37- assert test_avro_encoder_instance .schema == _TEST_SCHEMA ['data' ]['schema' ]
38- assert test_avro_decoder_instance .schema == _TEST_SCHEMA ['data' ]['schema' ]
38+ def test_get_json_schema (self , test_avro_encoder_instance ,
39+ test_avro_decoder_instance ):
40+ assert test_avro_encoder_instance .schema == _TEST_SCHEMA ['data' ][
41+ 'schema' ]
42+ assert test_avro_decoder_instance .schema == _TEST_SCHEMA ['data' ][
43+ 'schema' ]
3944
4045 def test_request_error (self , requests_mock ):
4146 requests_mock .get ('https://test_schema_url' , exc = ConnectTimeout )
@@ -54,18 +59,21 @@ def test_missing_key_error(self, requests_mock):
5459 with pytest .raises (AvroClientError ):
5560 AvroEncoder ('https://test_schema_url' )
5661
57- def test_encode_record (self , test_avro_encoder_instance , test_avro_decoder_instance ):
62+ def test_encode_record (self , test_avro_encoder_instance ,
63+ test_avro_decoder_instance ):
5864 TEST_RECORD = {'patron_id' : 123 , 'library_branch' : 'aa' }
5965 encoded_record = test_avro_encoder_instance .encode_record (TEST_RECORD )
6066 assert type (encoded_record ) is bytes
61- assert test_avro_decoder_instance .decode_record (encoded_record ) == TEST_RECORD
67+ assert test_avro_decoder_instance .decode_record (
68+ encoded_record ) == TEST_RECORD
6269
6370 def test_encode_record_error (self , test_avro_encoder_instance ):
6471 TEST_RECORD = {'patron_id' : 123 , 'bad_field' : 'bad' }
6572 with pytest .raises (AvroClientError ):
6673 test_avro_encoder_instance .encode_record (TEST_RECORD )
6774
68- def test_encode_batch (self , test_avro_encoder_instance , test_avro_decoder_instance ):
75+ def test_encode_batch (self , test_avro_encoder_instance ,
76+ test_avro_decoder_instance ):
6977 TEST_BATCH = [
7078 {'patron_id' : 123 , 'library_branch' : 'aa' },
7179 {'patron_id' : 456 , 'library_branch' : None },
@@ -89,10 +97,11 @@ def test_decode_record_binary(self, test_avro_decoder_instance):
8997 TEST_ENCODED_RECORD = b'\xf6 \x01 \x02 \x04 aa'
9098 assert test_avro_decoder_instance .decode_record (
9199 TEST_ENCODED_RECORD ) == TEST_DECODED_RECORD
92-
100+
93101 def test_decode_record_b64 (self , test_avro_decoder_instance ):
94102 TEST_DECODED_RECORD = {"patron_id'" : 123 , "library_branch" : "aa" }
95- TEST_ENCODED_RECORD = "eyJwYXRyb25faWQnIjogMTIzLCAibGlicmFyeV9icmFuY2giOiAiYWEifQ=="
103+ TEST_ENCODED_RECORD = (
104+ "eyJwYXRyb25faWQnIjogMTIzLCAibGlicmFyeV9icmFuY2giOiAiYWEifQ==" )
96105 assert test_avro_decoder_instance .decode_record (
97106 TEST_ENCODED_RECORD , "base64" ) == TEST_DECODED_RECORD
98107
0 commit comments