mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
Adds test for updates endpoint
This commit is contained in:
parent
78df37a861
commit
1f2da18655
1 changed files with 42 additions and 0 deletions
42
bookwyrm/tests/views/test_updates.py
Normal file
42
bookwyrm/tests/views/test_updates.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue