Esempio n. 1
0
    def test_it_searches(self, pyramid_request, search_lib):
        views.search(pyramid_request)

        search = search_lib.Search.return_value
        search_lib.Search.assert_called_with(pyramid_request,
                                             separate_replies=False)
        search.run.assert_called_once_with(pyramid_request.params)
Esempio n. 2
0
    def test_it_loads_annotations_from_database(self, pyramid_request, search_run, storage):
        search_run.return_value = SearchResult(2, ['row-1', 'row-2'], [], {})

        views.search(pyramid_request)

        storage.fetch_ordered_annotations.assert_called_once_with(
            pyramid_request.db, ['row-1', 'row-2'], query_processor=mock.ANY)
Esempio n. 3
0
    def test_it_loads_annotations_from_database(self, pyramid_request, search_run, storage):
        search_run.return_value = SearchResult(2, ['row-1', 'row-2'], [], {})

        views.search(pyramid_request)

        storage.fetch_ordered_annotations.assert_called_once_with(
            pyramid_request.db, ['row-1', 'row-2'], query_processor=mock.ANY)
Esempio n. 4
0
    def test_it_loads_replies_from_database(self, pyramid_request, search_run, storage):
        pyramid_request.params = {'_separate_replies': '1'}
        search_run.return_value = SearchResult(1, ['row-1'], ['reply-1', 'reply-2'], {})

        views.search(pyramid_request)

        assert mock.call(pyramid_request.db, ['reply-1', 'reply-2'],
                         query_processor=mock.ANY) in storage.fetch_ordered_annotations.call_args_list
Esempio n. 5
0
    def test_it_loads_replies_from_database(self, pyramid_request, search_run, storage):
        pyramid_request.params = {'_separate_replies': '1'}
        search_run.return_value = SearchResult(1, ['row-1'], ['reply-1', 'reply-2'], {})

        views.search(pyramid_request)

        assert mock.call(pyramid_request.db, ['reply-1', 'reply-2'],
                         query_processor=mock.ANY) in storage.fetch_ordered_annotations.call_args_list
Esempio n. 6
0
    def test_it_searches(self, pyramid_request, search_lib):
        pyramid_request.stats = mock.Mock()

        views.search(pyramid_request)

        search = search_lib.Search.return_value
        search_lib.Search.assert_called_with(pyramid_request,
                                             separate_replies=False,
                                             stats=pyramid_request.stats)
        search.run.assert_called_once_with(pyramid_request.params)
Esempio n. 7
0
    def test_it_renders_replies(self, links_service, pyramid_request,
                                search_run):
        ann = models.Annotation(userid='luke')
        pyramid_request.db.add(ann)
        pyramid_request.db.flush()
        reply1 = models.Annotation(userid='sarah', references=[ann.id])
        reply2 = models.Annotation(userid='sarah', references=[ann.id])
        pyramid_request.db.add_all([reply1, reply2])
        pyramid_request.db.flush()

        search_run.return_value = SearchResult(1, [ann.id],
                                               [reply1.id, reply2.id], {})

        pyramid_request.params = {'_separate_replies': '1'}

        expected = {
            'total':
            1,
            'rows':
            [presenters.AnnotationJSONPresenter(ann, links_service).asdict()],
            'replies': [
                presenters.AnnotationJSONPresenter(reply1,
                                                   links_service).asdict(),
                presenters.AnnotationJSONPresenter(reply2,
                                                   links_service).asdict(),
            ]
        }

        assert views.search(pyramid_request) == expected
Esempio n. 8
0
    def test_it_renders_replies(self, links_service, pyramid_request,
                                search_run, factories, group_service):
        ann = AnnotationResource(factories.Annotation(userid='luke'),
                                 group_service, links_service)
        reply1 = AnnotationResource(
            factories.Annotation(userid='sarah',
                                 references=[ann.annotation.id]),
            group_service, links_service)
        reply2 = AnnotationResource(
            factories.Annotation(userid='sarah',
                                 references=[ann.annotation.id]),
            group_service, links_service)

        search_run.return_value = SearchResult(
            1, [ann.annotation.id],
            [reply1.annotation.id, reply2.annotation.id], {})

        pyramid_request.params = {'_separate_replies': '1'}

        expected = {
            'total':
            1,
            'rows': [presenters.AnnotationJSONPresenter(ann).asdict()],
            'replies': [
                presenters.AnnotationJSONPresenter(reply1).asdict(),
                presenters.AnnotationJSONPresenter(reply2).asdict(),
            ]
        }

        assert views.search(pyramid_request) == expected
Esempio n. 9
0
    def test_it_renders_search_results(self, links_service, pyramid_request, search_run, factories):
        ann1 = factories.Annotation(userid='luke')
        ann2 = factories.Annotation(userid='sarah')

        search_run.return_value = SearchResult(2, [ann1.id, ann2.id], [], {})

        expected = {
            'total': 2,
            'rows': [
                presenters.AnnotationJSONPresenter(ann1, links_service).asdict(),
                presenters.AnnotationJSONPresenter(ann2, links_service).asdict(),
            ]
        }

        assert views.search(pyramid_request) == expected
Esempio n. 10
0
    def test_it_renders_search_results(self, links_service, pyramid_request, search_run, factories):
        ann1 = factories.Annotation(userid='luke')
        ann2 = factories.Annotation(userid='sarah')

        search_run.return_value = SearchResult(2, [ann1.id, ann2.id], [], {})

        expected = {
            'total': 2,
            'rows': [
                presenters.AnnotationJSONPresenter(ann1, links_service).asdict(),
                presenters.AnnotationJSONPresenter(ann2, links_service).asdict(),
            ]
        }

        assert views.search(pyramid_request) == expected
Esempio n. 11
0
    def test_it_renders_replies(self, links_service, pyramid_request, search_run, factories):
        ann = factories.Annotation(userid='luke')
        reply1 = factories.Annotation(userid='sarah', references=[ann.id])
        reply2 = factories.Annotation(userid='sarah', references=[ann.id])

        search_run.return_value = SearchResult(1, [ann.id], [reply1.id, reply2.id], {})

        pyramid_request.params = {'_separate_replies': '1'}

        expected = {
            'total': 1,
            'rows': [presenters.AnnotationJSONPresenter(ann, links_service).asdict()],
            'replies': [
                presenters.AnnotationJSONPresenter(reply1, links_service).asdict(),
                presenters.AnnotationJSONPresenter(reply2, links_service).asdict(),
            ]
        }

        assert views.search(pyramid_request) == expected