def test_book_statuses(self, *_): """statuses about a book""" 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, ) with patch( "bookwyrm.activitystreams.BooksStream.bulk_add_objects_to_store" ) as redis_mock: activitystreams.BooksStream().add_book_statuses( self.local_user, self.book) args = redis_mock.call_args[0] queryset = args[0] self.assertEqual(queryset.count(), 1) self.assertTrue(status in queryset) self.assertEqual(args[1], f"{self.local_user.id}-books")
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_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_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_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])