moviewyrm/bookwyrm/tests/views/test_updates.py

58 lines
2 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):
2021-04-26 16:15:42 +00:00
"""lets the ui check for unread notification"""
2021-03-13 19:11:06 +00:00
def setUp(self):
2021-04-26 16:15:42 +00:00
"""we need basic test data and mocks"""
2021-08-02 23:05:40 +00:00
self.factory = RequestFactory()
2021-08-03 17:25:53 +00:00
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",
"password",
local=True,
localname="mouse",
)
2021-08-02 23:05:40 +00:00
models.SiteSettings.objects.create()
2021-03-13 19:11:06 +00:00
2021-03-23 20:02:45 +00:00
def test_get_notification_count(self):
2021-04-26 16:15:42 +00:00
"""there are so many views, this just makes sure it LOADS"""
2021-03-13 19:11:06 +00:00
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):
2021-04-26 16:15:42 +00:00
"""there are so many views, this just makes sure it LOADS"""
2021-03-23 20:02:45 +00:00
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)