mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-17 13:46:35 +00:00
Adds tests and fixes unset ordering warnings
This commit is contained in:
parent
d706b26ac9
commit
72dc21e82a
2 changed files with 28 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
""" test for app action functionality """
|
""" test for app action functionality """
|
||||||
from unittest.mock import patch
|
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.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
@ -44,6 +45,8 @@ class AuthorViews(TestCase):
|
||||||
parent_work=self.work,
|
parent_work=self.work,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.anonymous_user = AnonymousUser
|
||||||
|
self.anonymous_user.is_authenticated = False
|
||||||
models.SiteSettings.objects.create()
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_author_page(self):
|
def test_author_page(self):
|
||||||
|
@ -51,6 +54,7 @@ class AuthorViews(TestCase):
|
||||||
view = views.Author.as_view()
|
view = views.Author.as_view()
|
||||||
author = models.Author.objects.create(name="Jessica")
|
author = models.Author.objects.create(name="Jessica")
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
with patch("bookwyrm.views.author.is_api_request") as is_api:
|
with patch("bookwyrm.views.author.is_api_request") as is_api:
|
||||||
is_api.return_value = False
|
is_api.return_value = False
|
||||||
result = view(request, author.id)
|
result = view(request, author.id)
|
||||||
|
@ -59,7 +63,26 @@ class AuthorViews(TestCase):
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
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 = 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:
|
with patch("bookwyrm.views.author.is_api_request") as is_api:
|
||||||
is_api.return_value = True
|
is_api.return_value = True
|
||||||
result = view(request, author.id)
|
result = view(request, author.id)
|
||||||
|
@ -126,5 +149,5 @@ class AuthorViews(TestCase):
|
||||||
resp = view(request, author.id)
|
resp = view(request, author.id)
|
||||||
author.refresh_from_db()
|
author.refresh_from_db()
|
||||||
self.assertEqual(author.name, "Test Author")
|
self.assertEqual(author.name, "Test Author")
|
||||||
resp.render()
|
validate_html(resp.render())
|
||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
|
|
@ -33,7 +33,9 @@ class Author(View):
|
||||||
.filter(Q(authors=author) | Q(parent_work__authors=author))
|
.filter(Q(authors=author) | Q(parent_work__authors=author))
|
||||||
.annotate(default_id=Subquery(default_editions.values("id")[:1]))
|
.annotate(default_id=Subquery(default_editions.values("id")[:1]))
|
||||||
.filter(default_id=F("id"))
|
.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)
|
paginated = Paginator(books, PAGE_LENGTH)
|
||||||
page = paginated.get_page(request.GET.get("page"))
|
page = paginated.get_page(request.GET.get("page"))
|
||||||
|
|
Loading…
Reference in a new issue