From c3d0e8e7f70e9c6f687163a0541802e4f79cd55b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 21 Dec 2020 11:47:47 -0800 Subject: [PATCH 1/5] Fixes openlibrary import to prefer editions with covers --- bookwyrm/connectors/abstract_connector.py | 2 +- bookwyrm/connectors/openlibrary.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 5afd1089..86ac7435 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -140,7 +140,7 @@ class AbstractConnector(AbstractMinimalConnector): for author in self.get_authors_from_data(edition_data): edition.authors.add(author) if not edition.authors.exists() and work.authors.exists(): - edition.authors.add(work.authors.all()) + edition.authors.set(work.authors.all()) return edition diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index 74f76668..3b60c307 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -174,7 +174,7 @@ def pick_default_edition(options): if len(options) == 1: return options[0] - options = [e for e in options if e.get('cover')] or options + options = [e for e in options if e.get('covers')] or options options = [e for e in options if \ '/languages/eng' in str(e.get('languages'))] or options formats = ['paperback', 'hardcover', 'mass market paperback'] From 862f1d2580eda909db10acf68218a84ee3c08220 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 21 Dec 2020 12:22:47 -0800 Subject: [PATCH 2/5] Fixes cover unit test --- bookwyrm/tests/connectors/test_openlibrary_connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/tests/connectors/test_openlibrary_connector.py b/bookwyrm/tests/connectors/test_openlibrary_connector.py index b3d97ba3..e2d54cd3 100644 --- a/bookwyrm/tests/connectors/test_openlibrary_connector.py +++ b/bookwyrm/tests/connectors/test_openlibrary_connector.py @@ -44,7 +44,7 @@ class Openlibrary(TestCase): def test_pick_default_edition(self): edition = pick_default_edition(self.edition_list_data['entries']) - self.assertEqual(edition['key'], '/books/OL9952943M') + self.assertEqual(edition['key'], '/books/OL9788823M') def test_format_search_result(self): From bc64ae0504daafa292f4d6d10bacd796d91dc7c7 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 21 Dec 2020 12:49:00 -0800 Subject: [PATCH 3/5] Fixes assigning authors in test --- bookwyrm/tests/connectors/test_self_connector.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bookwyrm/tests/connectors/test_self_connector.py b/bookwyrm/tests/connectors/test_self_connector.py index 0a925d79..d747748f 100644 --- a/bookwyrm/tests/connectors/test_self_connector.py +++ b/bookwyrm/tests/connectors/test_self_connector.py @@ -26,30 +26,30 @@ class SelfConnector(TestCase): self.work = models.Work.objects.create( title='Example Work', ) - self.work.add(author) + self.work.authors.add(author) self.edition = models.Edition.objects.create( title='Edition of Example Work', published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc), parent_work=self.work, ) - self.edition.add(author) + self.edition.authors.add(author) edition = models.Edition.objects.create( title='Another Edition', parent_work=self.work, series='Anonymous' ) - edition.add(author) + edition.authors.add(author) edition = models.Edition.objects.create( title='More Editions', subtitle='The Anonymous Edition', parent_work=self.work, ) - edition.add(author) + edition.authors.add(author) edition = models.Edition.objects.create( title='An Edition', parent_work=self.work ) - edition.add(author) + edition.authors.add(author) def test_format_search_result(self): From adfb1e696ae6b8e8b56de7275dc8ae903bb04a57 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 21 Dec 2020 12:49:33 -0800 Subject: [PATCH 4/5] typo in test --- bookwyrm/tests/connectors/test_self_connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/tests/connectors/test_self_connector.py b/bookwyrm/tests/connectors/test_self_connector.py index d747748f..d80725d7 100644 --- a/bookwyrm/tests/connectors/test_self_connector.py +++ b/bookwyrm/tests/connectors/test_self_connector.py @@ -22,7 +22,7 @@ class SelfConnector(TestCase): priority=1, ) self.connector = Connector(DOMAIN) - author = models.Author.objects.create(name='Anonymouse') + author = models.Author.objects.create(name='Anonymous') self.work = models.Work.objects.create( title='Example Work', ) From 0de479a89f41969ad1ecca33f227e5f08b835862 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 21 Dec 2020 13:03:48 -0800 Subject: [PATCH 5/5] Fixes authors set in tests --- bookwyrm/tests/connectors/test_self_connector.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bookwyrm/tests/connectors/test_self_connector.py b/bookwyrm/tests/connectors/test_self_connector.py index d80725d7..91857def 100644 --- a/bookwyrm/tests/connectors/test_self_connector.py +++ b/bookwyrm/tests/connectors/test_self_connector.py @@ -22,34 +22,32 @@ class SelfConnector(TestCase): priority=1, ) self.connector = Connector(DOMAIN) - author = models.Author.objects.create(name='Anonymous') self.work = models.Work.objects.create( title='Example Work', ) - self.work.authors.add(author) + author = models.Author.objects.create(name='Anonymous') self.edition = models.Edition.objects.create( title='Edition of Example Work', published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc), parent_work=self.work, ) self.edition.authors.add(author) - edition = models.Edition.objects.create( + models.Edition.objects.create( title='Another Edition', parent_work=self.work, series='Anonymous' ) - edition.authors.add(author) - edition = models.Edition.objects.create( + models.Edition.objects.create( title='More Editions', subtitle='The Anonymous Edition', parent_work=self.work, ) - edition.authors.add(author) + edition = models.Edition.objects.create( title='An Edition', parent_work=self.work ) - edition.authors.add(author) + edition.authors.add(models.Author.objects.create(name='Fish')) def test_format_search_result(self):