Gets updates view to 100% test coverage

This commit is contained in:
Mouse Reeve 2021-12-09 18:16:34 -08:00
parent 2d63bfb791
commit 074c2cfb95
2 changed files with 12 additions and 3 deletions

View file

@ -2,7 +2,7 @@
import json
from unittest.mock import patch
from django.http import JsonResponse
from django.http import Http404, JsonResponse
from django.test import TestCase
from django.test.client import RequestFactory
@ -54,6 +54,7 @@ class UpdateViews(TestCase):
"bookwyrm.activitystreams.ActivityStream.get_unread_count"
) as mock_count:
with patch(
# pylint:disable=line-too-long
"bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type"
) as mock_count_by_status:
mock_count.return_value = 3
@ -64,3 +65,11 @@ class UpdateViews(TestCase):
data = json.loads(result.getvalue())
self.assertEqual(data["count"], 3)
self.assertEqual(data["count_by_type"]["review"], 5)
def test_get_unread_status_count_invalid_stream(self):
"""there are so many views, this just makes sure it LOADS"""
request = self.factory.get("")
request.user = self.local_user
with self.assertRaises(Http404):
views.get_unread_status_count(request, "fish")

View file

@ -1,6 +1,6 @@
""" endpoints for getting updates about activity """
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.http import Http404, JsonResponse
from bookwyrm import activitystreams
@ -21,7 +21,7 @@ def get_unread_status_count(request, stream="home"):
"""any unread statuses for this feed?"""
stream = activitystreams.streams.get(stream)
if not stream:
return JsonResponse({})
raise Http404
return JsonResponse(
{
"count": stream.get_unread_count(request.user),