Adds views test

This commit is contained in:
Mouse Reeve 2021-08-23 14:15:19 -07:00
parent fcd41aaf06
commit 47dbcc3af0

View file

@ -91,6 +91,50 @@ class ListViews(TestCase):
result.render() result.render()
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_bookmarked_lists_page(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.BookmarkedLists.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
booklist = models.List.objects.create(name="Public list", user=self.local_user)
models.List.objects.create(
name="Private list", privacy="direct", user=self.local_user
)
self.local_user.saved_lists.add(booklist)
request = self.factory.get("")
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
result.render()
self.assertEqual(result.status_code, 200)
self.assertEqual(result.context_data["lists"].object_list, [booklist])
def test_bookmarked_lists_page_empty(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.BookmarkedLists.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.List.objects.create(name="Public list", user=self.local_user)
models.List.objects.create(
name="Private list", privacy="direct", user=self.local_user
)
request = self.factory.get("")
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
result.render()
self.assertEqual(result.status_code, 200)
self.assertEqual(result.context_data["lists"].object_list, [])
def test_bookmarked_lists_page_logged_out(self):
"""logged out bookmarked lists"""
view = views.BookmarkedLists.as_view()
request = self.factory.get("")
request.user = self.anonymous_user
result = view(request)
self.assertEqual(result.status_code, 301)
def test_lists_create(self): def test_lists_create(self):
"""create list view""" """create list view"""
view = views.Lists.as_view() view = views.Lists.as_view()