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 #98 from postatum/94963198_to_dict_nesting
Browse files Browse the repository at this point in the history
Rename ES.index_refs. Default nesting depth to 1
  • Loading branch information
jstoiko committed Aug 29, 2015
2 parents b2a4d9f + 214968f commit a80f881
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions nefertari/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import six

from nefertari.utils import (
dictset, dict2obj, process_limit, split_strip)
dictset, dict2obj, process_limit, split_strip, to_dicts)
from nefertari.json_httpexceptions import (
JHTTPBadRequest, JHTTPNotFound, exception_response)
from nefertari import engine, RESERVED_PARAMS
Expand Down Expand Up @@ -322,7 +322,7 @@ def _bulk(self, action, documents, request=None):
else:
log.warning('Empty body')

def index(self, documents, request=None):
def index(self, documents, request=None, **kwargs):
""" Reindex all `document`s. """
self._bulk('index', documents, request)

Expand Down Expand Up @@ -621,8 +621,8 @@ def get(self, **kw):
return self.get_resource(**kw)

@classmethod
def index_refs(cls, db_obj, request=None):
for model_cls, documents in db_obj.get_reference_documents():
def index_relations(cls, db_obj, request=None, **kwargs):
for model_cls, documents in db_obj.get_related_documents(**kwargs):
if getattr(model_cls, '_index_enabled', False) and documents:
cls(model_cls.__name__).index(
documents, request=request)
to_dicts(documents), request=request)
2 changes: 1 addition & 1 deletion nefertari/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, data={}):
def to_dict(self, **kwargs):
_dict = dictset()
_keys = kwargs.pop('_keys', [])
__depth = kwargs.pop('__depth', 10)
__depth = kwargs.pop('__depth', 1)

data = dictset(self._data).subset(_keys) if _keys else self._data

Expand Down
12 changes: 6 additions & 6 deletions tests/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,26 +797,26 @@ def test_get(self, mock_get):

@patch('nefertari.elasticsearch.ES.settings')
@patch('nefertari.elasticsearch.ES.index')
def test_index_refs(self, mock_ind, mock_settings):
def test_index_relations(self, mock_ind, mock_settings):
class Foo(object):
_index_enabled = True

docs = [Foo()]
db_obj = Mock()
db_obj.get_reference_documents.return_value = [(Foo, docs)]
db_obj.get_related_documents.return_value = [(Foo, docs)]
mock_settings.index_name = 'foo'
es.ES.index_refs(db_obj)
es.ES.index_relations(db_obj)
mock_ind.assert_called_once_with(docs, request=None)

@patch('nefertari.elasticsearch.ES.settings')
@patch('nefertari.elasticsearch.ES.index')
def test_index_refs_index_disabled(self, mock_ind, mock_settings):
def test_index_relations_index_disabled(self, mock_ind, mock_settings):
class Foo(object):
_index_enabled = False

docs = [Foo()]
db_obj = Mock()
db_obj.get_reference_documents.return_value = [(Foo, docs)]
db_obj.get_related_documents.return_value = [(Foo, docs)]
mock_settings.index_name = 'foo'
es.ES.index_refs(db_obj)
es.ES.index_relations(db_obj)
assert not mock_ind.called

0 comments on commit a80f881

Please sign in to comment.