Fixed field source tests

This commit is contained in:
Syrus Akbary 2017-08-01 15:24:31 -07:00
parent 10a3e86cc5
commit 7f33fbe638

View File

@ -20,7 +20,8 @@ class MyInstance(object):
def test_field_basic(): def test_field_basic():
MyType = object() MyType = object()
args = {'my arg': Argument(True)} args = {'my arg': Argument(True)}
resolver = lambda: None
def resolver(): return None
deprecation_reason = 'Deprecated now' deprecation_reason = 'Deprecated now'
description = 'My Field' description = 'My Field'
my_default = 'something' my_default = 'something'
@ -60,7 +61,7 @@ def test_field_default_value_not_callable():
def test_field_source(): def test_field_source():
MyType = object() MyType = object()
field = Field(MyType, source='value') field = Field(MyType, source='value')
assert field.resolver(MyInstance, {}, None, None) == MyInstance.value assert field.resolver(MyInstance(), None) == MyInstance.value
def test_field_with_lazy_type(): def test_field_with_lazy_type():
@ -84,19 +85,20 @@ def test_field_not_source_and_resolver():
MyType = object() MyType = object()
with pytest.raises(Exception) as exc_info: with pytest.raises(Exception) as exc_info:
Field(MyType, source='value', resolver=lambda: None) Field(MyType, source='value', resolver=lambda: None)
assert str(exc_info.value) == 'A Field cannot have a source and a resolver in at the same time.' assert str(
exc_info.value) == 'A Field cannot have a source and a resolver in at the same time.'
def test_field_source_func(): def test_field_source_func():
MyType = object() MyType = object()
field = Field(MyType, source='value_func') field = Field(MyType, source='value_func')
assert field.resolver(MyInstance(), {}, None, None) == MyInstance.value_func() assert field.resolver(MyInstance(), None) == MyInstance.value_func()
def test_field_source_method(): def test_field_source_method():
MyType = object() MyType = object()
field = Field(MyType, source='value_method') field = Field(MyType, source='value_method')
assert field.resolver(MyInstance(), {}, None, None) == MyInstance().value_method() assert field.resolver(MyInstance(), None) == MyInstance().value_method()
def test_field_source_as_argument(): def test_field_source_as_argument():