def test_badge_returns_number_from_search(models, search_run): request = mock.Mock(params={'uri': 'test_uri'}) models.Blocklist.is_blocked.return_value = False search_run.return_value = mock.Mock(total=29) result = views.badge(request) search_run.assert_called_once_with({'uri': 'test_uri', 'limit': 0}) assert result == {'total': 29}
def test_badge_returns_0_if_blocked(models, search_run): request = mock.Mock(params={'uri': 'test_uri'}) models.Blocklist.is_blocked.return_value = True search_run.return_value = {'total': 29} result = views.badge(request) assert not search_run.called assert result == {'total': 0}
def test_badge_returns_number_from_search_lib(models, search_lib): request = mock.Mock(params={'uri': 'test_uri'}) models.Blocklist.is_blocked.return_value = False search_lib.search.return_value = {'total': 29} result = views.badge(request) search_lib.search.assert_called_once_with( request, {'uri': 'test_uri', 'limit': 0}) assert result == {'total': search_lib.search.return_value['total']}
def test_badge_returns_number_from_search_lib(models, search_lib): request = mock.Mock(params={'uri': 'test_uri'}) models.Blocklist.is_blocked.return_value = False search_lib.search.return_value = {'total': 29} result = views.badge(request) search_lib.search.assert_called_once_with(request, { 'uri': 'test_uri', 'limit': 0 }) assert result == {'total': search_lib.search.return_value['total']}
def test_badge_raises_if_no_uri(): with pytest.raises(httpexceptions.HTTPBadRequest): views.badge(mock.Mock(params={}))