2021-04-16 00:43:27 +00:00
|
|
|
""" test populating user streams """
|
|
|
|
from unittest.mock import patch
|
|
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
from bookwyrm import models
|
|
|
|
from bookwyrm.management.commands.populate_streams import populate_streams
|
|
|
|
|
|
|
|
|
2021-11-12 17:17:00 +00:00
|
|
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
2021-04-16 00:43:27 +00:00
|
|
|
class Activitystreams(TestCase):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""using redis to build activity streams"""
|
2021-04-16 00:43:27 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""we need some stuff"""
|
2021-09-06 21:48:45 +00:00
|
|
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
|
|
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
|
|
|
):
|
2021-08-03 17:25:53 +00:00
|
|
|
self.local_user = models.User.objects.create_user(
|
|
|
|
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
|
|
|
)
|
|
|
|
self.another_user = models.User.objects.create_user(
|
|
|
|
"nutria",
|
|
|
|
"nutria@nutria.nutria",
|
|
|
|
"password",
|
|
|
|
local=True,
|
|
|
|
localname="nutria",
|
|
|
|
)
|
2021-08-02 23:05:40 +00:00
|
|
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
|
|
|
self.remote_user = models.User.objects.create_user(
|
|
|
|
"rat",
|
|
|
|
"rat@rat.com",
|
|
|
|
"ratword",
|
|
|
|
local=False,
|
|
|
|
remote_id="https://example.com/users/rat",
|
|
|
|
inbox="https://example.com/users/rat/inbox",
|
|
|
|
outbox="https://example.com/users/rat/outbox",
|
2021-05-26 21:57:29 +00:00
|
|
|
)
|
2021-08-02 23:05:40 +00:00
|
|
|
self.book = models.Edition.objects.create(title="test book")
|
2021-04-16 00:43:27 +00:00
|
|
|
|
2021-04-16 00:48:43 +00:00
|
|
|
def test_populate_streams(self, _):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""make sure the function on the redis manager gets called"""
|
2021-09-06 20:53:49 +00:00
|
|
|
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
2021-04-16 00:43:27 +00:00
|
|
|
models.Comment.objects.create(
|
|
|
|
user=self.local_user, content="hi", book=self.book
|
|
|
|
)
|
|
|
|
|
2021-08-08 14:32:23 +00:00
|
|
|
with patch("bookwyrm.activitystreams.populate_stream_task.delay") as redis_mock:
|
2021-04-16 00:43:27 +00:00
|
|
|
populate_streams()
|
2021-08-08 21:17:02 +00:00
|
|
|
self.assertEqual(redis_mock.call_count, 6) # 2 users x 3 streams
|