Gets updates view to 100% test coverage
This commit is contained in:
parent
2d63bfb791
commit
074c2cfb95
|
@ -2,7 +2,7 @@
|
||||||
import json
|
import json
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from django.http import JsonResponse
|
from django.http import Http404, JsonResponse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ class UpdateViews(TestCase):
|
||||||
"bookwyrm.activitystreams.ActivityStream.get_unread_count"
|
"bookwyrm.activitystreams.ActivityStream.get_unread_count"
|
||||||
) as mock_count:
|
) as mock_count:
|
||||||
with patch(
|
with patch(
|
||||||
|
# pylint:disable=line-too-long
|
||||||
"bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type"
|
"bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type"
|
||||||
) as mock_count_by_status:
|
) as mock_count_by_status:
|
||||||
mock_count.return_value = 3
|
mock_count.return_value = 3
|
||||||
|
@ -64,3 +65,11 @@ class UpdateViews(TestCase):
|
||||||
data = json.loads(result.getvalue())
|
data = json.loads(result.getvalue())
|
||||||
self.assertEqual(data["count"], 3)
|
self.assertEqual(data["count"], 3)
|
||||||
self.assertEqual(data["count_by_type"]["review"], 5)
|
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")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
""" endpoints for getting updates about activity """
|
""" endpoints for getting updates about activity """
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.http import JsonResponse
|
from django.http import Http404, JsonResponse
|
||||||
|
|
||||||
from bookwyrm import activitystreams
|
from bookwyrm import activitystreams
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ def get_unread_status_count(request, stream="home"):
|
||||||
"""any unread statuses for this feed?"""
|
"""any unread statuses for this feed?"""
|
||||||
stream = activitystreams.streams.get(stream)
|
stream = activitystreams.streams.get(stream)
|
||||||
if not stream:
|
if not stream:
|
||||||
return JsonResponse({})
|
raise Http404
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
{
|
{
|
||||||
"count": stream.get_unread_count(request.user),
|
"count": stream.get_unread_count(request.user),
|
||||||
|
|
Loading…
Reference in New Issue