Esempio n. 1
0
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"])
Esempio n. 2
0
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"])
Esempio n. 3
0
 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
Esempio n. 4
0
async def test_deserialize_dict(dummy_guillotina):
    assert schema_compatible({'foo': 'bar'}, ITestSchema['dict_value']) == {
        'foo': 'bar'
    }
Esempio n. 5
0
async def test_deserialize_int(dummy_guillotina):
    assert schema_compatible(5, ITestSchema['integer']) == 5
Esempio n. 6
0
async def test_deserialize_dict(dummy_guillotina):
    assert schema_compatible({"foo": "bar"}, ITestSchema["dict_value"]) == {
        "foo": "bar"
    }
Esempio n. 7
0
async def test_deserialize_tuple(dummy_guillotina):
    assert schema_compatible(["foo", "bar"],
                             ITestSchema["tuple_of_text"]) == ("foo", "bar")
Esempio n. 8
0
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
Esempio n. 10
0
async def test_deserialize_datetime(dummy_guillotina):
    now = datetime.utcnow()
    converted = schema_compatible(now.isoformat(), ITestSchema['datetime'])
    assert converted.minute == now.minute
Esempio n. 11
0
async def test_deserialize_dict(dummy_guillotina):
    assert schema_compatible({'foo': 'bar'}, ITestSchema['dict_value']) == {'foo': 'bar'}
Esempio n. 12
0
async def test_deserialize_frozenset(dummy_guillotina):
    assert len(schema_compatible(['foo', 'bar'], ITestSchema['frozenset_of_text'])) == 2
Esempio n. 13
0
async def test_deserialize_tuple(dummy_guillotina):
    assert schema_compatible(['foo', 'bar'], ITestSchema['tuple_of_text']) == ('foo', 'bar')
Esempio n. 14
0
async def test_deserialize_list(dummy_guillotina):
    assert schema_compatible(['foo', 'bar'], ITestSchema['list_of_text']) == ['foo', 'bar']
Esempio n. 15
0
async def test_deserialize_float(dummy_guillotina):
    assert int(schema_compatible(5.5534, ITestSchema['floating'])) == 5
Esempio n. 16
0
async def test_deserialize_text(dummy_guillotina):
    assert schema_compatible("foobar", ITestSchema["text"]) == "foobar"
Esempio n. 17
0
async def test_deserialize_int(dummy_guillotina):
    assert schema_compatible(5, ITestSchema["integer"]) == 5
Esempio n. 18
0
def test_python_schema(iterations):
    for _ in range(iterations):
        schema_compatible(TEST_PAYLOAD, IDublinCore)
Esempio n. 19
0
async def test_deserialize_list(dummy_guillotina):
    assert schema_compatible(["foo", "bar"],
                             ITestSchema["list_of_text"]) == ["foo", "bar"]
Esempio n. 20
0
async def test_deserialize_text(dummy_guillotina):
    assert schema_compatible('foobar', ITestSchema['text']) == 'foobar'
Esempio n. 21
0
async def test_deserialize_frozenset(dummy_guillotina):
    assert len(
        schema_compatible(["foo", "bar"],
                          ITestSchema["frozenset_of_text"])) == 2
Esempio n. 22
0
async def test_deserialize_list(dummy_guillotina):
    assert schema_compatible(['foo', 'bar'],
                             ITestSchema['list_of_text']) == ['foo', 'bar']
Esempio n. 23
0
async def test_deserialize_tuple(dummy_guillotina):
    assert schema_compatible(['foo', 'bar'],
                             ITestSchema['tuple_of_text']) == ('foo', 'bar')
Esempio n. 24
0
async def test_deserialize_frozenset(dummy_guillotina):
    assert len(
        schema_compatible(['foo', 'bar'],
                          ITestSchema['frozenset_of_text'])) == 2
Esempio n. 25
0
async def test_deserialize_datetime(dummy_guillotina):
    now = datetime.utcnow()
    converted = schema_compatible(now.isoformat(), ITestSchema["datetime"])
    assert converted.minute == now.minute
Esempio n. 26
0
async def test_deserialize_text(dummy_guillotina):
    assert schema_compatible('foobar', ITestSchema['text']) == 'foobar'