moviewyrm/bookwyrm/tests/views/test_updates.py

57 lines
1.9 KiB
Python
Raw Normal View History

2021-03-13 19:11:06 +00:00
""" test for app action functionality """
import json
2021-03-23 20:02:45 +00:00
from unittest.mock import patch
2021-03-13 19:11:06 +00:00
from django.http import JsonResponse
from django.test import TestCase
from django.test.client import RequestFactory
from bookwyrm import models, views
class UpdateViews(TestCase):
""" lets the ui check for unread notification """
def setUp(self):
""" we need basic test data and mocks """
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",
"password",
local=True,
localname="mouse",
)
models.SiteSettings.objects.create()
2021-03-23 20:02:45 +00:00
def test_get_notification_count(self):
2021-03-13 19:11:06 +00:00
""" there are so many views, this just makes sure it LOADS """
request = self.factory.get("")
request.user = self.local_user
2021-03-23 20:02:45 +00:00
result = views.get_notification_count(request)
2021-03-13 19:11:06 +00:00
self.assertIsInstance(result, JsonResponse)
data = json.loads(result.getvalue())
2021-03-23 20:02:45 +00:00
self.assertEqual(data["count"], 0)
2021-03-13 19:11:06 +00:00
models.Notification.objects.create(
notification_type="BOOST", user=self.local_user
)
2021-03-23 20:02:45 +00:00
result = views.get_notification_count(request)
self.assertIsInstance(result, JsonResponse)
data = json.loads(result.getvalue())
self.assertEqual(data["count"], 1)
def test_get_unread_status_count(self):
""" there are so many views, this just makes sure it LOADS """
request = self.factory.get("")
request.user = self.local_user
2021-03-23 20:07:29 +00:00
with patch("bookwyrm.activitystreams.ActivityStream.get_unread_count") as mock:
2021-03-23 20:02:45 +00:00
mock.return_value = 3
2021-03-23 20:07:29 +00:00
result = views.get_unread_status_count(request, "home")
2021-03-23 20:02:45 +00:00
2021-03-13 19:11:06 +00:00
self.assertIsInstance(result, JsonResponse)
data = json.loads(result.getvalue())
2021-03-23 20:02:45 +00:00
self.assertEqual(data["count"], 3)