From 7bcf0a1d53f2f28302ef6302b208373de936ee93 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 31 Dec 2020 07:46:35 -0800 Subject: [PATCH 1/2] Fixes missing code for editions list json --- bookwyrm/models/book.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 1e1d8d20..fb20ee25 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -126,6 +126,14 @@ class Work(OrderedCollectionPageMixin, Book): ''' in case the default edition is not set ''' return self.default_edition or self.editions.first() + def to_edition_list(self, **kwargs): + ''' an ordered collection of editions ''' + return self.to_ordered_collection( + self.editions.all(), + remote_id='%s/editions' % self.remote_id, + **kwargs + ) + activity_serializer = activitypub.Work serialize_reverse_fields = [('editions', 'editions')] deserialize_reverse_fields = [('editions', 'editions')] From d04a1956f583cc2ed236a180d91ae10b0f19430d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 31 Dec 2020 07:52:08 -0800 Subject: [PATCH 2/2] Test that editions page loads --- bookwyrm/tests/test_views.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/bookwyrm/tests/test_views.py b/bookwyrm/tests/test_views.py index 1dff049a..a1ff52a0 100644 --- a/bookwyrm/tests/test_views.py +++ b/bookwyrm/tests/test_views.py @@ -17,7 +17,9 @@ class Views(TestCase): def setUp(self): ''' we need basic test data and mocks ''' self.factory = RequestFactory() - self.book = models.Edition.objects.create(title='Test Book') + self.work = models.Work.objects.create(title='Test Work') + self.book = models.Edition.objects.create( + title='Test Book', parent_work=self.work) models.Connector.objects.create( identifier='self', connector_file='self_connector', @@ -176,3 +178,21 @@ class Views(TestCase): self.assertEqual(response.template_name, 'search_results.html') self.assertEqual( response.context_data['book_results'][0].title, 'Gideon the Ninth') + + + def test_editions_page(self): + ''' there are so many views, this just makes sure it LOADS ''' + request = self.factory.get('') + with patch('bookwyrm.views.is_api_request') as is_api: + is_api.return_value = False + result = views.editions_page(request, self.work.id) + self.assertIsInstance(result, TemplateResponse) + self.assertEqual(result.template_name, 'editions.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.editions_page(request, self.work.id) + self.assertIsInstance(result, JsonResponse) + self.assertEqual(result.status_code, 200)