Tests for books stream
This commit is contained in:
parent
142d0da3b7
commit
f3a757951c
|
@ -6,6 +6,7 @@ from bookwyrm import activitystreams, models
|
||||||
|
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||||
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
class Activitystreams(TestCase):
|
class Activitystreams(TestCase):
|
||||||
"""using redis to build activity streams"""
|
"""using redis to build activity streams"""
|
||||||
|
|
||||||
|
@ -32,7 +33,8 @@ class Activitystreams(TestCase):
|
||||||
inbox="https://example.com/users/rat/inbox",
|
inbox="https://example.com/users/rat/inbox",
|
||||||
outbox="https://example.com/users/rat/outbox",
|
outbox="https://example.com/users/rat/outbox",
|
||||||
)
|
)
|
||||||
self.book = models.Edition.objects.create(title="test book")
|
work = models.Work.objects.create(title="test work")
|
||||||
|
self.book = models.Edition.objects.create(title="test book", parent_work=work)
|
||||||
|
|
||||||
class TestStream(activitystreams.ActivityStream):
|
class TestStream(activitystreams.ActivityStream):
|
||||||
"""test stream, don't have to do anything here"""
|
"""test stream, don't have to do anything here"""
|
||||||
|
@ -190,3 +192,96 @@ class Activitystreams(TestCase):
|
||||||
)
|
)
|
||||||
users = activitystreams.LocalStream().get_audience(status)
|
users = activitystreams.LocalStream().get_audience(status)
|
||||||
self.assertEqual(users, [])
|
self.assertEqual(users, [])
|
||||||
|
|
||||||
|
def test_localstream_get_audience_books_no_book(self, *_):
|
||||||
|
"""get a list of users that should see a status"""
|
||||||
|
status = models.Status.objects.create(
|
||||||
|
user=self.local_user, content="hi", privacy="public"
|
||||||
|
)
|
||||||
|
audience = activitystreams.BooksStream().get_audience(status)
|
||||||
|
# no books, no audience
|
||||||
|
self.assertEqual(audience, [])
|
||||||
|
|
||||||
|
def test_localstream_get_audience_books_mention_books(self, *_):
|
||||||
|
"""get a list of users that should see a status"""
|
||||||
|
status = models.Status.objects.create(
|
||||||
|
user=self.local_user, content="hi", privacy="public"
|
||||||
|
)
|
||||||
|
status.mention_books.add(self.book)
|
||||||
|
status.save(broadcast=False)
|
||||||
|
models.ShelfBook.objects.create(
|
||||||
|
user=self.local_user,
|
||||||
|
shelf=self.local_user.shelf_set.first(),
|
||||||
|
book=self.book,
|
||||||
|
)
|
||||||
|
# yes book, yes audience
|
||||||
|
audience = activitystreams.BooksStream().get_audience(status)
|
||||||
|
self.assertTrue(self.local_user in audience)
|
||||||
|
|
||||||
|
def test_localstream_get_audience_books_book_field(self, *_):
|
||||||
|
"""get a list of users that should see a status"""
|
||||||
|
status = models.Comment.objects.create(
|
||||||
|
user=self.local_user, content="hi", privacy="public", book=self.book
|
||||||
|
)
|
||||||
|
models.ShelfBook.objects.create(
|
||||||
|
user=self.local_user,
|
||||||
|
shelf=self.local_user.shelf_set.first(),
|
||||||
|
book=self.book,
|
||||||
|
)
|
||||||
|
# yes book, yes audience
|
||||||
|
audience = activitystreams.BooksStream().get_audience(status)
|
||||||
|
self.assertTrue(self.local_user in audience)
|
||||||
|
|
||||||
|
def test_localstream_get_audience_books_alternate_edition(self, *_):
|
||||||
|
"""get a list of users that should see a status"""
|
||||||
|
alt_book = models.Edition.objects.create(
|
||||||
|
title="hi", parent_work=self.book.parent_work
|
||||||
|
)
|
||||||
|
status = models.Comment.objects.create(
|
||||||
|
user=self.remote_user, content="hi", privacy="public", book=alt_book
|
||||||
|
)
|
||||||
|
models.ShelfBook.objects.create(
|
||||||
|
user=self.local_user,
|
||||||
|
shelf=self.local_user.shelf_set.first(),
|
||||||
|
book=self.book,
|
||||||
|
)
|
||||||
|
# yes book, yes audience
|
||||||
|
audience = activitystreams.BooksStream().get_audience(status)
|
||||||
|
self.assertTrue(self.local_user in audience)
|
||||||
|
|
||||||
|
def test_localstream_get_audience_books_non_public(self, *_):
|
||||||
|
"""get a list of users that should see a status"""
|
||||||
|
alt_book = models.Edition.objects.create(
|
||||||
|
title="hi", parent_work=self.book.parent_work
|
||||||
|
)
|
||||||
|
status = models.Comment.objects.create(
|
||||||
|
user=self.remote_user, content="hi", privacy="unlisted", book=alt_book
|
||||||
|
)
|
||||||
|
models.ShelfBook.objects.create(
|
||||||
|
user=self.local_user,
|
||||||
|
shelf=self.local_user.shelf_set.first(),
|
||||||
|
book=self.book,
|
||||||
|
)
|
||||||
|
# yes book, yes audience
|
||||||
|
audience = activitystreams.BooksStream().get_audience(status)
|
||||||
|
self.assertEqual(audience, [])
|
||||||
|
|
||||||
|
def test_get_statuses_for_user_books(self, *_):
|
||||||
|
"""create a stream for a user"""
|
||||||
|
alt_book = models.Edition.objects.create(
|
||||||
|
title="hi", parent_work=self.book.parent_work
|
||||||
|
)
|
||||||
|
status = models.Status.objects.create(
|
||||||
|
user=self.local_user, content="hi", privacy="public"
|
||||||
|
)
|
||||||
|
status = models.Comment.objects.create(
|
||||||
|
user=self.remote_user, content="hi", privacy="public", book=alt_book
|
||||||
|
)
|
||||||
|
models.ShelfBook.objects.create(
|
||||||
|
user=self.local_user,
|
||||||
|
shelf=self.local_user.shelf_set.first(),
|
||||||
|
book=self.book,
|
||||||
|
)
|
||||||
|
# yes book, yes audience
|
||||||
|
result = activitystreams.BooksStream().get_statuses_for_user(self.local_user)
|
||||||
|
self.assertEqual(list(result), [status])
|
||||||
|
|
Loading…
Reference in New Issue