Merge branch 'main' into domain-block
This commit is contained in:
@ -8,20 +8,20 @@ from bookwyrm import models, views
|
||||
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
class InboxActivities(TestCase):
|
||||
class InboxAdd(TestCase):
|
||||
""" inbox tests """
|
||||
|
||||
def setUp(self):
|
||||
""" basic user and book data """
|
||||
self.local_user = models.User.objects.create_user(
|
||||
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)
|
||||
local_user.remote_id = "https://example.com/user/mouse"
|
||||
local_user.save(broadcast=False)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
@ -32,17 +32,17 @@ class InboxActivities(TestCase):
|
||||
inbox="https://example.com/users/rat/inbox",
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
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=work,
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_handle_add_book_to_shelf(self):
|
||||
""" shelving 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,
|
||||
)
|
||||
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()
|
||||
@ -52,27 +52,20 @@ 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",
|
||||
"actor": self.remote_user.remote_id,
|
||||
"type": "ShelfItem",
|
||||
"book": self.book.remote_id,
|
||||
"id": "https://bookwyrm.social/shelfbook/6189",
|
||||
},
|
||||
"target": "https://bookwyrm.social/user/mouse/shelf/to-read",
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
}
|
||||
views.inbox.activity_task(activity)
|
||||
self.assertEqual(shelf.books.first(), book)
|
||||
self.assertEqual(shelf.books.first(), self.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",
|
||||
@ -97,10 +90,10 @@ 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",
|
||||
"actor": self.remote_user.remote_id,
|
||||
"type": "ListItem",
|
||||
"book": self.book.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,49 +101,7 @@ 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)
|
||||
|
||||
@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)
|
||||
self.assertEqual(booklist.books.first(), self.book)
|
||||
self.assertEqual(listitem.remote_id, "https://bookwyrm.social/listbook/6189")
|
||||
|
@ -136,6 +136,9 @@ class InboxActivities(TestCase):
|
||||
"id": "http://www.faraway.com/boost/12",
|
||||
"actor": self.remote_user.remote_id,
|
||||
"object": status.remote_id,
|
||||
"to": ["https://www.w3.org/ns/activitystreams#public"],
|
||||
"cc": ["https://example.com/user/mouse/followers"],
|
||||
"published": "Mon, 25 May 2020 19:31:20 GMT",
|
||||
}
|
||||
responses.add(
|
||||
responses.GET, status.remote_id, json=status.to_activity(), status=200
|
||||
@ -185,6 +188,7 @@ class InboxActivities(TestCase):
|
||||
"id": "http://fake.com/unknown/boost",
|
||||
"actor": self.remote_user.remote_id,
|
||||
"object": self.status.remote_id,
|
||||
"published": "Mon, 25 May 2020 19:31:20 GMT",
|
||||
},
|
||||
}
|
||||
views.inbox.activity_task(activity)
|
||||
|
@ -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 = {
|
||||
@ -49,13 +58,44 @@ class InboxActivities(TestCase):
|
||||
"type": "Remove",
|
||||
"actor": "https://example.com/users/rat",
|
||||
"object": {
|
||||
"type": "Edition",
|
||||
"title": "Test Title",
|
||||
"work": work.remote_id,
|
||||
"id": "https://bookwyrm.social/book/37292",
|
||||
"actor": self.remote_user.remote_id,
|
||||
"type": "ShelfItem",
|
||||
"book": self.book.remote_id,
|
||||
"id": shelfbook.remote_id,
|
||||
},
|
||||
"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": {
|
||||
"actor": self.remote_user.remote_id,
|
||||
"type": "ListItem",
|
||||
"book": self.book.remote_id,
|
||||
"id": listitem.remote_id,
|
||||
},
|
||||
"target": booklist.remote_id,
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
}
|
||||
views.inbox.activity_task(activity)
|
||||
|
||||
self.assertEqual(booklist.books.count(), 0)
|
||||
|
Reference in New Issue
Block a user