Esempio n. 1
0
    def test_it_presents_the_annotation(self, es, presenters, pyramid_request):
        annotation = mock.Mock()

        index.index(es, annotation, pyramid_request)

        presenters.AnnotationSearchIndexPresenter.assert_called_once_with(
            annotation)
Esempio n. 2
0
    def test_it_notifies_before_save_event(self, AnnotationTransformEvent, es,
                                           notify, presenters,
                                           pyramid_request):
        index.index(es, mock.Mock(), pyramid_request)

        event = AnnotationTransformEvent.return_value
        notify.assert_called_once_with(event)
Esempio n. 3
0
    def test_it_allows_to_override_target_index(self, es, presenters,
                                                pyramid_request):
        index.index(es,
                    mock.Mock(),
                    pyramid_request,
                    target_index='custom-index')

        _, kwargs = es.conn.index.call_args
        assert kwargs['index'] == 'custom-index'
Esempio n. 4
0
    def test_it_indexes_the_annotation(self, es, presenters, pyramid_request):
        index.index(es, mock.Mock(), pyramid_request)

        es.conn.index.assert_called_once_with(
            index='hypothesis',
            doc_type='annotation',
            body=presenters.AnnotationSearchIndexPresenter.return_value.asdict.return_value,
            id='test_annotation_id',
        )
Esempio n. 5
0
    def test_it_indexes_the_annotation(self, es, presenters, pyramid_request):
        index.index(es, mock.Mock(), pyramid_request)

        es.conn.index.assert_called_once_with(
            index='hypothesis',
            doc_type='annotation',
            body=presenters.AnnotationSearchIndexPresenter.return_value.asdict.return_value,
            id='test_annotation_id',
        )
Esempio n. 6
0
    def test_it_creates_an_annotation_before_save_event(
            self, AnnotationTransformEvent, es, presenters, pyramid_request):
        presented = presenters.AnnotationSearchIndexPresenter.return_value.asdict(
        )

        index.index(es, mock.Mock(), pyramid_request)

        AnnotationTransformEvent.assert_called_once_with(
            pyramid_request, presented)
Esempio n. 7
0
    def test_it_notifies_before_save_event(self,
                                           AnnotationTransformEvent,
                                           es,
                                           notify,
                                           presenters,
                                           pyramid_request):
        index.index(es, mock.Mock(), pyramid_request)

        event = AnnotationTransformEvent.return_value
        notify.assert_called_once_with(event)
Esempio n. 8
0
def add_annotation(id_):
    annotation = storage.fetch_annotation(celery.request.db, id_)
    if annotation:
        index(celery.request.es, annotation, celery.request)

        # If a reindex is running at the moment, add annotation to the new index
        # as well.
        future_index = _current_reindex_new_name(celery.request)
        if future_index is not None:
            index(celery.request.es, annotation, celery.request,
                  target_index=future_index)
Esempio n. 9
0
    def test_it_creates_an_annotation_before_save_event(self,
                                                        AnnotationTransformEvent,
                                                        es,
                                                        presenters,
                                                        pyramid_request):
        annotation = mock.Mock()
        presented = presenters.AnnotationSearchIndexPresenter.return_value.asdict()

        index.index(es, annotation, pyramid_request)

        AnnotationTransformEvent.assert_called_once_with(pyramid_request, annotation, presented)
Esempio n. 10
0
File: indexer.py Progetto: gnott/h
def add_annotation(id_):
    annotation = storage.fetch_annotation(celery.request.db, id_)
    if annotation:
        index(celery.request.es, annotation, celery.request)

        # If a reindex is running at the moment, add annotation to the new index
        # as well.
        future_index = _current_reindex_new_name(celery.request)
        if future_index is not None:
            index(celery.request.es, annotation, celery.request,
                  target_index=future_index)

        if annotation.is_reply:
            add_annotation.delay(annotation.thread_root_id)
Esempio n. 11
0
File: indexer.py Progetto: yumatch/h
def add_annotation(id_):
    annotation = storage.fetch_annotation(celery.request.db, id_)
    if annotation:
        index(celery.request.es, annotation, celery.request)

        if celery.request.feature('index_es6'):
            index(celery.request.es6, annotation, celery.request)

        # If a reindex is running at the moment, add annotation to the new index
        # as well.
        future_index = _current_reindex_new_name(celery.request,
                                                 'reindex.new_index')
        if future_index is not None:
            index(celery.request.es,
                  annotation,
                  celery.request,
                  target_index=future_index)

        future_es6_index = _current_reindex_new_name(celery.request,
                                                     'reindex.new_es6_index')
        if future_es6_index is not None:
            index(celery.request.es6,
                  annotation,
                  celery.request,
                  target_index=future_es6_index)

        if annotation.is_reply:
            add_annotation.delay(annotation.thread_root_id)
Esempio n. 12
0
 def _index(annotation):
     """Index the given annotation into Elasticsearch."""
     index.index(es_client, annotation, pyramid_request)
Esempio n. 13
0
    def test_it_allows_to_override_target_index(self, es, presenters, pyramid_request):
        index.index(es, mock.Mock(), pyramid_request, target_index='custom-index')

        _, kwargs = es.conn.index.call_args
        assert kwargs['index'] == 'custom-index'
Esempio n. 14
0
    def test_it_presents_the_annotation(self, es, presenters, pyramid_request):
        annotation = mock.Mock()

        index.index(es, annotation, pyramid_request)

        presenters.AnnotationSearchIndexPresenter.assert_called_once_with(annotation)