From 1f2da1865564a20a82d1a97b8c17e4fb5571718e Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Mar 2021 11:11:06 -0800 Subject: [PATCH] Adds test for updates endpoint --- bookwyrm/tests/views/test_updates.py | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bookwyrm/tests/views/test_updates.py diff --git a/bookwyrm/tests/views/test_updates.py b/bookwyrm/tests/views/test_updates.py new file mode 100644 index 00000000..b41b2014 --- /dev/null +++ b/bookwyrm/tests/views/test_updates.py @@ -0,0 +1,42 @@ +""" test for app action functionality """ +import json +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() + + def test_get_updates(self): + """ there are so many views, this just makes sure it LOADS """ + view = views.Updates.as_view() + request = self.factory.get("") + request.user = self.local_user + + result = view(request) + self.assertIsInstance(result, JsonResponse) + data = json.loads(result.getvalue()) + self.assertEqual(data["notifications"], 0) + + models.Notification.objects.create( + notification_type="BOOST", user=self.local_user + ) + result = view(request) + self.assertIsInstance(result, JsonResponse) + data = json.loads(result.getvalue()) + self.assertEqual(data["notifications"], 1)