Skip to content

Commit

Permalink
Move tests to call fields.get_value
Browse files Browse the repository at this point in the history
  • Loading branch information
arajkumar committed Mar 12, 2020
1 parent b1285df commit 1b145ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion flask_restplus/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def is_indexable_but_not_string(obj):


def is_integer_indexable(obj):
return isinstance(obj, list) or isinstance(obj, set)
return isinstance(obj, list) or isinstance(obj, tuple)


def get_value(key, obj, default=None):
Expand Down
20 changes: 12 additions & 8 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,6 @@ def test_with_attribute(self):
field = fields.Raw(attribute='bar')
assert field.output('foo', {'bar': 42}) == 42

def test_with_attribute_list(self):
field = fields.Raw(attribute='bar.0')
assert field.output('foo', {'bar': [42]}) == 42

def test_with_attribute_dict_list(self):
field = fields.Raw(attribute='bar.0.val')
assert field.output('foo', {'bar': [{'val': 42}]}) == 42

def test_with_lambda_attribute(self, mocker):
obj = mocker.Mock()
obj.value = 42
Expand Down Expand Up @@ -1387,3 +1379,15 @@ def __getitem__(self, n):

obj = Test('hi')
assert fields.get_value('value', obj) == 'hi'

def test_get_value_int_indexable_list(self):
assert fields.get_value('bar.0', {'bar': [42]}) == 42

def test_get_value_int_indexable_nested_list(self):
assert fields.get_value('bar.0.val', {'bar': [{'val': 42}]}) == 42

def test_get_value_int_indexable_tuple(self):
assert fields.get_value('bar.0', {'bar': (42, 43)}) == 42

def test_get_value_int_indexable_nested_tuple(self):
assert fields.get_value('bar.0.val', {'bar': [{'val': 42}]}) == 42

0 comments on commit 1b145ec

Please sign in to comment.