示例#1
0
文件: core_test.py 项目: welhefna/h
    def test_search_annotations_excludes_replies_when_asked(self, pyramid_request, query):
        search = core.Search(pyramid_request, separate_replies=True)

        search.search_annotations({})

        assert mock.call(query.TopLevelAnnotationsFilter()) in \
            search.builder.append_filter.call_args_list
示例#2
0
文件: core_test.py 项目: welhefna/h
    def test_search_annotations_includes_replies_by_default(self, pyramid_request, query):
        search = core.Search(pyramid_request)
        search.search_annotations({})

        assert not query.TopLevelAnnotationsFilter.called, (
                "Replies should not be filtered out of the 'rows' list if "
                "separate_replies=True is not given")
示例#3
0
文件: core_test.py 项目: welhefna/h
    def test_search_replies_adds_a_replies_matcher(self, pyramid_request, query):
        search = core.Search(pyramid_request, separate_replies=True)

        search.search_replies(['id-1', 'id-2'])

        assert mock.call(query.RepliesMatcher(['id-1', 'id-2'])) in \
            search.reply_builder.append_matcher.call_args_list
示例#4
0
    def test_search_annotations_parses_aggregation_results(
            self, pyramid_request):
        search = core.Search(pyramid_request)
        search.es.conn.search.return_value = {
            'hits': {
                'total': 0,
                'hits': [],
            },
            'aggregations': {
                'foobar': {
                    'foo': 'bar'
                },
                'bazqux': {
                    'baz': 'qux'
                },
            }
        }
        foobaragg = mock.Mock(key='foobar')
        bazquxagg = mock.Mock(key='bazqux')
        search.append_aggregation(foobaragg)
        search.append_aggregation(bazquxagg)

        search._search_annotations({})

        foobaragg.parse_result.assert_called_with({'foo': 'bar'})
        bazquxagg.parse_result.assert_called_with({'baz': 'qux'})
示例#5
0
文件: core_test.py 项目: welhefna/h
    def test_append_aggregation_appends_to_annotation_builder(self, pyramid_request):
        aggregation = mock.Mock()
        search = core.Search(pyramid_request)
        search.builder = mock.Mock()

        search.append_aggregation(aggregation)

        search.builder.append_aggregation.assert_called_once_with(aggregation)
示例#6
0
文件: core_test.py 项目: welhefna/h
    def test_append_matcher_appends_to_reply_builder(self, pyramid_request):
        matcher = mock.Mock()
        search = core.Search(pyramid_request)
        search.reply_builder = mock.Mock()

        search.append_matcher(matcher)

        search.reply_builder.append_matcher.assert_called_once_with(matcher)
示例#7
0
文件: core_test.py 项目: welhefna/h
    def test_append_filter_appends_to_reply_builder(self, pyramid_request):
        filter_ = mock.Mock()
        search = core.Search(pyramid_request)
        search.reply_builder = mock.Mock()

        search.append_filter(filter_)

        search.reply_builder.append_filter.assert_called_once_with(filter_)
示例#8
0
文件: core_test.py 项目: welhefna/h
    def test_run_searches_annotations(self, pyramid_request, search_annotations):
        params = mock.Mock()

        search_annotations.return_value = (0, [], {})

        search = core.Search(pyramid_request)
        search.run(params)

        search_annotations.assert_called_once_with(search, params)
示例#9
0
    def test_run_searches_replies(self, pyramid_request, _search_replies,
                                  _search_annotations):
        annotation_ids = [mock.Mock(), mock.Mock()]
        _search_annotations.return_value = (2, annotation_ids, {})

        search = core.Search(pyramid_request)
        search.run({})

        _search_replies.assert_called_once_with(search, annotation_ids)
示例#10
0
文件: core_test.py 项目: welhefna/h
    def test_search_annotations_returns_parsed_aggregations(self, pyramid_request):
        search = core.Search(pyramid_request)
        search.es.conn.search.return_value = {
            'hits': {'total': 0, 'hits': []},
            'aggregations': {'foobar': {'foo': 'bar'}}
        }
        foobaragg = mock.Mock(key='foobar')
        search.append_aggregation(foobaragg)

        _, _, aggregations = search.search_annotations({})
        assert aggregations == {'foobar': foobaragg.parse_result.return_value}
示例#11
0
文件: core_test.py 项目: welhefna/h
    def test_search_replies_searches_replies_when_asked(self, pyramid_request):
        search = core.Search(pyramid_request, separate_replies=True)

        search.es.conn.search.return_value = {
            'hits': {
                'total': 2,
                'hits': [{'_id': 'reply-1'}, {'_id': 'reply-2'}],
            }
        }

        assert search.search_replies(['id-1']) == ['reply-1', 'reply-2']
示例#12
0
文件: core_test.py 项目: welhefna/h
    def test_search_replies_logs_warning_if_there_are_too_many_replies(self, pyramid_request, log):
        search = core.Search(pyramid_request, separate_replies=True)

        search.es.conn.search.return_value = {
            'hits': {
                'total': 1100,
                'hits': [{'_id': 'reply-1'}],
            }
        }

        search.search_replies(['id-1'])
        assert log.warn.call_count == 1
示例#13
0
文件: core_test.py 项目: jayzhen521/h
    def test_run_returns_search_results(self, pyramid_request,
                                        search_annotations, search_replies):
        total = 4
        annotation_ids = ['id-1', 'id-3', 'id-6', 'id-5']
        reply_ids = ['reply-8', 'reply-5']
        aggregations = {'foo': 'bar'}
        search_annotations.return_value = (total, annotation_ids, aggregations)
        search_replies.return_value = reply_ids

        search = core.Search(pyramid_request)
        result = search.run({})

        assert result == core.SearchResult(total, annotation_ids, reply_ids,
                                           aggregations)
示例#14
0
文件: core_test.py 项目: welhefna/h
 def test_search_replies_works_with_stats_client(self, pyramid_request):
     search = core.Search(pyramid_request,
                          stats=FakeStatsdClient(),
                          separate_replies=True)
     # This should not raise
     search.search_replies(['id-1'])
示例#15
0
文件: core_test.py 项目: welhefna/h
    def test_search_replies_skips_search_by_default(self, pyramid_request):
        search = core.Search(pyramid_request)
        search.search_replies(['id-1', 'id-2'])

        assert not search.es.conn.search.called
示例#16
0
文件: core_test.py 项目: welhefna/h
 def test_search_annotations_works_with_stats_client(self, pyramid_request):
     search = core.Search(pyramid_request, stats=FakeStatsdClient())
     # This should not raise
     search.search_annotations({})