Beispiel #1
0
def test_search_calls_feature(logic, get_user):
    """It should call request.feature() once with the right args."""
    request = mock.Mock()

    views.search(request)

    request.feature.assert_called_once_with('search_normalized')
Beispiel #2
0
def test_search_calls_get_user(get_user):
    """It should call get_user() once passing the request."""
    request = mock.Mock()

    views.search(request)

    get_user.assert_called_once_with(request)
Beispiel #3
0
def test_search_calls_get_user(logic, get_user):
    """It should call get_user() once with the right args."""
    request = mock.Mock()

    views.search(request)

    get_user.assert_called_once_with(request)
Beispiel #4
0
def test_search_calls_get_user(get_user):
    """It should call get_user() once passing the request."""
    request = mock.Mock()

    views.search(request)

    get_user.assert_called_once_with(request)
Beispiel #5
0
def test_search_passes_params_to_search(search_lib):
    """It should pass request.params to search_lib.search()."""
    request = mock.Mock()

    views.search(request)

    assert search_lib.search.call_args[1]['request_params'] == request.params
Beispiel #6
0
def test_search_calls_feature():
    """It should call request.feature() once, passing 'search_normalized'."""
    request = mock.Mock()

    views.search(request)

    request.feature.assert_called_once_with('search_normalized')
Beispiel #7
0
def test_search_calls_feature():
    """It should call request.feature() once, passing 'search_normalized'."""
    request = mock.Mock()

    views.search(request)

    request.feature.assert_called_once_with('search_normalized')
Beispiel #8
0
def test_search_passes_params_to_search(search_lib):
    """It should pass request.params to search_lib.search()."""
    request = mock.Mock()

    views.search(request)

    assert search_lib.search.call_args[1]['request_params'] == request.params
Beispiel #9
0
def test_search_searches(search_lib):
    request = testing.DummyRequest()

    views.search(request)

    search_lib.search.assert_called_once_with(
        request, request.params, separate_replies=False)
Beispiel #10
0
def test_search_passes_search_normalized_uris(search_lib):
    """It should pass search_normalized from request.feature() to search()."""
    request = mock.Mock()

    views.search(request)

    assert search_lib.search.call_args[1]['search_normalized_uris'] == (
        request.feature.return_value)
Beispiel #11
0
    def test_it_loads_annotations_from_database(self, mock_request, search_lib, storage):
        search_lib.search.return_value = {'total': 2,
                                          'rows': [{'id': 'row-1'}, {'id': 'row-2'}]}

        views.search(mock_request)

        storage.fetch_ordered_annotations.assert_called_once_with(
            mock_request.db, ['row-1', 'row-2'], load_documents=True)
Beispiel #12
0
def test_search_searches(search_lib):
    request = testing.DummyRequest()

    views.search(request)

    search_lib.search.assert_called_once_with(request,
                                              request.params,
                                              separate_replies=False)
Beispiel #13
0
def test_search_calls_search_annotations(logic, get_user):
    """It should call search_annotations() once with the right args."""
    request = mock.Mock()

    views.search(request)

    logic.search_annotations.assert_called_once_with(
        request.params, get_user.return_value, request.feature.return_value)
Beispiel #14
0
def test_search_passes_search_normalized_uris(search_lib):
    """It should pass search_normalized from request.feature() to search()."""
    request = mock.Mock()

    views.search(request)

    assert search_lib.search.call_args[1]['search_normalized_uris'] == (
        request.feature.return_value)
Beispiel #15
0
    def test_it_loads_replies_from_database(self, mock_request, search_lib, storage):
        mock_request.params = {'_separate_replies': '1'}
        search_lib.search.return_value = {'total': 1,
                                          'rows': [{'id': 'row-1'}],
                                          'replies': [{'id': 'reply-1'},
                                                      {'id': 'reply-2'}]}

        views.search(mock_request)

        assert mock.call(mock_request.db, ['reply-1', 'reply-2'],
                         load_documents=True) in storage.fetch_ordered_annotations.call_args_list
Beispiel #16
0
    def test_it_renders_replies(self, mock_request, search_lib):
        ann = models.Annotation(userid='luke')
        mock_request.db.add(ann)
        mock_request.db.flush()
        reply1 = models.Annotation(userid='sarah', references=[ann.id])
        reply2 = models.Annotation(userid='sarah', references=[ann.id])
        mock_request.db.add_all([reply1, reply2])
        mock_request.db.flush()

        search_lib.search.return_value = {'total': 1,
                                          'rows': [{'id': ann.id}],
                                          'replies': [{'id': reply1.id}, {'id': reply2.id}],
                                          }

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

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

        assert views.search(mock_request) == expected
