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
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'
def test_object(self, mocker): obj = mocker.Mock() obj.foo = 42 field = fields.Raw() assert field.output('foo', obj) == 42
def test_attribute_not_found(self): field = fields.Raw() assert field.output('foo', {'bar': 42}) is None
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
def test_with_attribute(self): field = fields.Raw(attribute='bar') assert field.output('foo', {'bar': 42}) == 42
def test_default_as_callable(self): field = fields.Raw(default=lambda: 'aaa') assert field.__schema__['default'] == 'aaa' self.assert_field(field, None, 'aaa')
def test_default(self): field = fields.Raw(default='aaa') assert field.__schema__['default'] == 'aaa' self.assert_field(field, None, 'aaa')
def test_type(self): field = fields.Raw() assert field.__schema__['type'] == 'object'