diff --git a/bookwyrm/tests/views/test_author.py b/bookwyrm/tests/views/test_author.py index 03c027fae..75c7433fe 100644 --- a/bookwyrm/tests/views/test_author.py +++ b/bookwyrm/tests/views/test_author.py @@ -1,6 +1,7 @@ """ test for app action functionality """ from unittest.mock import patch -from django.contrib.auth.models import Group, Permission + +from django.contrib.auth.models import AnonymousUser, Group, Permission from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied from django.template.response import TemplateResponse @@ -44,6 +45,8 @@ class AuthorViews(TestCase): parent_work=self.work, ) + self.anonymous_user = AnonymousUser + self.anonymous_user.is_authenticated = False models.SiteSettings.objects.create() def test_author_page(self): @@ -51,6 +54,7 @@ class AuthorViews(TestCase): view = views.Author.as_view() author = models.Author.objects.create(name="Jessica") request = self.factory.get("") + request.user = self.local_user with patch("bookwyrm.views.author.is_api_request") as is_api: is_api.return_value = False result = view(request, author.id) @@ -59,7 +63,26 @@ class AuthorViews(TestCase): self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200) + def test_author_page_logged_out(self): + """there are so many views, this just makes sure it LOADS""" + view = views.Author.as_view() + author = models.Author.objects.create(name="Jessica") request = self.factory.get("") + request.user = self.anonymous_user + with patch("bookwyrm.views.author.is_api_request") as is_api: + is_api.return_value = False + result = view(request, author.id) + self.assertIsInstance(result, TemplateResponse) + validate_html(result.render()) + self.assertEqual(result.status_code, 200) + self.assertEqual(result.status_code, 200) + + def test_author_page_api_response(self): + """there are so many views, this just makes sure it LOADS""" + view = views.Author.as_view() + author = models.Author.objects.create(name="Jessica") + request = self.factory.get("") + request.user = self.local_user with patch("bookwyrm.views.author.is_api_request") as is_api: is_api.return_value = True result = view(request, author.id) @@ -126,5 +149,5 @@ class AuthorViews(TestCase): resp = view(request, author.id) author.refresh_from_db() self.assertEqual(author.name, "Test Author") - resp.render() + validate_html(resp.render()) self.assertEqual(resp.status_code, 200) diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index 4cb7ac2b5..6c3ee36ff 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -33,7 +33,9 @@ class Author(View): .filter(Q(authors=author) | Q(parent_work__authors=author)) .annotate(default_id=Subquery(default_editions.values("id")[:1])) .filter(default_id=F("id")) - ).prefetch_related("authors") + .order_by("-first_published_date", "-published_date", "-created_date") + .prefetch_related("authors") + ) paginated = Paginator(books, PAGE_LENGTH) page = paginated.get_page(request.GET.get("page"))