mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-22 08:07:14 +00:00
Adds remove list item test and updates add/create tests
This commit is contained in:
parent
24685187e8
commit
a7375c4c13
3 changed files with 57 additions and 16 deletions
|
@ -97,10 +97,9 @@ class InboxActivities(TestCase):
|
|||
"type": "Add",
|
||||
"actor": "https://example.com/users/rat",
|
||||
"object": {
|
||||
"type": "Edition",
|
||||
"title": "Test Title",
|
||||
"work": work.remote_id,
|
||||
"id": "https://bookwyrm.social/book/37292",
|
||||
"type": "ListItem",
|
||||
"book": self.edition.remote_id,
|
||||
"id": "https://bookwyrm.social/listbook/6189",
|
||||
},
|
||||
"target": "https://bookwyrm.social/user/mouse/list/to-read",
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
|
@ -108,8 +107,10 @@ class InboxActivities(TestCase):
|
|||
views.inbox.activity_task(activity)
|
||||
|
||||
booklist = models.List.objects.get()
|
||||
listitem = models.ListItem.objects.get()
|
||||
self.assertEqual(booklist.name, "Test List")
|
||||
self.assertEqual(booklist.books.first(), book)
|
||||
self.assertEqual(listitem.remote_id, "https://bookwyrm.social/listbook/6189")
|
||||
|
||||
@responses.activate
|
||||
def test_handle_tag_book(self):
|
||||
|
|
|
@ -9,7 +9,7 @@ from bookwyrm import models, views
|
|||
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
class InboxActivities(TestCase):
|
||||
class InboxCreate(TestCase):
|
||||
""" readthrough tests """
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -7,11 +7,20 @@ from bookwyrm import models, views
|
|||
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
class InboxActivities(TestCase):
|
||||
class InboxRemove(TestCase):
|
||||
""" inbox tests """
|
||||
|
||||
def setUp(self):
|
||||
""" basic user and book data """
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
@ -22,26 +31,26 @@ class InboxActivities(TestCase):
|
|||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
self.work = models.Work.objects.create(title="work title")
|
||||
self.book = models.Edition.objects.create(
|
||||
title="Test",
|
||||
remote_id="https://bookwyrm.social/book/37292",
|
||||
parent_work=self.work,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_handle_unshelve_book(self):
|
||||
""" remove a book from a shelf """
|
||||
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,
|
||||
)
|
||||
shelf = models.Shelf.objects.create(user=self.remote_user, name="Test Shelf")
|
||||
shelf.remote_id = "https://bookwyrm.social/user/mouse/shelf/to-read"
|
||||
shelf.save()
|
||||
|
||||
shelfbook = models.ShelfBook.objects.create(
|
||||
user=self.remote_user, shelf=shelf, book=book
|
||||
user=self.remote_user, shelf=shelf, book=self.book
|
||||
)
|
||||
|
||||
self.assertEqual(shelf.books.first(), book)
|
||||
self.assertEqual(shelf.books.first(), self.book)
|
||||
self.assertEqual(shelf.books.count(), 1)
|
||||
|
||||
activity = {
|
||||
|
@ -51,11 +60,42 @@ class InboxActivities(TestCase):
|
|||
"object": {
|
||||
"type": "Edition",
|
||||
"title": "Test Title",
|
||||
"work": work.remote_id,
|
||||
"id": "https://bookwyrm.social/book/37292",
|
||||
"work": self.work.remote_id,
|
||||
"id": "https//bookwyrm.social/book/37292",
|
||||
},
|
||||
"target": "https://bookwyrm.social/user/mouse/shelf/to-read",
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
}
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertFalse(shelf.books.exists())
|
||||
|
||||
def test_handle_remove_book_from_list(self):
|
||||
""" listing a book """
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
booklist = models.List.objects.create(
|
||||
name="test list",
|
||||
user=self.local_user,
|
||||
)
|
||||
listitem = models.ListItem.objects.create(
|
||||
user=self.local_user,
|
||||
book=self.book,
|
||||
book_list=booklist,
|
||||
)
|
||||
self.assertEqual(booklist.books.count(), 1)
|
||||
|
||||
activity = {
|
||||
"id": listitem.remote_id,
|
||||
"type": "Remove",
|
||||
"actor": "https://example.com/users/rat",
|
||||
"object": {
|
||||
"type": "Edition",
|
||||
"title": "Test Title",
|
||||
"work": self.work.remote_id,
|
||||
"id": "https://bookwyrm.social/book/37292",
|
||||
},
|
||||
"target": booklist.remote_id,
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
}
|
||||
views.inbox.activity_task(activity)
|
||||
|
||||
self.assertEqual(booklist.books.count(), 0)
|
||||
|
|
Loading…
Reference in a new issue