From 0c73a1f42e0849aa4849993c7c153246764a1143 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 2 Nov 2020 16:23:18 -0800 Subject: [PATCH] updates test data and serialization --- bookwyrm/models/base_model.py | 1 - ...onnector.py => test_bookwyrm_connector.py} | 2 +- bookwyrm/tests/data/fr_edition.json | 68 +++++++++---------- bookwyrm/tests/data/fr_work.json | 64 ++++++++--------- bookwyrm/tests/models/test_user_model.py | 2 +- bookwyrm/tests/test_signing.py | 2 +- 6 files changed, 64 insertions(+), 75 deletions(-) rename bookwyrm/tests/connectors/{test_fedireads_connector.py => test_bookwyrm_connector.py} (97%) diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index 2215a28a..b48ceea9 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -68,7 +68,6 @@ class ActivitypubMixin: if not hasattr(self, mapping.model_key) or not mapping.activity_key: continue value = getattr(self, mapping.model_key) - print(value) if hasattr(value, 'local_id'): value = value.local_id elif hasattr(value, 'remote_id'): diff --git a/bookwyrm/tests/connectors/test_fedireads_connector.py b/bookwyrm/tests/connectors/test_bookwyrm_connector.py similarity index 97% rename from bookwyrm/tests/connectors/test_fedireads_connector.py rename to bookwyrm/tests/connectors/test_bookwyrm_connector.py index 5f475fdb..c41b454c 100644 --- a/bookwyrm/tests/connectors/test_fedireads_connector.py +++ b/bookwyrm/tests/connectors/test_bookwyrm_connector.py @@ -50,5 +50,5 @@ class BookWyrmConnector(TestCase): def test_get_date(self): date = get_date(self.edition_data['published_date']) - expected = parser.parse("2017-05-10T00:00:00+00:00") + expected = parser.parse("2020-09-15T00:00:00+00:00") self.assertEqual(date, expected) diff --git a/bookwyrm/tests/data/fr_edition.json b/bookwyrm/tests/data/fr_edition.json index bdb7c150..0cc17d29 100644 --- a/bookwyrm/tests/data/fr_edition.json +++ b/bookwyrm/tests/data/fr_edition.json @@ -1,42 +1,40 @@ { - "@context": "https://www.w3.org/ns/activitystreams", - "type": "Document", - "book_type": "Edition", - "name": "Jonathan Strange and Mr Norrell", - "url": "https://example.com/book/122", + "id": "https://bookwyrm.social/book/5989", + "type": "Edition", "authors": [ - "https://example.com/author/25" + "https://bookwyrm.social/author/417" ], - "published_date": "2017-05-10T00:00:00+00:00", - "work": { - "@context": "https://www.w3.org/ns/activitystreams", - "type": "Document", - "book_type": "Work", - "name": "Jonathan Strange and Mr Norrell", - "url": "https://example.com/book/121", - "authors": [ - "https://example.com/author/25" - ], - "title": "Jonathan Strange and Mr Norrell", - "attachment": [ - { - "type": "Document", - "mediaType": "image/jpg", - "url": "https://example.com/images/covers/8775540-M.jpg", - "name": "Cover of \"Jonathan Strange and Mr Norrell\"" - } - ] - }, - "title": "Jonathan Strange and Mr Norrell", - "subtitle": "Bloomsbury Modern Classics", - "isbn_13": "9781408891469", - "physical_format": "paperback", + "first_published_date": null, + "published_date": "2020-09-15T00:00:00+00:00", + "title": "Piranesi", + "sort_title": null, + "subtitle": null, + "description": "Piranesi's house is no ordinary building; its rooms are infinite, its corridors endless, its walls are lined with thousands upon thousands of statues, each one different from all the others. Within the labyrinth of halls an ocean is imprisoned; waves thunder up staircases, rooms are flooded in an instant. But Piranesi is not afraid; he understands the tides as he understands the pattern of the labyrinth itself. He lives to explore the house.\r\n\r\nThere is one other person in the house--a man called The Other, who visits Piranesi twice a week and asks for help with research into A Great and Secret Knowledge. But as Piranesi explores, evidence emerges of another person, and a terrible truth begins to unravel, revealing a world beyond the one Piranesi has always known.\r\n\r\nFor readers of Neil Gaiman's The Ocean at the End of the Lane and fans of Madeline Miller's Circe, Piranesi introduces an astonishing new world, an infinite labyrinth full of startling images of surreal beauty, haunted by the tides and the clouds.", + "languages": [ + "English" + ], + "series": null, + "series_number": null, + "subjects": [], + "subject_places": [], + "openlibrary_key": "OL29486417M", + "librarything_key": null, + "goodreads_key": null, "attachment": [ { - "type": "Document", - "mediaType": "image/jpg", - "url": "https://example.com/images/covers/9155821-M.jpg", - "name": "Cover of \"Jonathan Strange and Mr Norrell\"" + "url": "https://bookwyrm.social/images/covers/50202953._SX318_.jpg", + "type": "Image" } - ] + ], + "isbn_10": "1526622424", + "isbn_13": "9781526622426", + "oclc_number": null, + "asin": null, + "pages": 272, + "physical_format": null, + "publishers": [ + "Bloomsbury Publishing Plc" + ], + "work": "https://bookwyrm.social/book/5988", + "@context": "https://www.w3.org/ns/activitystreams" } diff --git a/bookwyrm/tests/data/fr_work.json b/bookwyrm/tests/data/fr_work.json index e93f6706..4e759a19 100644 --- a/bookwyrm/tests/data/fr_work.json +++ b/bookwyrm/tests/data/fr_work.json @@ -1,44 +1,36 @@ { - "@context": "https://www.w3.org/ns/activitystreams", - "type": "Document", - "book_type": "Work", - "name": "Jonathan Strange and Mr Norrell", - "url": "https://example.com/book/121", + "id": "https://bookwyrm.social/book/5988", + "type": "Work", "authors": [ - "https://example.com/author/25" + "https://bookwyrm.social/author/417" ], - "editions": [ - { - "@context": "https://www.w3.org/ns/activitystreams", - "type": "Document", - "book_type": "Edition", - "name": "Jonathan Strange and Mr Norrell", - "url": "https://example.com/book/122", - "authors": [ - "https://example.com/author/25" - ], - "published_date": "2017-05-10T00:00:00+00:00", - "title": "Jonathan Strange and Mr Norrell", - "subtitle": "Bloomsbury Modern Classics", - "isbn_13": "9781408891469", - "physical_format": "paperback", - "attachment": [ - { - "type": "Document", - "mediaType": "image/jpg", - "url": "https://example.com/images/covers/9155821-M.jpg", - "name": "Cover of \"Jonathan Strange and Mr Norrell\"" - } - ] - } + "first_published_date": null, + "published_date": null, + "title": "Piranesi", + "sort_title": null, + "subtitle": null, + "description": "**From the *New York Times* bestselling author of *Jonathan Strange & Mr. Norrell*, an intoxicating, hypnotic new novel set in a dreamlike alternative reality.**\r\n\r\nPiranesi's house is no ordinary building; its rooms are infinite, its corridors endless, its walls are lined with thousands upon thousands of statues, each one different from all the others. Within the labyrinth of halls an ocean is imprisoned; waves thunder up staircases, rooms are flooded in an instant. But Piranesi is not afraid; he understands the tides as he understands the pattern of the labyrinth itself. He lives to explore the house.\r\n\r\nThere is one other person in the house--a man called The Other, who visits Piranesi twice a week and asks for help with research into A Great and Secret Knowledge. But as Piranesi explores, evidence emerges of another person, and a terrible truth begins to unravel, revealing a world beyond the one Piranesi has always known.\r\n\r\nFor readers of Neil Gaiman's *The Ocean at the End of the Lane* and fans of Madeline Miller's *Circe*, *Piranesi* introduces an astonishing new world, an infinite labyrinth full of startling images of surreal beauty, haunted by the tides and the clouds.\r\n\r\nThis description comes from the publisher.", + "languages": [], + "series": null, + "series_number": null, + "subjects": [ + "English literature" ], - "title": "Jonathan Strange and Mr Norrell", + "subject_places": [], + "openlibrary_key": "OL20893680W", + "librarything_key": null, + "goodreads_key": null, "attachment": [ { - "type": "Document", - "mediaType": "image/jpg", - "url": "https://example.com/images/covers/8775540-M.jpg", - "name": "Cover of \"Jonathan Strange and Mr Norrell\"" + "url": "https://bookwyrm.social/images/covers/10226290-M.jpg", + "type": "Image" } - ] + ], + "lccn": null, + "editions": [ + "https://bookwyrm.social/book/5989", + "OL28439584M", + "OL28300471M" + ], + "@context": "https://www.w3.org/ns/activitystreams" } diff --git a/bookwyrm/tests/models/test_user_model.py b/bookwyrm/tests/models/test_user_model.py index 0b43cc00..203c558d 100644 --- a/bookwyrm/tests/models/test_user_model.py +++ b/bookwyrm/tests/models/test_user_model.py @@ -50,7 +50,7 @@ class User(TestCase): self.assertEqual(activity['inbox'], self.user.inbox) self.assertEqual(activity['outbox'], self.user.outbox) self.assertEqual(activity['followers'], self.user.ap_followers) - self.assertEqual(activity['bookwyrmUser'], False) + self.assertEqual(activity['bookwyrmUser'], True) self.assertEqual(activity['discoverable'], True) self.assertEqual(activity['type'], 'Person') diff --git a/bookwyrm/tests/test_signing.py b/bookwyrm/tests/test_signing.py index 62870336..ed5600ac 100644 --- a/bookwyrm/tests/test_signing.py +++ b/bookwyrm/tests/test_signing.py @@ -61,7 +61,7 @@ class Signature(TestCase): digest=None, date=None): now = date or http_date() - data = json.dumps(get_follow_data(sender, self.rat)).encode('utf-8') + data = json.dumps(get_follow_data(sender, self.rat)) digest = digest or make_digest(data) signature = make_signature( signer or sender, self.rat.inbox, now, digest)