def test_annotations_index_calls_feature(): """It should call request.feature() once, passing 'search_normalized'.""" request = mock.Mock() views.annotations_index(request) request.feature.assert_called_once_with('search_normalized')
def test_annotations_index_calls_get_user(get_user): """It should call get_user() once passing the request.""" request = mock.Mock() views.annotations_index(request) get_user.assert_called_once_with(request)
def test_annotations_index_passes_search_normalized_uris(search_lib): """It should pass search_normalized from request.feature() to index().""" request = mock.Mock() views.annotations_index(request) assert search_lib.index.call_args[1]['search_normalized_uris'] == ( request.feature.return_value)
def test_annotations_index_returns_total(search_lib): """It should return the total from search_lib.index().""" search_lib.index.return_value = { 'total': 3, # In production these would be annotation dicts, not strings. 'rows': ['annotation_1', 'annotation_2', 'annotation_3'] } response_data = views.annotations_index(mock.Mock()) assert response_data['total'] == 3
def test_annotations_index_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.annotations_index(request) assert result == { 'total': 3, 'rows': ['A', 'B', 'C'], }
def test_annotations_index_returns_rendered_annotations(search_lib): """It should return the rendered annotations. It should pass the annotations from search_lib.index() through search_lib.render() and return the results. """ search_lib.index.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.annotations_index(mock.Mock()) assert response_data['rows'] == [ 'annotation_1_rendered', 'annotation_2_rendered', 'annotation_3_rendered']
def test_annotations_index_returns_rendered_annotations(search_lib): """It should return the rendered annotations. It should pass the annotations from search_lib.index() through search_lib.render() and return the results. """ search_lib.index.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.annotations_index(mock.Mock()) assert response_data['rows'] == [ 'annotation_1_rendered', 'annotation_2_rendered', 'annotation_3_rendered' ]
def test_annotations_index_returns_search_results(search_lib): request = testing.DummyRequest() result = views.annotations_index(request) assert result == search_lib.search.return_value
def test_annotations_index_searches(search_lib): request = testing.DummyRequest() views.annotations_index(request) search_lib.search.assert_called_once_with(request, {"limit": 20})
def test_annotations_index_passes_user_to_index(get_user, search_lib): """It should pass the user from get_user() to search_lib.index().""" views.annotations_index(mock.Mock()) assert search_lib.index.call_args[1]['user'] == get_user.return_value
def test_annotations_index_calls_index(search_lib): """It should call search_lib.index() once.""" views.annotations_index(mock.Mock()) assert search_lib.index.call_count == 1