Beispiel #17
0
def test_search_returns_search_results(search_lib):
    request = testing.DummyRequest()
    search_lib.search.return_value = {'total': 0, 'rows': []}

    result = views.search(request)

    assert result == {'total': 0, 'rows': []}
Beispiel #18
0
def test_search_presents_replies(search_lib, AnnotationJSONPresenter):
    request = testing.DummyRequest(params={'_separate_replies': '1'})
    search_lib.search.return_value = {
        'total': 1,
        'rows': [{
            'foo': 'bar'
        }],
        'replies': [{
            'baz': 'bat'
        }, {
            'baz': 'bat'
        }]
    }
    presenter = AnnotationJSONPresenter.return_value
    presenter.asdict.return_value = {'giraffe': True}

    result = views.search(request)

    assert result == {
        'total': 1,
        'rows': [{
            'giraffe': True
        }],
        'replies': [{
            'giraffe': True
        }, {
            'giraffe': True
        }]
    }
Beispiel #19
0
    def test_it_returns_search_results(self, search_lib):
        request = testing.DummyRequest()
        search_lib.search.return_value = {'total': 0, 'rows': []}

        result = views.search(request)

        assert result == {'total': 0, 'rows': []}
Beispiel #20
0
def test_search_renders_replies(search_lib):
    search_lib.search.return_value = {
        'total': 3,
        'rows': ['parent_annotation'],
        'replies': ['a', 'b', 'c']
    }
    search_lib.render.side_effect = lambda x: x.upper()

    result = views.search(mock.Mock())

    assert result['replies'] == ['A', 'B', 'C']
Beispiel #21
0
def test_search_returns_total(search_lib):
    """It should return the total from search_lib.search()."""
    search_lib.search.return_value = {
        'total': 3,
        # In production these would be annotation dicts, not strings.
        'rows': ['annotation_1', 'annotation_2', 'annotation_3']
    }

    response_data = views.search(mock.Mock())

    assert response_data['total'] == 3
Beispiel #22
0
def test_search_returns_total(search_lib):
    """It should return the total from search_lib.search()."""
    search_lib.search.return_value = {
        'total': 3,
        # In production these would be annotation dicts, not strings.
        'rows': ['annotation_1', 'annotation_2', 'annotation_3']
    }

    response_data = views.search(mock.Mock())

    assert response_data['total'] == 3
Beispiel #23
0
def test_search_renders_results(search_lib):
    request = testing.DummyRequest()
    search_lib.search.return_value = {'total': 3, 'rows': ['a', 'b', 'c']}
    search_lib.render.side_effect = lambda x: x.upper()

    result = views.search(request)

    assert result == {
        'total': 3,
        'rows': ['A', 'B', 'C'],
    }
Beispiel #24
0
def test_search_renders_replies(search_lib):
    search_lib.search.return_value = {
        'total': 3,
        'rows': ['parent_annotation'],
        'replies': ['a', 'b', 'c']
    }
    search_lib.render.side_effect = lambda x: x.upper()

    result = views.search(mock.Mock())

    assert result['replies'] == ['A', 'B', 'C']
Beispiel #25
0
def test_search_presents_annotations(search_lib, AnnotationJSONPresenter):
    request = testing.DummyRequest()
    search_lib.search.return_value = {'total': 2, 'rows': [{'foo': 'bar'},
                                                           {'baz': 'bat'}]}
    presenter = AnnotationJSONPresenter.return_value
    presenter.asdict.return_value = {'giraffe': True}

    result = views.search(request)

    assert result == {'total': 2, 'rows': [{'giraffe': True},
                                           {'giraffe': True}]}
Beispiel #26
0
    def test_it_presents_annotations(self,
                                     pyramid_request,
                                     search_lib,
                                     AnnotationJSONPresenter):
        search_lib.search.return_value = {'total': 2, 'rows': [{'foo': 'bar'},
                                                               {'baz': 'bat'}]}
        presenter = AnnotationJSONPresenter.return_value
        presenter.asdict.return_value = {'giraffe': True}

        result = views.search(pyramid_request)

        assert result == {'total': 2, 'rows': [{'giraffe': True},
                                               {'giraffe': True}]}
Beispiel #27
0
def test_search_renders_results(search_lib):
    request = testing.DummyRequest()
    search_lib.search.return_value = {
        'total': 3,
        'rows': ['a', 'b', 'c'],
    }
    search_lib.render.side_effect = lambda x: x.upper()

    result = views.search(request)

    assert result == {
        'total': 3,
        'rows': ['A', 'B', 'C'],
    }
