Exemple #1
0
 def test_nested_object(self, mocker):
     foo = mocker.Mock()
     bar = mocker.Mock()
     bar.value = 42
     foo.bar = bar
     field = fields.Raw()
     assert field.output('bar.value', foo) == 42
Exemple #2
0
    def test_with_partial_attribute(self, mocker):
        def f(x, suffix):
            return '{0}-{1}'.format(x.value, suffix)

        obj = mocker.Mock()
        obj.value = 42

        p = partial(f, suffix='whatever')
        field = fields.Raw(attribute=p)
        assert field.output('foo', obj) == '42-whatever'
Exemple #3
0
 def test_object(self, mocker):
     obj = mocker.Mock()
     obj.foo = 42
     field = fields.Raw()
     assert field.output('foo', obj) == 42
Exemple #4
0
 def test_attribute_not_found(self):
     field = fields.Raw()
     assert field.output('foo', {'bar': 42}) is None
Exemple #5
0
 def test_with_lambda_attribute(self, mocker):
     obj = mocker.Mock()
     obj.value = 42
     field = fields.Raw(attribute=lambda x: x.value)
     assert field.output('foo', obj) == 42
Exemple #6
0
 def test_with_attribute(self):
     field = fields.Raw(attribute='bar')
     assert field.output('foo', {'bar': 42}) == 42
Exemple #7
0
 def test_default_as_callable(self):
     field = fields.Raw(default=lambda: 'aaa')
     assert field.__schema__['default'] == 'aaa'
     self.assert_field(field, None, 'aaa')
Exemple #8
0
 def test_default(self):
     field = fields.Raw(default='aaa')
     assert field.__schema__['default'] == 'aaa'
     self.assert_field(field, None, 'aaa')
Exemple #9
0
 def test_type(self):
     field = fields.Raw()
     assert field.__schema__['type'] == 'object'