Adds more shelf page tests

This commit is contained in:
Mouse Reeve 2022-01-20 14:23:02 -08:00
parent d9175ce0b0
commit 28d675c5a0

View file

@ -51,6 +51,11 @@ class ShelfViews(TestCase):
def test_shelf_page_all_books(self, *_):
"""there are so many views, this just makes sure it LOADS"""
models.ShelfBook.objects.create(
book=self.book,
shelf=self.shelf,
user=self.local_user,
)
view = views.Shelf.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -61,6 +66,41 @@ class ShelfViews(TestCase):
validate_html(result.render())
self.assertEqual(result.status_code, 200)
def test_shelf_page_all_books_empty(self, *_):
"""No books shelved"""
view = views.Shelf.as_view()
request = self.factory.get("")
request.user = self.local_user
with patch("bookwyrm.views.shelf.shelf.is_api_request") as is_api:
is_api.return_value = False
result = view(request, self.local_user.username)
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)
def test_shelf_page_all_books_avoid_duplicates(self, *_):
"""Make sure books aren't showing up twice on the all shelves view"""
models.ShelfBook.objects.create(
book=self.book,
shelf=self.shelf,
user=self.local_user,
)
models.ShelfBook.objects.create(
book=self.book,
shelf=self.local_user.shelf_set.first(),
user=self.local_user,
)
view = views.Shelf.as_view()
request = self.factory.get("")
request.user = self.local_user
with patch("bookwyrm.views.shelf.shelf.is_api_request") as is_api:
is_api.return_value = False
result = view(request, self.local_user.username)
self.assertEqual(result.context_data["books"].object_list.count(), 1)
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)
def test_shelf_page_all_books_json(self, *_):
"""there is no json view here"""
view = views.Shelf.as_view()