Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop' of github.com:brandicted/nefertari into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoiko committed Jun 12, 2015
2 parents 2f69ec4 + 3f57390 commit e32e486
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nefertari/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,12 @@ def _get_object(id_):
if not ids:
return
if isinstance(ids, list):
self._json_params[name] = [_get_object(_id) for _id in ids]
self._json_params[name] = []
for _id in ids:
obj = _id if _id is None else _get_object(_id)
self._json_params[name].append(obj)
else:
self._json_params[name] = _get_object(ids)
self._json_params[name] = ids if ids is None else _get_object(ids)


class ESAggregationMixin(object):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,22 @@ def test_id2obj_setdefault(self, run):
model.pk_field.assert_called_once_with()
model.get.assert_called_once_with(idname='1')

@patch('nefertari.view.BaseView._run_init_actions')
def test_id2obj_value_none(self, run):
model = Mock()
model.pk_field.return_value = 'idname'
model.get.return_value = 'foo'
request = Mock(content_type='', method='', accept=[''], user=None)
view = BaseView(
context={}, request=request, _json_params={'foo': 'bar'},
_query_params={'foo1': 'bar1'})
view._json_params['users'] = [None, '1']
view._json_params['story'] = None
view.id2obj(name='users', model=model)
view.id2obj(name='story', model=model)
assert view._json_params['users'] == [None, 'foo']
assert view._json_params['story'] is None

@patch('nefertari.view.BaseView._run_init_actions')
def test_id2obj_already_object(self, run):
id_ = Mock()
Expand Down

0 comments on commit e32e486

Please sign in to comment.