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

Commit

Permalink
Merge pull request #63 from postatum/99837454_wrong_error_code
Browse files Browse the repository at this point in the history
Use ES.get_resource to get ES item in ACLs
  • Loading branch information
jstoiko committed Jul 31, 2015
2 parents 884d24c + 1332975 commit 6ef62e6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
7 changes: 1 addition & 6 deletions ramses/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,7 @@ def getitem_es(self, key):
from nefertari.elasticsearch import ES
es = ES(self.__context_class__.__name__)
pk_field = self.__context_class__.pk_field()
kwargs = {
pk_field: key,
'_limit': 1,
'__raise_on_empty': True,
}
obj = es.get_collection(**kwargs)[0]
obj = es.get_resource(**{pk_field: key})
obj.__acl__ = self.context_acl(obj)
obj.__parent__ = self
obj.__name__ = key
Expand Down
5 changes: 2 additions & 3 deletions tests/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,15 @@ def test_getitem_db(self):
def test_getitem_es(self, mock_es):
found_obj = Mock()
es_obj = Mock()
es_obj.get_collection.return_value = [found_obj]
es_obj.get_resource.return_value = found_obj
mock_es.return_value = es_obj
obj = acl.BaseACL('req')
obj.__context_class__ = Mock(__name__='Foo')
obj.__context_class__.pk_field.return_value = 'myname'
obj.context_acl = Mock()
value = obj.getitem_es(key='varvar')
mock_es.assert_called_with('Foo')
es_obj.get_collection.assert_called_once_with(
myname='varvar', _limit=1, __raise_on_empty=True)
es_obj.get_resource.assert_called_once_with(myname='varvar')
obj.context_acl.assert_called_once_with(found_obj)
assert value.__acl__ == obj.context_acl()
assert value.__parent__ is obj
Expand Down

0 comments on commit 6ef62e6

Please sign in to comment.