Test tag and list add

This commit is contained in:
Mouse Reeve
2021-02-23 17:18:25 -08:00
parent 6e6bcb2f48
commit 4d0e52bf51
6 changed files with 73 additions and 40 deletions

View File

@ -612,30 +612,6 @@ 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 '''
@ -687,6 +663,49 @@ class Inbox(TestCase):
self.assertEqual(booklist.books.first(), book)
@responses.activate
def test_handle_tag_book(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://www.example.com/tag/cool-tag',
json={
"id": "https://1b1a78582461.ngrok.io/tag/tag",
"type": "OrderedCollection",
"totalItems": 0,
"first": "https://1b1a78582461.ngrok.io/tag/tag?page=1",
"last": "https://1b1a78582461.ngrok.io/tag/tag?page=1",
"name": "cool tag",
"@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://www.example.com/tag/cool-tag",
"@context": "https://www.w3.org/ns/activitystreams"
}
views.inbox.activity_task(activity)
tag = models.Tag.objects.get()
self.assertFalse(models.List.objects.exists())
self.assertEqual(tag.name, 'cool tag')
self.assertEqual(tag.books.first(), book)
def test_handle_update_user(self):
''' update an existing user '''
# we only do this with remote users

View File

@ -59,6 +59,21 @@ class TagViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_tag_page_activitypub_page(self):
''' there are so many views, this just makes sure it LOADS '''
view = views.Tag.as_view()
with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'):
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('', {'page': 1})
with patch('bookwyrm.views.tag.is_api_request') as is_api:
is_api.return_value = True
result = view(request, tag.identifier)
self.assertIsInstance(result, ActivitypubResponse)
self.assertEqual(result.status_code, 200)
def test_tag(self):
''' add a tag to a book '''
view = views.AddTag.as_view()