async def test_deserialize_union(dummy_guillotina): assert schema_compatible(123456789, ITestSchema["union_field"]) == 123456789 now = datetime.utcnow() converted = schema_compatible(now.isoformat(), ITestSchema["union_field"]) assert converted.minute == now.minute with pytest.raises(ValueDeserializationError): schema_compatible("invalid-date", ITestSchema["union_field"])
async def test_deserialize_union_of_obj(dummy_guillotina): assert schema_compatible({"foo": "oooo"}, ITestSchema["union_field_obj"]) == { "foo": "oooo" } assert schema_compatible({"bar": "aaar"}, ITestSchema["union_field_obj"]) == { "bar": "aaar" } with pytest.raises(ValueDeserializationError): schema_compatible({"inexisting"}, ITestSchema["union_field_obj"])
def __call__(self, value): # if not isinstance(value, str) and not isinstance(value, bytes): # return value schema = self.field value = schema_compatible(value, schema) self.field.validate(value) return value
async def test_deserialize_dict(dummy_guillotina): assert schema_compatible({'foo': 'bar'}, ITestSchema['dict_value']) == { 'foo': 'bar' }
async def test_deserialize_int(dummy_guillotina): assert schema_compatible(5, ITestSchema['integer']) == 5
async def test_deserialize_dict(dummy_guillotina): assert schema_compatible({"foo": "bar"}, ITestSchema["dict_value"]) == { "foo": "bar" }
async def test_deserialize_tuple(dummy_guillotina): assert schema_compatible(["foo", "bar"], ITestSchema["tuple_of_text"]) == ("foo", "bar")
async def test_deserialize_float(dummy_guillotina): assert int(schema_compatible(5.5534, ITestSchema["floating"])) == 5
def __call__(self, value): schema = self.field value = schema_compatible(value, schema) self.field.validate(value) return value
async def test_deserialize_datetime(dummy_guillotina): now = datetime.utcnow() converted = schema_compatible(now.isoformat(), ITestSchema['datetime']) assert converted.minute == now.minute
async def test_deserialize_dict(dummy_guillotina): assert schema_compatible({'foo': 'bar'}, ITestSchema['dict_value']) == {'foo': 'bar'}
async def test_deserialize_frozenset(dummy_guillotina): assert len(schema_compatible(['foo', 'bar'], ITestSchema['frozenset_of_text'])) == 2
async def test_deserialize_tuple(dummy_guillotina): assert schema_compatible(['foo', 'bar'], ITestSchema['tuple_of_text']) == ('foo', 'bar')
async def test_deserialize_list(dummy_guillotina): assert schema_compatible(['foo', 'bar'], ITestSchema['list_of_text']) == ['foo', 'bar']
async def test_deserialize_float(dummy_guillotina): assert int(schema_compatible(5.5534, ITestSchema['floating'])) == 5
async def test_deserialize_text(dummy_guillotina): assert schema_compatible("foobar", ITestSchema["text"]) == "foobar"
async def test_deserialize_int(dummy_guillotina): assert schema_compatible(5, ITestSchema["integer"]) == 5
def test_python_schema(iterations): for _ in range(iterations): schema_compatible(TEST_PAYLOAD, IDublinCore)
async def test_deserialize_list(dummy_guillotina): assert schema_compatible(["foo", "bar"], ITestSchema["list_of_text"]) == ["foo", "bar"]
async def test_deserialize_text(dummy_guillotina): assert schema_compatible('foobar', ITestSchema['text']) == 'foobar'
async def test_deserialize_frozenset(dummy_guillotina): assert len( schema_compatible(["foo", "bar"], ITestSchema["frozenset_of_text"])) == 2
async def test_deserialize_list(dummy_guillotina): assert schema_compatible(['foo', 'bar'], ITestSchema['list_of_text']) == ['foo', 'bar']
async def test_deserialize_tuple(dummy_guillotina): assert schema_compatible(['foo', 'bar'], ITestSchema['tuple_of_text']) == ('foo', 'bar')
async def test_deserialize_frozenset(dummy_guillotina): assert len( schema_compatible(['foo', 'bar'], ITestSchema['frozenset_of_text'])) == 2
async def test_deserialize_datetime(dummy_guillotina): now = datetime.utcnow() converted = schema_compatible(now.isoformat(), ITestSchema["datetime"]) assert converted.minute == now.minute
async def test_deserialize_text(dummy_guillotina): assert schema_compatible('foobar', ITestSchema['text']) == 'foobar'