Ejemplo n.º 1
0
def test_serializer_source_wildcard():
    """
    Test that '*' wildcard causes whole instance is returned on get attribute
    """
    serializer = BaseSerializer()

    instance = {"foo", "bar"}
    assert serializer.get_attribute(instance, '*') == instance
Ejemplo n.º 2
0
def test_serializer_source_wildcard():
    """
    Test that '*' wildcard causes whole instance is returned on get attribute
    """
    serializer = BaseSerializer()

    instance = {"foo", "bar"}
    assert serializer.get_attribute(instance, '*') == instance
Ejemplo n.º 3
0
def test_serializer_set_attribute():
    serializer = BaseSerializer()

    # test dict keys are treated as attributes
    instance = {}
    serializer.set_attribute(instance, 'foo', 'bar')
    assert instance == {'foo': 'bar'}

    # test normal objects atrributes are attributes indeed
    # in scope of this method
    class SomeObject():
        def __init__(self):
            self.foo = None

    instance = SomeObject()
    serializer.set_attribute(instance, 'foo', 'bar')
    assert instance.foo == 'bar'
Ejemplo n.º 4
0
def test_serializer_get_attribute():
    serializer = BaseSerializer()

    # test dict keys are treated as attributes
    instance = {'foo': 'bar'}
    assert serializer.get_attribute(instance, 'foo') == 'bar'

    # test normal objects atrributes are attributes indeed
    # in scope of this method
    class SomeObject():
        def __init__(self):
            self.foo = 'bar'

    instance = SomeObject()
    assert serializer.get_attribute(instance, 'foo') == 'bar'

    # test that getting non existent attribute returns None
    assert serializer.get_attribute(instance, 'nonexistens') is None
Ejemplo n.º 5
0
def test_serializer_get_attribute():
    serializer = BaseSerializer()

    # test dict keys are treated as attributes
    instance = {'foo': 'bar'}
    assert serializer.get_attribute(instance, 'foo') == 'bar'

    # test normal objects atrributes are attributes indeed
    # in scope of this method
    class SomeObject():
        def __init__(self):
            self.foo = 'bar'

    instance = SomeObject()
    assert serializer.get_attribute(instance, 'foo') == 'bar'

    # test that getting non existent attribute returns None
    assert serializer.get_attribute(instance, 'nonexistens') is None
Ejemplo n.º 6
0
def test_serializer_set_attribute():
    serializer = BaseSerializer()

    # test dict keys are treated as attributes
    instance = {}
    serializer.set_attribute(instance, 'foo', 'bar')
    assert instance == {'foo': 'bar'}

    # test normal objects atrributes are attributes indeed
    # in scope of this method
    class SomeObject():
        def __init__(self):
            self.foo = None

    instance = SomeObject()
    serializer.set_attribute(instance, 'foo', 'bar')
    assert instance.foo == 'bar'