예제 #1
0
def test_field_custom_attr_gettr():
    serializer = field('a', attr_getter=lambda x: x.a + 1)
    test_obj = TestObject()
    target = {}
    serializer.serialize(test_obj, target)

    assert {'a': 2} == target
예제 #2
0
def test_field_multiple():
    serializer = field('d', multiple=True)
    test_obj = TestObject()
    target = {}
    serializer.serialize(test_obj, target)

    assert {'d': [1, 2]} == target

    from_json = {'d': [1, 2]}
    target = {}
    serializer.deserialize(from_json, target)

    assert {'d': [1, 2]} == target
예제 #3
0
def test_dict_field():
    serializer = dict_field('a')
    test_obj = {'a': 'b'}
    target = {}
    serializer.serialize(test_obj, target)

    assert {'a': 'b'} == target

    from_json = {'a': 'b'}
    target = {}
    serializer.deserialize(from_json, target)

    assert {'a': 'b'} == target
예제 #4
0
def test_field():
    serializer = field('a')
    test_obj = TestObject()
    target = {}
    serializer.serialize(test_obj, target)

    assert {'a': 1} == target

    from_json = {'a': 1}
    target = {}
    serializer.deserialize(from_json, target)

    assert {'a': 1} == target
예제 #5
0
def test_dict_field():
    serializer = dict_field('a')
    test_obj = {'a': 'b'}
    target = {}
    serializer.serialize(test_obj, target)

    assert {'a': 'b'} == target

    from_json = {'a': 'b'}
    target = {}
    serializer.deserialize(from_json, target)

    assert {'a': 'b'} == target

    serializer = dict_field('empty')
    test_obj = {"empty": None}
    target = {}
    serializer.serialize(test_obj, target)

    assert {"empty": None} == target

    serializer = dict_field('empty')
    test_obj = {"empty": None}
    target = {}
    serializer.serialize(test_obj, target, serialization_context)

    assert {} == target
예제 #6
0
def test_field():
    serializer = field('a')
    test_obj = TestObject()
    target = {}
    serializer.serialize(test_obj, target)

    assert {'a': 1} == target

    from_json = {'a': 1}
    target = {}
    serializer.deserialize(from_json, target)

    assert {'a': 1} == target

    serializer = field('empty')
    test_obj = TestObject()
    target = {}
    serializer.serialize(test_obj, target)

    assert {"empty": None} == target

    serializer = field('empty')
    test_obj = TestObject()
    target = {}
    serializer.serialize(test_obj, target, serialization_context)

    assert {} == target
예제 #7
0
def test_field_multiple():
    serializer = multiple_field('d')
    test_obj = TestObject()
    target = {}
    serializer.serialize(test_obj, target)

    assert {'d': [1, 2]} == target

    from_json = {'d': [1, 2]}
    target = {}
    serializer.deserialize(from_json, target)

    assert {'d': [1, 2]} == target

    serializer = multiple_field('e')
    test_obj = TestObject()
    target = {}
    serializer.serialize(test_obj, target)

    assert {'e': []} == target

    serializer = multiple_field('e')
    test_obj = TestObject()
    target = {}
    serializer.serialize(test_obj, target, serialization_context)

    assert {'e': []} == target