mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-09-28 06:12:03 +00:00
More tests for more notification types
This commit is contained in:
parent
221b5138e8
commit
6a5323c6e7
1 changed files with 195 additions and 1 deletions
|
@ -44,7 +44,7 @@ class NotificationViews(TestCase):
|
||||||
validate_html(result.render())
|
validate_html(result.render())
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
def test_notifications_page_notifications(self):
|
def test_notifications_page_status_notifications(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
models.Notification.notify(
|
models.Notification.notify(
|
||||||
self.local_user,
|
self.local_user,
|
||||||
|
@ -80,6 +80,200 @@ class NotificationViews(TestCase):
|
||||||
validate_html(result.render())
|
validate_html(result.render())
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_notifications_page_follow_request(self):
|
||||||
|
"""import completed notification"""
|
||||||
|
models.Notification.notify(
|
||||||
|
self.local_user,
|
||||||
|
self.another_user,
|
||||||
|
notification_type="FOLLOW_REQUEST",
|
||||||
|
)
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
|
||||||
|
def test_notifications_page_follows(self):
|
||||||
|
"""import completed notification"""
|
||||||
|
models.Notification.notify(
|
||||||
|
self.local_user,
|
||||||
|
self.another_user,
|
||||||
|
notification_type="FOLLOW",
|
||||||
|
)
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
|
||||||
|
def test_notifications_page_report(self):
|
||||||
|
"""import completed notification"""
|
||||||
|
report = models.Report.objects.create(
|
||||||
|
user=self.another_user,
|
||||||
|
reporter=self.local_user,
|
||||||
|
)
|
||||||
|
notification = models.Notification.objects.create(
|
||||||
|
user=self.local_user,
|
||||||
|
notification_type="REPORT",
|
||||||
|
)
|
||||||
|
notification.related_reports.add(report)
|
||||||
|
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
|
||||||
|
def test_notifications_page_import(self):
|
||||||
|
"""import completed notification"""
|
||||||
|
import_job = models.ImportJob.objects.create(user=self.local_user, mappings={})
|
||||||
|
models.Notification.objects.create(
|
||||||
|
user=self.local_user, notification_type="IMPORT", related_import=import_job
|
||||||
|
)
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_notifications_page_list(self):
|
||||||
|
"""Adding books to lists"""
|
||||||
|
book = models.Edition.objects.create(title="shape")
|
||||||
|
with patch(
|
||||||
|
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||||
|
), patch("bookwyrm.lists_stream.remove_list_task.delay"):
|
||||||
|
book_list = models.List.objects.create(user=self.local_user, name="hi")
|
||||||
|
item = models.ListItem.objects.create(
|
||||||
|
book=book, user=self.another_user, book_list=book_list, order=1
|
||||||
|
)
|
||||||
|
models.Notification.notify_list_item(self.local_user, item)
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_notifications_page_group_invite(self):
|
||||||
|
"""group related notifications"""
|
||||||
|
group = models.Group.objects.create(user=self.another_user, name="group")
|
||||||
|
models.Notification.notify(
|
||||||
|
self.local_user,
|
||||||
|
self.another_user,
|
||||||
|
notification_type="INVITE",
|
||||||
|
related_group=group,
|
||||||
|
)
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_notifications_page_group_accept(self):
|
||||||
|
"""group related notifications"""
|
||||||
|
group = models.Group.objects.create(user=self.another_user, name="group")
|
||||||
|
models.Notification.notify(
|
||||||
|
self.local_user,
|
||||||
|
self.another_user,
|
||||||
|
notification_type="ACCEPT",
|
||||||
|
related_group=group,
|
||||||
|
)
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_notifications_page_group_join(self):
|
||||||
|
"""group related notifications"""
|
||||||
|
group = models.Group.objects.create(user=self.another_user, name="group")
|
||||||
|
models.Notification.notify(
|
||||||
|
self.local_user,
|
||||||
|
self.another_user,
|
||||||
|
notification_type="JOIN",
|
||||||
|
related_group=group,
|
||||||
|
)
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_notifications_page_group_leave(self):
|
||||||
|
"""group related notifications"""
|
||||||
|
group = models.Group.objects.create(user=self.another_user, name="group")
|
||||||
|
models.Notification.notify(
|
||||||
|
self.local_user,
|
||||||
|
self.another_user,
|
||||||
|
notification_type="LEAVE",
|
||||||
|
related_group=group,
|
||||||
|
)
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_notifications_page_group_remove(self):
|
||||||
|
"""group related notifications"""
|
||||||
|
group = models.Group.objects.create(user=self.another_user, name="group")
|
||||||
|
models.Notification.notify(
|
||||||
|
self.local_user,
|
||||||
|
self.another_user,
|
||||||
|
notification_type="REMOVE",
|
||||||
|
related_group=group,
|
||||||
|
)
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_notifications_page_group_changes(self):
|
||||||
|
"""group related notifications"""
|
||||||
|
group = models.Group.objects.create(user=self.another_user, name="group")
|
||||||
|
models.Notification.notify(
|
||||||
|
self.local_user,
|
||||||
|
self.another_user,
|
||||||
|
notification_type="GROUP_PRIVACY",
|
||||||
|
related_group=group,
|
||||||
|
)
|
||||||
|
models.Notification.notify(
|
||||||
|
self.local_user,
|
||||||
|
self.another_user,
|
||||||
|
notification_type="GROUP_NAME",
|
||||||
|
related_group=group,
|
||||||
|
)
|
||||||
|
models.Notification.notify(
|
||||||
|
self.local_user,
|
||||||
|
self.another_user,
|
||||||
|
notification_type="GROUP_DESCRIPTION",
|
||||||
|
related_group=group,
|
||||||
|
)
|
||||||
|
view = views.Notifications.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
|
result = view(request)
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
validate_html(result.render())
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
def test_clear_notifications(self):
|
def test_clear_notifications(self):
|
||||||
"""erase notifications"""
|
"""erase notifications"""
|
||||||
models.Notification.objects.create(
|
models.Notification.objects.create(
|
||||||
|
|
Loading…
Reference in a new issue