From 29ee027f6dbebcf44230410edab8377f1e60e020 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 31 Dec 2020 08:05:24 -0800 Subject: [PATCH] Tests tag page and orders tag collection json --- bookwyrm/models/book.py | 2 +- bookwyrm/models/tag.py | 4 +++- bookwyrm/tests/test_views.py | 40 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index fb20ee25..08189510 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -129,7 +129,7 @@ class Work(OrderedCollectionPageMixin, Book): def to_edition_list(self, **kwargs): ''' an ordered collection of editions ''' return self.to_ordered_collection( - self.editions.all(), + self.editions.order_by('-updated_date').all(), remote_id='%s/editions' % self.remote_id, **kwargs ) diff --git a/bookwyrm/models/tag.py b/bookwyrm/models/tag.py index 940b4192..cb12d382 100644 --- a/bookwyrm/models/tag.py +++ b/bookwyrm/models/tag.py @@ -17,7 +17,9 @@ class Tag(OrderedCollectionMixin, BookWyrmModel): @classmethod def book_queryset(cls, identifier): ''' county of books associated with this tag ''' - return cls.objects.filter(identifier=identifier) + return cls.objects.filter( + identifier=identifier + ).order_by('-updated_date') @property def collection_queryset(self): diff --git a/bookwyrm/tests/test_views.py b/bookwyrm/tests/test_views.py index a1ff52a0..fa8c99e4 100644 --- a/bookwyrm/tests/test_views.py +++ b/bookwyrm/tests/test_views.py @@ -196,3 +196,43 @@ class Views(TestCase): result = views.editions_page(request, self.work.id) self.assertIsInstance(result, JsonResponse) self.assertEqual(result.status_code, 200) + + + def test_author_page(self): + ''' there are so many views, this just makes sure it LOADS ''' + author = models.Author.objects.create(name='Jessica') + request = self.factory.get('') + with patch('bookwyrm.views.is_api_request') as is_api: + is_api.return_value = False + result = views.author_page(request, author.id) + self.assertIsInstance(result, TemplateResponse) + self.assertEqual(result.template_name, 'author.html') + self.assertEqual(result.status_code, 200) + + request = self.factory.get('') + with patch('bookwyrm.views.is_api_request') as is_api: + is_api.return_value = True + result = views.author_page(request, author.id) + self.assertIsInstance(result, JsonResponse) + self.assertEqual(result.status_code, 200) + + + def test_tag_page(self): + ''' there are so many views, this just makes sure it LOADS ''' + tag = models.Tag.objects.create(name='hi there') + models.UserTag.objects.create( + tag=tag, user=self.local_user, book=self.book) + request = self.factory.get('') + with patch('bookwyrm.views.is_api_request') as is_api: + is_api.return_value = False + result = views.tag_page(request, tag.identifier) + self.assertIsInstance(result, TemplateResponse) + self.assertEqual(result.template_name, 'tag.html') + self.assertEqual(result.status_code, 200) + + request = self.factory.get('') + with patch('bookwyrm.views.is_api_request') as is_api: + is_api.return_value = True + result = views.tag_page(request, tag.identifier) + self.assertIsInstance(result, JsonResponse) + self.assertEqual(result.status_code, 200)