Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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': []}
Ejemplo n.º 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
        }]
    }
Ejemplo n.º 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': []}
Ejemplo n.º 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']
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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'],
    }
Ejemplo n.º 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']
Ejemplo n.º 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}]}
Ejemplo n.º 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}]}
Ejemplo n.º 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'],
    }
Ejemplo n.º 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}]}
Ejemplo n.º 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
Ejemplo n.º 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']
Ejemplo n.º 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'
    ]
Ejemplo n.º 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
            }]
        }
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 37
0
def test_search_returns_search_results(search_lib):
    request = testing.DummyRequest()

    result = views.search(request)

    assert result == search_lib.search.return_value
Ejemplo n.º 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': []}
Ejemplo n.º 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
Ejemplo n.º 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