Beispiel #28
0
    def test_it_presents_replies(self, search_lib, AnnotationJSONPresenter):
        request = testing.DummyRequest(params={'_separate_replies': '1'})
        search_lib.search.return_value = {'total': 1,
                                          'rows': [{'foo': 'bar'}],
                                          'replies': [{'baz': 'bat'},
                                                      {'baz': 'bat'}]}
        presenter = AnnotationJSONPresenter.return_value
        presenter.asdict.return_value = {'giraffe': True}

        result = views.search(request)

        assert result == {'total': 1,
                          'rows': [{'giraffe': True}],
                          'replies': [{'giraffe': True},
                                      {'giraffe': True}]}
Beispiel #29
0
    def test_it_renders_search_results(self, mock_request, search_lib):
        ann1 = models.Annotation(userid='luke')
        ann2 = models.Annotation(userid='sarah')
        mock_request.db.add_all([ann1, ann2])
        mock_request.db.flush()

        search_lib.search.return_value = {'total': 2,
                                          'rows': [{'id': ann1.id}, {'id': ann2.id}]}

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

        assert views.search(mock_request) == expected
Beispiel #30
0
def test_search_returns_rendered_annotations(search_lib):
    """It should return the rendered annotations.

    It should pass the annotations from search_lib.search() through
    search_lib.render() and return the results.

    """
    search_lib.search.return_value = {
        'total': 3,
        # In production these would be annotation dicts, not strings.
        'rows': ['annotation_1', 'annotation_2', 'annotation_3']
    }
    # Our mock render function just appends '_rendered' onto our mock
    # annotation strings.
    search_lib.render.side_effect = lambda annotation: annotation + '_rendered'

    response_data = views.search(mock.Mock())

    assert response_data['rows'] == [
        'annotation_1_rendered', 'annotation_2_rendered',
        'annotation_3_rendered']
Beispiel #31
0
def test_search_returns_rendered_annotations(search_lib):
    """It should return the rendered annotations.

    It should pass the annotations from search_lib.search() through
    search_lib.render() and return the results.

    """
    search_lib.search.return_value = {
        'total': 3,
        # In production these would be annotation dicts, not strings.
        'rows': ['annotation_1', 'annotation_2', 'annotation_3']
    }
    # Our mock render function just appends '_rendered' onto our mock
    # annotation strings.
    search_lib.render.side_effect = lambda annotation: annotation + '_rendered'

    response_data = views.search(mock.Mock())

    assert response_data['rows'] == [
        'annotation_1_rendered', 'annotation_2_rendered',
        'annotation_3_rendered'
    ]
Beispiel #32
0
    def test_it_presents_annotations(self, search_lib,
                                     AnnotationJSONPresenter):
        request = testing.DummyRequest()
        search_lib.search.return_value = {
            'total': 2,
            'rows': [{
                'foo': 'bar'
            }, {
                'baz': 'bat'
            }]
        }
        presenter = AnnotationJSONPresenter.return_value
        presenter.asdict.return_value = {'giraffe': True}

        result = views.search(request)

        assert result == {
            'total': 2,
            'rows': [{
                'giraffe': True
            }, {
                'giraffe': True
            }]
        }
Beispiel #33
0
def test_search_passes_user_to_search(get_user, search_lib):
    """It should pass the user from get_user() to search_lib.search()."""
    views.search(mock.Mock())

    assert search_lib.search.call_args[1]['user'] == get_user.return_value
Beispiel #34
0
def test_search_calls_search(search_lib):
    """It should call search_lib.search() once."""
    views.search(mock.Mock())

    assert search_lib.search.call_count == 1
Beispiel #35
0
    def test_it_searches(self, mock_request, search_lib):
        views.search(mock_request)

        search_lib.search.assert_called_once_with(mock_request,
                                                  mock_request.params,
                                                  separate_replies=False)
Beispiel #36
0
def test_search_passes_user_to_search(get_user, search_lib):
    """It should pass the user from get_user() to search_lib.search()."""
    views.search(mock.Mock())

    assert search_lib.search.call_args[1]['user'] == get_user.return_value
Beispiel #37
0
def test_search_returns_search_results(search_lib):
    request = testing.DummyRequest()

    result = views.search(request)

    assert result == search_lib.search.return_value
Beispiel #38
0
    def test_it_returns_search_results(self, pyramid_request, search_lib):
        search_lib.search.return_value = {'total': 0, 'rows': []}

        result = views.search(pyramid_request)

        assert result == {'total': 0, 'rows': []}
Beispiel #39
0
def test_search_calls_search(search_lib):
    """It should call search_lib.search() once."""
    views.search(mock.Mock())

    assert search_lib.search.call_count == 1
Beispiel #40
0
def test_search_returns_search_annotations(logic, get_user):
    """It should return what search_annotations() returns."""
    assert views.search(mock.Mock()) == logic.search_annotations.return_value