def test_schema_unknown_fields(): input_data = {"a": {"a": "hello", "b": "world"}, "c": 1} with pytest.warns( UserWarning, match=re.escape("Unknown fields: ['c'] while parsing schema 'NestedSchema'"), ): obj = cryptocurrency.read_data(input_data, NestedSchema) assert cryptocurrency.serialize(obj) == input_data
def test_schema_unknown_fields(): input_data = {'a': {'a': 'hello', 'b': 'world'}, 'c': 1} with pytest.warns( UserWarning, match= r"Unknown fields: \['c'\] while parsing schema 'NestedSchema'", ): cryptocurrency.read_data(input_data, NestedSchema) obj = cryptocurrency.read_data(input_data, NestedSchema) assert cryptocurrency.serialize(obj) == input_data
def test_parse(): assert cryptocurrency.ResponseStatus._fields != cryptocurrency.Quote._fields cryptocurrency.Platform( # nosec id=1, name="name", symbol="symbol", slug="slug", token_address="foobar", ) assert len(cryptocurrency.Platform._fields) == 5 data = { "status": { "timestamp": "ts", "error_code": 200, "error_message": None, "elapsed": 1, "credit_count": 1, "notice": None, } } obj = cryptocurrency.read_data(data, cryptocurrency.APIRequestResponse) assert obj.status.credit_count == 1 assert cryptocurrency.serialize(obj) == data
def test_parse(): assert cryptocurrency.ResponseStatus._fields != cryptocurrency.Quote._fields cryptocurrency.Platform( id=1, name='name', symbol='symbol', slug='slug', token_address='token', ) assert len(cryptocurrency.Platform._fields) == 5 data = { 'status': { 'timestamp': 'ts', 'error_code': 200, 'error_message': None, 'elapsed': 1, 'credit_count': 1, 'notice': None, } } obj = cryptocurrency.read_data(data, cryptocurrency.APIRequestResponse) assert obj.status.credit_count == 1 assert cryptocurrency.serialize(obj) == data