moviewyrm/bookwyrm/tests/views/test_updates.py
2021-05-26 23:57:29 +02:00

58 lines
2.1 KiB
Python

""" test for app action functionality """
import json
from unittest.mock import patch
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"""
with patch("bookwyrm.preview_images.generate_user_preview_image_task.delay"):
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",
"password",
local=True,
localname="mouse",
)
with patch("bookwyrm.preview_images.generate_site_preview_image_task.delay"):
models.SiteSettings.objects.create()
def test_get_notification_count(self):
"""there are so many views, this just makes sure it LOADS"""
request = self.factory.get("")
request.user = self.local_user
result = views.get_notification_count(request)
self.assertIsInstance(result, JsonResponse)
data = json.loads(result.getvalue())
self.assertEqual(data["count"], 0)
models.Notification.objects.create(
notification_type="BOOST", user=self.local_user
)
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
with patch("bookwyrm.activitystreams.ActivityStream.get_unread_count") as mock:
mock.return_value = 3
result = views.get_unread_status_count(request, "home")
self.assertIsInstance(result, JsonResponse)
data = json.loads(result.getvalue())
self.assertEqual(data["count"], 3)