From 6e6bcb2f4833e27d4c626d9d6d7c73c2616db5ff Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 23 Feb 2021 15:51:02 -0800 Subject: [PATCH] gotta simplify the add activity --- bookwyrm/activitypub/__init__.py | 2 +- bookwyrm/activitypub/verbs.py | 11 ++--- bookwyrm/models/list.py | 2 +- bookwyrm/tests/views/test_inbox.py | 75 ++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 10 deletions(-) diff --git a/bookwyrm/activitypub/__init__.py b/bookwyrm/activitypub/__init__.py index f06154ab..fdfbb1f0 100644 --- a/bookwyrm/activitypub/__init__.py +++ b/bookwyrm/activitypub/__init__.py @@ -15,7 +15,7 @@ from .response import ActivitypubResponse from .book import Edition, Work, Author from .verbs import Create, Delete, Undo, Update from .verbs import Follow, Accept, Reject, Block -from .verbs import Add, AddListItem, Remove +from .verbs import Add, Remove from .verbs import Announce, Like # this creates a list of all the Activity types that we can serialize, diff --git a/bookwyrm/activitypub/verbs.py b/bookwyrm/activitypub/verbs.py index 6f1a4d44..1236338b 100644 --- a/bookwyrm/activitypub/verbs.py +++ b/bookwyrm/activitypub/verbs.py @@ -121,6 +121,9 @@ class Add(Verb): target: str object: Edition type: str = 'Add' + notes: str = None + order: int = 0 + approved: bool = True def action(self): ''' add obj to collection ''' @@ -131,14 +134,6 @@ class Add(Verb): self.to_model(model=model) -@dataclass(init=False) -class AddListItem(Add): - '''Add activity that's aware of the book obj ''' - notes: str = None - order: int = 0 - approved: bool = True - - @dataclass(init=False) class Remove(Verb): '''Remove activity ''' diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index ef48ed95..1b14c2aa 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -68,7 +68,7 @@ class ListItem(CollectionItemMixin, BookWyrmModel): order = fields.IntegerField(blank=True, null=True) endorsement = models.ManyToManyField('User', related_name='endorsers') - activity_serializer = activitypub.AddListItem + activity_serializer = activitypub.Add object_field = 'book' collection_field = 'book_list' diff --git a/bookwyrm/tests/views/test_inbox.py b/bookwyrm/tests/views/test_inbox.py index c2658917..45966d59 100644 --- a/bookwyrm/tests/views/test_inbox.py +++ b/bookwyrm/tests/views/test_inbox.py @@ -612,6 +612,81 @@ class Inbox(TestCase): self.assertEqual(shelf.books.first(), book) +# def test_handle_tag_book(self): +# ''' tagging a book ''' +# work = models.Work.objects.create(title='work title') +# book = models.Edition.objects.create( +# title='Test', remote_id='https://bookwyrm.social/book/37292', +# parent_work=work) +# +# activity = { +# "id": "https://bookwyrm.social/shelfbook/6189#add", +# "type": "Add", +# "actor": "https://example.com/users/rat", +# "object": { +# "type": "Edition", +# "title": "Test Title", +# "work": work.remote_id, +# "id": "https://bookwyrm.social/book/37292", +# }, +# "target": "", +# "@context": "https://www.w3.org/ns/activitystreams" +# } +# views.inbox.activity_task(activity) +# self.assertEqual(shelf.books.first(), book) + + + @responses.activate + def test_handle_add_book_to_list(self): + ''' listing a book ''' + work = models.Work.objects.create(title='work title') + book = models.Edition.objects.create( + title='Test', remote_id='https://bookwyrm.social/book/37292', + parent_work=work) + + responses.add( + responses.GET, + 'https://bookwyrm.social/user/mouse/list/to-read', + json={ + "id": "https://example.com/list/22", + "type": "BookList", + "totalItems": 1, + "first": "https://example.com/list/22?page=1", + "last": "https://example.com/list/22?page=1", + "name": "Test List", + "owner": "https://example.com/user/mouse", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://example.com/user/mouse/followers" + ], + "summary": "summary text", + "curation": "curated", + "@context": "https://www.w3.org/ns/activitystreams" + } + ) + + activity = { + "id": "https://bookwyrm.social/listbook/6189#add", + "type": "Add", + "actor": "https://example.com/users/rat", + "object": { + "type": "Edition", + "title": "Test Title", + "work": work.remote_id, + "id": "https://bookwyrm.social/book/37292", + }, + "target": "https://bookwyrm.social/user/mouse/list/to-read", + "@context": "https://www.w3.org/ns/activitystreams" + } + views.inbox.activity_task(activity) + + booklist = models.List.objects.get() + self.assertEqual(booklist.name, 'Test List') + self.assertEqual(booklist.books.first(), book) + + def test_handle_update_user(self): ''' update an existing user ''' # we only do this with remote users