Updates updates tests
This commit is contained in:
parent
9e9fd5c5a6
commit
5caac46c31
|
@ -1,5 +1,7 @@
|
||||||
""" test for app action functionality """
|
""" test for app action functionality """
|
||||||
import json
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
@ -22,21 +24,33 @@ class UpdateViews(TestCase):
|
||||||
)
|
)
|
||||||
models.SiteSettings.objects.create()
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_get_updates(self):
|
def test_get_notification_count(self):
|
||||||
""" there are so many views, this just makes sure it LOADS """
|
""" there are so many views, this just makes sure it LOADS """
|
||||||
view = views.Updates.as_view()
|
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
result = view(request)
|
result = views.get_notification_count(request)
|
||||||
self.assertIsInstance(result, JsonResponse)
|
self.assertIsInstance(result, JsonResponse)
|
||||||
data = json.loads(result.getvalue())
|
data = json.loads(result.getvalue())
|
||||||
self.assertEqual(data["notifications"], 0)
|
self.assertEqual(data["count"], 0)
|
||||||
|
|
||||||
models.Notification.objects.create(
|
models.Notification.objects.create(
|
||||||
notification_type="BOOST", user=self.local_user
|
notification_type="BOOST", user=self.local_user
|
||||||
)
|
)
|
||||||
result = view(request)
|
result = views.get_notification_count(request)
|
||||||
self.assertIsInstance(result, JsonResponse)
|
self.assertIsInstance(result, JsonResponse)
|
||||||
data = json.loads(result.getvalue())
|
data = json.loads(result.getvalue())
|
||||||
self.assertEqual(data["notifications"], 1)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue