diff --git a/bookwyrm/tests/views/test_author.py b/bookwyrm/tests/views/test_author.py index ad5c069d..71daef2a 100644 --- a/bookwyrm/tests/views/test_author.py +++ b/bookwyrm/tests/views/test_author.py @@ -50,6 +50,43 @@ class AuthorViews(TestCase): models.SiteSettings.objects.create() def test_author_page(self): + """there are so many views, this just makes sure it LOADS""" + view = views.Author.as_view() + author = models.Author.objects.create(name="Jessica") + self.book.authors.add(author) + 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) + self.assertIsInstance(result, TemplateResponse) + validate_html(result.render()) + self.assertEqual(result.status_code, 200) + + def test_author_page_edition_author(self): + """there are so many views, this just makes sure it LOADS""" + view = views.Author.as_view() + another_book = models.Edition.objects.create( + title="Example Edition", + remote_id="https://example.com/book/1", + parent_work=self.work, + isbn_13="9780300112511", + ) + author = models.Author.objects.create(name="Jessica") + self.book.authors.add(author) + 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) + books = result.context_data["books"] + self.assertEqual(books.object_list.count(), 1) + + self.assertIsInstance(result, TemplateResponse) + validate_html(result.render()) + self.assertEqual(result.status_code, 200) + + def test_author_page_empty(self): """there are so many views, this just makes sure it LOADS""" view = views.Author.as_view() author = models.Author.objects.create(name="Jessica") diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index 3310fef0..b4eb7ef5 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -1,6 +1,7 @@ """ the good people stuff! the authors! """ from django.contrib.auth.decorators import login_required, permission_required from django.core.paginator import Paginator +from django.db.models import Q from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator @@ -25,9 +26,11 @@ class Author(View): if is_api_request(request): return ActivitypubResponse(author.to_activity()) - books = models.Work.objects.filter( - authors=author, editions__authors=author - ).distinct() + books = ( + models.Work.objects.filter(Q(authors=author) | Q(editions__authors=author)) + .order_by("-published_date") + .distinct() + ) paginated = Paginator(books, PAGE_LENGTH) page = paginated.get_page(request.GET.get("page"))