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