1
0
Fork 0

Merge pull request #1613 from bookwyrm-social/list-not-loading

Use a redis cache to store lists for user
This commit is contained in:
Mouse Reeve 2022-01-08 13:38:20 -08:00 committed by GitHub
commit e1a617f742
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
108 changed files with 1044 additions and 204 deletions

View file

@ -31,7 +31,7 @@ class BaseActivity(TestCase):
"""we're probably going to re-use this so why copy/paste"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)

View file

@ -16,7 +16,7 @@ class Activitystreams(TestCase):
"""use a test csv"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
)

View file

@ -16,7 +16,7 @@ class Activitystreams(TestCase):
"""use a test csv"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
)

View file

@ -16,7 +16,7 @@ class Activitystreams(TestCase):
"""use a test csv"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
)

View file

@ -16,7 +16,7 @@ class Activitystreams(TestCase):
"""use a test csv"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
)

View file

@ -5,6 +5,8 @@ from bookwyrm import activitystreams, models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.lists_stream.add_user_lists_task.delay")
@patch("bookwyrm.lists_stream.remove_user_lists_task.delay")
class ActivitystreamsSignals(TestCase):
"""using redis to build activity streams"""
@ -12,7 +14,7 @@ class ActivitystreamsSignals(TestCase):
"""use a test csv"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
)
@ -32,11 +34,11 @@ class ActivitystreamsSignals(TestCase):
work = models.Work.objects.create(title="test work")
self.book = models.Edition.objects.create(title="test book", parent_work=work)
def test_add_status_on_create_ignore(self, _):
def test_add_status_on_create_ignore(self, *_):
"""a new statuses has entered"""
activitystreams.add_status_on_create(models.User, self.local_user, False)
def test_add_status_on_create_deleted(self, _):
def test_add_status_on_create_deleted(self, *_):
"""a new statuses has entered"""
with patch("bookwyrm.activitystreams.remove_status_task.delay"):
status = models.Status.objects.create(
@ -48,7 +50,7 @@ class ActivitystreamsSignals(TestCase):
args = mock.call_args[0]
self.assertEqual(args[0], status.id)
def test_add_status_on_create_created(self, _):
def test_add_status_on_create_created(self, *_):
"""a new statuses has entered"""
status = models.Status.objects.create(
user=self.remote_user, content="hi", privacy="public"
@ -60,18 +62,18 @@ class ActivitystreamsSignals(TestCase):
self.assertEqual(args["args"][0], status.id)
self.assertEqual(args["queue"], "high_priority")
def test_populate_streams_on_account_create(self, _):
def test_populate_streams_on_account_create_command(self, *_):
"""create streams for a user"""
with patch("bookwyrm.activitystreams.populate_stream_task.delay") as mock:
activitystreams.populate_streams_on_account_create(
models.User, self.local_user, True
activitystreams.populate_streams_on_account_create_command(
self.local_user.id
)
self.assertEqual(mock.call_count, 3)
args = mock.call_args[0]
self.assertEqual(args[0], "books")
self.assertEqual(args[1], self.local_user.id)
def test_remove_statuses_on_block(self, _):
def test_remove_statuses_on_block(self, *_):
"""don't show statuses from blocked users"""
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") as mock:
models.UserBlocks.objects.create(
@ -83,7 +85,7 @@ class ActivitystreamsSignals(TestCase):
self.assertEqual(args[0], self.local_user.id)
self.assertEqual(args[1], self.remote_user.id)
def test_add_statuses_on_unblock(self, _):
def test_add_statuses_on_unblock(self, *_):
"""re-add statuses on unblock"""
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"):
block = models.UserBlocks.objects.create(
@ -100,7 +102,7 @@ class ActivitystreamsSignals(TestCase):
self.assertEqual(args[1], self.remote_user.id)
self.assertEqual(kwargs["stream_list"], ["local", "books"])
def test_add_statuses_on_unblock_reciprocal_block(self, _):
def test_add_statuses_on_unblock_reciprocal_block(self, *_):
"""re-add statuses on unblock"""
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"):
block = models.UserBlocks.objects.create(

View file

@ -11,7 +11,7 @@ class Activitystreams(TestCase):
"""use a test csv"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
)

View file

@ -30,7 +30,7 @@ class GoodreadsImport(TestCase):
self.csv = open(datafile, "r", encoding=self.importer.encoding)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True
)

View file

@ -33,7 +33,7 @@ class GenericImporter(TestCase):
self.csv = open(datafile, "r", encoding=self.importer.encoding)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True
)

View file

@ -32,7 +32,7 @@ class LibrarythingImport(TestCase):
self.csv = open(datafile, "r", encoding=self.importer.encoding)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mmai", "mmai@mmai.mmai", "password", local=True
)

View file

@ -30,7 +30,7 @@ class OpenLibraryImport(TestCase):
self.csv = open(datafile, "r", encoding=self.importer.encoding)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True
)

View file

@ -30,7 +30,7 @@ class StorygraphImport(TestCase):
self.csv = open(datafile, "r", encoding=self.importer.encoding)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True
)

View file

@ -0,0 +1 @@
from . import *

View file

@ -0,0 +1,109 @@
""" testing lists_stream """
from unittest.mock import patch
from django.test import TestCase
from bookwyrm import lists_stream, models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class ListsStreamSignals(TestCase):
"""using redis to build activity streams"""
def setUp(self):
"""use a test csv"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
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(
"fish", "fish@fish.fish", "password", local=True, localname="fish"
)
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",
)
def test_add_list_on_create_command(self, _):
"""a new lists has entered"""
book_list = models.List.objects.create(
user=self.remote_user, name="hi", privacy="public"
)
with patch("bookwyrm.lists_stream.add_list_task.delay") as mock:
lists_stream.add_list_on_create_command(book_list.id)
self.assertEqual(mock.call_count, 1)
args = mock.call_args[0]
self.assertEqual(args[0], book_list.id)
def test_remove_list_on_delete(self, _):
"""delete a list"""
book_list = models.List.objects.create(
user=self.remote_user, name="hi", privacy="public"
)
with patch("bookwyrm.lists_stream.remove_list_task.delay") as mock:
lists_stream.remove_list_on_delete(models.List, book_list)
args = mock.call_args[0]
self.assertEqual(args[0], book_list.id)
def test_populate_lists_on_account_create_command(self, _):
"""create streams for a user"""
with patch("bookwyrm.lists_stream.populate_lists_task.delay") as mock:
lists_stream.add_list_on_account_create_command(self.local_user.id)
self.assertEqual(mock.call_count, 1)
args = mock.call_args[0]
self.assertEqual(args[0], self.local_user.id)
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
def test_remove_lists_on_block(self, *_):
"""don't show lists from blocked users"""
with patch("bookwyrm.lists_stream.remove_user_lists_task.delay") as mock:
models.UserBlocks.objects.create(
user_subject=self.local_user,
user_object=self.remote_user,
)
args = mock.call_args[0]
self.assertEqual(args[0], self.local_user.id)
self.assertEqual(args[1], self.remote_user.id)
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
def test_add_lists_on_unblock(self, *_):
"""re-add lists on unblock"""
with patch("bookwyrm.lists_stream.remove_user_lists_task.delay"):
block = models.UserBlocks.objects.create(
user_subject=self.local_user,
user_object=self.remote_user,
)
with patch("bookwyrm.lists_stream.add_user_lists_task.delay") as mock:
block.delete()
args = mock.call_args[0]
self.assertEqual(args[0], self.local_user.id)
self.assertEqual(args[1], self.remote_user.id)
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
def test_add_lists_on_unblock_reciprocal_block(self, *_):
"""dont' re-add lists on unblock if there's a block the other way"""
with patch("bookwyrm.lists_stream.remove_user_lists_task.delay"):
block = models.UserBlocks.objects.create(
user_subject=self.local_user,
user_object=self.remote_user,
)
block = models.UserBlocks.objects.create(
user_subject=self.remote_user,
user_object=self.local_user,
)
with patch("bookwyrm.lists_stream.add_user_lists_task.delay") as mock:
block.delete()
self.assertFalse(mock.called)

View file

@ -0,0 +1,171 @@
""" testing activitystreams """
from datetime import datetime
from unittest.mock import patch
from django.test import TestCase
from bookwyrm import lists_stream, models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
class ListsStream(TestCase):
"""using redis to build activity streams"""
def setUp(self):
"""use a test csv"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
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",
)
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",
)
self.stream = lists_stream.ListsStream()
def test_lists_stream_ids(self, *_):
"""the abstract base class for stream objects"""
self.assertEqual(
self.stream.stream_id(self.local_user),
f"{self.local_user.id}-lists",
)
def test_get_rank(self, *_):
"""sort order for lists"""
book_list = models.List.objects.create(
user=self.remote_user, name="hi", privacy="public"
)
book_list.updated_date = datetime(2020, 1, 1, 0, 0, 0)
self.assertEqual(self.stream.get_rank(book_list), 1577836800.0)
def test_add_user_lists(self, *_):
"""add all of a user's lists"""
book_list = models.List.objects.create(
user=self.remote_user, name="hi", privacy="public"
)
with patch(
"bookwyrm.lists_stream.ListsStream.bulk_add_objects_to_store"
) as mock:
self.stream.add_user_lists(self.local_user, self.remote_user)
self.assertEqual(mock.call_count, 1)
args = mock.call_args[0]
self.assertEqual(args[0][0], book_list)
self.assertEqual(args[1], f"{self.local_user.id}-lists")
def test_remove_user_lists(self, *_):
"""remove user's lists"""
book_list = models.List.objects.create(
user=self.remote_user, name="hi", privacy="public"
)
with patch(
"bookwyrm.lists_stream.ListsStream.bulk_remove_objects_from_store"
) as mock:
self.stream.remove_user_lists(self.local_user, self.remote_user)
self.assertEqual(mock.call_count, 1)
args = mock.call_args[0]
self.assertEqual(args[0][0], book_list)
self.assertEqual(args[1], f"{self.local_user.id}-lists")
def test_get_audience(self, *_):
"""get a list of users that should see a list"""
book_list = models.List.objects.create(
user=self.remote_user, name="hi", privacy="public"
)
users = self.stream.get_audience(book_list)
# remote users don't have feeds
self.assertFalse(self.remote_user in users)
self.assertTrue(self.local_user in users)
self.assertTrue(self.another_user in users)
def test_get_audience_direct(self, *_):
"""get a list of users that should see a list"""
book_list = models.List.objects.create(
user=self.remote_user,
name="hi",
privacy="direct",
)
users = self.stream.get_audience(book_list)
self.assertFalse(users.exists())
book_list = models.List.objects.create(
user=self.local_user,
name="hi",
privacy="direct",
)
users = self.stream.get_audience(book_list)
self.assertTrue(self.local_user in users)
self.assertFalse(self.another_user in users)
self.assertFalse(self.remote_user in users)
def test_get_audience_followers_remote_user(self, *_):
"""get a list of users that should see a list"""
book_list = models.List.objects.create(
user=self.remote_user,
name="hi",
privacy="followers",
)
users = self.stream.get_audience(book_list)
self.assertFalse(users.exists())
def test_get_audience_followers_self(self, *_):
"""get a list of users that should see a list"""
book_list = models.List.objects.create(
user=self.local_user,
name="hi",
privacy="followers",
)
users = self.stream.get_audience(book_list)
self.assertTrue(self.local_user in users)
self.assertFalse(self.another_user in users)
self.assertFalse(self.remote_user in users)
def test_get_audience_followers_with_relationship(self, *_):
"""get a list of users that should see a list"""
self.remote_user.followers.add(self.local_user)
book_list = models.List.objects.create(
user=self.remote_user,
name="hi",
privacy="followers",
)
users = self.stream.get_audience(book_list)
self.assertTrue(self.local_user in users)
self.assertFalse(self.another_user in users)
def test_get_audience_followers_with_group(self, *_):
"""get a list of users that should see a list"""
group = models.Group.objects.create(name="test group", user=self.remote_user)
models.GroupMember.objects.create(
group=group,
user=self.local_user,
)
book_list = models.List.objects.create(
user=self.remote_user, name="hi", privacy="followers", curation="group"
)
users = self.stream.get_audience(book_list)
self.assertFalse(self.local_user in users)
book_list.group = group
book_list.save(broadcast=False)
users = self.stream.get_audience(book_list)
self.assertTrue(self.local_user in users)
self.assertFalse(self.another_user in users)

View file

@ -0,0 +1,109 @@
""" testing lists_stream """
from unittest.mock import patch
from django.test import TestCase
from bookwyrm import lists_stream, models
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
class Activitystreams(TestCase):
"""using redis to build activity streams"""
def setUp(self):
"""use a test csv"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
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",
)
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",
)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
self.list = models.List.objects.create(
user=self.local_user, name="hi", privacy="public"
)
def test_populate_lists_task(self, *_):
"""populate lists cache"""
with patch("bookwyrm.lists_stream.ListsStream.populate_lists") as mock:
lists_stream.populate_lists_task(self.local_user.id)
self.assertTrue(mock.called)
args = mock.call_args[0]
self.assertEqual(args[0], self.local_user)
with patch("bookwyrm.lists_stream.ListsStream.populate_lists") as mock:
lists_stream.populate_lists_task(self.local_user.id)
self.assertTrue(mock.called)
args = mock.call_args[0]
self.assertEqual(args[0], self.local_user)
def test_remove_list_task(self, *_):
"""remove a list from all streams"""
with patch(
"bookwyrm.lists_stream.ListsStream.remove_object_from_related_stores"
) as mock:
lists_stream.remove_list_task(self.list.id)
self.assertEqual(mock.call_count, 1)
args = mock.call_args[0]
self.assertEqual(args[0], self.list.id)
def test_add_list_task(self, *_):
"""add a list to all streams"""
with patch("bookwyrm.lists_stream.ListsStream.add_list") as mock:
lists_stream.add_list_task(self.list.id)
self.assertEqual(mock.call_count, 1)
args = mock.call_args[0]
self.assertEqual(args[0], self.list)
def test_remove_user_lists_task(self, *_):
"""remove all lists by a user from another users' feeds"""
with patch("bookwyrm.lists_stream.ListsStream.remove_user_lists") as mock:
lists_stream.remove_user_lists_task(
self.local_user.id, self.another_user.id
)
self.assertEqual(mock.call_count, 1)
args = mock.call_args[0]
self.assertEqual(args[0], self.local_user)
self.assertEqual(args[1], self.another_user)
with patch("bookwyrm.lists_stream.ListsStream.remove_user_lists") as mock:
lists_stream.remove_user_lists_task(
self.local_user.id, self.another_user.id
)
self.assertEqual(mock.call_count, 1)
args = mock.call_args[0]
self.assertEqual(args[0], self.local_user)
self.assertEqual(args[1], self.another_user)
def test_add_user_lists_task(self, *_):
"""add a user's lists to another users feeds"""
with patch("bookwyrm.lists_stream.ListsStream.add_user_lists") as mock:
lists_stream.add_user_lists_task(self.local_user.id, self.another_user.id)
self.assertEqual(mock.call_count, 1)
args = mock.call_args[0]
self.assertEqual(args[0], self.local_user)
self.assertEqual(args[1], self.another_user)
with patch("bookwyrm.lists_stream.ListsStream.add_user_lists") as mock:
lists_stream.add_user_lists_task(self.local_user.id, self.another_user.id)
self.assertEqual(mock.call_count, 1)
args = mock.call_args[0]
self.assertEqual(args[0], self.local_user)
self.assertEqual(args[1], self.another_user)

View file

@ -0,0 +1,54 @@
""" test populating user streams """
from unittest.mock import patch
from django.test import TestCase
from bookwyrm import models
from bookwyrm.management.commands.populate_lists_streams import populate_lists_streams
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
class Activitystreams(TestCase):
"""using redis to build activity streams"""
def setUp(self):
"""we need some stuff"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
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",
)
models.User.objects.create_user(
"gerbil",
"gerbil@nutria.nutria",
"password",
local=True,
localname="gerbil",
is_active=False,
)
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",
)
self.book = models.Edition.objects.create(title="test book")
def test_populate_streams(self, *_):
"""make sure the function on the redis manager gets called"""
with patch("bookwyrm.lists_stream.populate_lists_task.delay") as list_mock:
populate_lists_streams()
self.assertEqual(list_mock.call_count, 2) # 2 users

View file

@ -14,7 +14,7 @@ class Activitystreams(TestCase):
"""we need some stuff"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
)
@ -25,6 +25,14 @@ class Activitystreams(TestCase):
local=True,
localname="nutria",
)
models.User.objects.create_user(
"gerbil",
"gerbil@gerbil.gerbil",
"password",
local=True,
localname="gerbil",
is_active=False,
)
with patch("bookwyrm.models.user.set_remote_server.delay"):
self.remote_user = models.User.objects.create_user(
"rat",
@ -44,6 +52,11 @@ class Activitystreams(TestCase):
user=self.local_user, content="hi", book=self.book
)
with patch("bookwyrm.activitystreams.populate_stream_task.delay") as redis_mock:
with patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
) as redis_mock, patch(
"bookwyrm.lists_stream.populate_lists_task.delay"
) as list_mock:
populate_streams()
self.assertEqual(redis_mock.call_count, 6) # 2 users x 3 streams
self.assertEqual(list_mock.call_count, 2) # 2 users

View file

@ -29,7 +29,7 @@ class ActivitypubMixins(TestCase):
"""shared data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
)
@ -332,7 +332,7 @@ class ActivitypubMixins(TestCase):
self.assertEqual(activity["id"], "https://example.com/status/1/activity")
self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["type"], "Delete")
self.assertEqual(activity["to"], ["%s/followers" % self.local_user.remote_id])
self.assertEqual(activity["to"], [f"{self.local_user.remote_id}/followers"])
self.assertEqual(
activity["cc"], ["https://www.w3.org/ns/activitystreams#Public"]
)
@ -374,7 +374,7 @@ class ActivitypubMixins(TestCase):
for number in range(0, 2 * PAGE_LENGTH):
models.Status.objects.create(
user=self.local_user,
content="test status {:d}".format(number),
content=f"test status {number}",
)
page_1 = to_ordered_collection_page(
models.Status.objects.all(), "http://fish.com/", page=1
@ -400,7 +400,7 @@ class ActivitypubMixins(TestCase):
for number in range(0, 2 * PAGE_LENGTH):
models.Status.objects.create(
user=self.local_user,
content="test status {:d}".format(number),
content=f"test status {number}",
)
MockSelf = namedtuple("Self", ("remote_id"))

View file

@ -16,7 +16,7 @@ class BaseModel(TestCase):
"""shared data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
)

View file

@ -27,6 +27,7 @@ from bookwyrm.settings import DOMAIN
# pylint: disable=too-many-public-methods
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
class ModelFields(TestCase):
"""overwrites standard model feilds to work with activitypub"""

View file

@ -14,21 +14,15 @@ class Group(TestCase):
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.owner_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
self.rat = models.User.objects.create_user(
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
self.badger = models.User.objects.create_user(
"badger",
"badger@badger.badger",
@ -37,9 +31,6 @@ class Group(TestCase):
localname="badger",
)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
self.capybara = models.User.objects.create_user(
"capybara",
"capybara@capybara.capybara",

View file

@ -20,7 +20,7 @@ class ImportJob(TestCase):
"""data is from a goodreads export of The Raven Tower"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True
)

View file

@ -1,7 +1,7 @@
""" testing models """
from uuid import UUID
from unittest.mock import patch
from django.test import TestCase
from uuid import UUID
from bookwyrm import models, settings
@ -14,7 +14,7 @@ class List(TestCase):
"""look, a list"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)
@ -27,7 +27,7 @@ class List(TestCase):
book_list = models.List.objects.create(
name="Test List", user=self.local_user
)
expected_id = "https://%s/list/%d" % (settings.DOMAIN, book_list.id)
expected_id = f"https://{settings.DOMAIN}/list/{book_list.id}"
self.assertEqual(book_list.get_remote_id(), expected_id)
def test_to_activity(self, _):

View file

@ -15,7 +15,7 @@ class ReadThrough(TestCase):
"""look, a shelf"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)

View file

@ -1,12 +1,16 @@
""" testing models """
import json
from unittest.mock import patch
from django.db import IntegrityError
from django.test import TestCase
from bookwyrm import models
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
@patch("bookwyrm.lists_stream.add_user_lists_task.delay")
@patch("bookwyrm.lists_stream.remove_user_lists_task.delay")
class Relationship(TestCase):
"""following, blocking, stuff like that"""
@ -24,14 +28,39 @@ class Relationship(TestCase):
)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
)
self.local_user.remote_id = "http://local.com/user/mouse"
self.local_user.save(broadcast=False, update_fields=["remote_id"])
def test_user_follows_from_request(self, _):
def test_user_follows(self, *_):
"""basic functionality of user follows"""
relationship = models.UserFollows.objects.create(
user_subject=self.local_user, user_object=self.remote_user
)
self.assertEqual(relationship.status, "follows")
activity = relationship.to_activity()
self.assertEqual(activity.type, "Follow")
self.assertEqual(
relationship.remote_id,
f"http://local.com/user/mouse#follows/{relationship.id}",
)
def test_user_follows_blocks(self, *_):
"""can't follow if you're blocked"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.UserBlocks.objects.create(
user_subject=self.local_user, user_object=self.remote_user
)
with self.assertRaises(IntegrityError):
models.UserFollows.objects.create(
user_subject=self.local_user, user_object=self.remote_user
)
def test_user_follows_from_request(self, *_):
"""convert a follow request into a follow"""
with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
@ -42,19 +71,19 @@ class Relationship(TestCase):
activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Follow")
self.assertEqual(
request.remote_id, "http://local.com/user/mouse#follows/%d" % request.id
request.remote_id, f"http://local.com/user/mouse#follows/{request.id}"
)
self.assertEqual(request.status, "follow_request")
rel = models.UserFollows.from_request(request)
self.assertEqual(
rel.remote_id, "http://local.com/user/mouse#follows/%d" % request.id
rel.remote_id, f"http://local.com/user/mouse#follows/{request.id}"
)
self.assertEqual(rel.status, "follows")
self.assertEqual(rel.user_subject, self.local_user)
self.assertEqual(rel.user_object, self.remote_user)
def test_user_follows_from_request_custom_remote_id(self, _):
def test_user_follows_from_request_custom_remote_id(self, *_):
"""store a specific remote id for a relationship provided by remote"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
request = models.UserFollowRequest.objects.create(
@ -72,7 +101,7 @@ class Relationship(TestCase):
self.assertEqual(rel.user_object, self.remote_user)
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_follow_request_activity(self, broadcast_mock, _):
def test_follow_request_activity(self, broadcast_mock, *_):
"""accept a request and make it a relationship"""
models.UserFollowRequest.objects.create(
user_subject=self.local_user,
@ -84,7 +113,7 @@ class Relationship(TestCase):
self.assertEqual(activity["type"], "Follow")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_follow_request_accept(self, broadcast_mock, _):
def test_follow_request_accept(self, broadcast_mock, *_):
"""accept a request and make it a relationship"""
self.local_user.manually_approves_followers = True
self.local_user.save(
@ -110,7 +139,7 @@ class Relationship(TestCase):
self.assertEqual(rel.user_object, self.local_user)
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
def test_follow_request_reject(self, broadcast_mock, _):
def test_follow_request_reject(self, broadcast_mock, *_):
"""accept a request and make it a relationship"""
self.local_user.manually_approves_followers = True
self.local_user.save(

View file

@ -9,6 +9,7 @@ from bookwyrm import models, settings
# pylint: disable=unused-argument
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
class Shelf(TestCase):
@ -18,7 +19,7 @@ class Shelf(TestCase):
"""look, a shelf"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)
@ -31,7 +32,7 @@ class Shelf(TestCase):
shelf = models.Shelf.objects.create(
name="Test Shelf", identifier="test-shelf", user=self.local_user
)
expected_id = "https://%s/user/mouse/books/test-shelf" % settings.DOMAIN
expected_id = f"https://{settings.DOMAIN}/user/mouse/books/test-shelf"
self.assertEqual(shelf.get_remote_id(), expected_id)
def test_to_activity(self, *_):

View file

@ -16,7 +16,7 @@ class SiteModels(TestCase):
"""we need basic test data and mocks"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -28,7 +28,7 @@ class Status(TestCase):
"""useful things for creating a status"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)

View file

@ -15,7 +15,7 @@ class User(TestCase):
def setUp(self):
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.user = models.User.objects.create_user(
"mouse@%s" % DOMAIN,
"mouse@mouse.mouse",

View file

@ -16,7 +16,7 @@ class BookWyrmTags(TestCase):
"""create some filler objects"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.mouse",

View file

@ -16,7 +16,7 @@ class InteractionTags(TestCase):
"""create some filler objects"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.mouse",

View file

@ -17,7 +17,7 @@ class StatusDisplayTags(TestCase):
"""create some filler objects"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.mouse",

View file

@ -17,7 +17,7 @@ class UtilitiesTags(TestCase):
"""create some filler objects"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.mouse",
@ -50,3 +50,10 @@ class UtilitiesTags(TestCase):
"""uuid functionality"""
uuid = utilities.get_uuid("hi")
self.assertTrue(re.match(r"hi[A-Za-z0-9\-]", uuid))
def test_get_title(self, *_):
"""the title of a book"""
self.assertEqual(utilities.get_title(None), "")
self.assertEqual(utilities.get_title(self.book), "Test Book")
book = models.Edition.objects.create(title="Oh", subtitle="oh my")
self.assertEqual(utilities.get_title(book), "Oh: oh my")

View file

@ -16,7 +16,7 @@ class Emailing(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -32,7 +32,7 @@ class PreviewImages(TestCase):
)
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"possum@local.com",
"possum@possum.possum",

View file

@ -39,19 +39,19 @@ class Signature(TestCase):
"""create users and test data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.mouse = models.User.objects.create_user(
"mouse@%s" % DOMAIN,
f"mouse@{DOMAIN}",
"mouse@example.com",
"",
local=True,
localname="mouse",
)
self.rat = models.User.objects.create_user(
"rat@%s" % DOMAIN, "rat@example.com", "", local=True, localname="rat"
f"rat@{DOMAIN}", "rat@example.com", "", local=True, localname="rat"
)
self.cat = models.User.objects.create_user(
"cat@%s" % DOMAIN, "cat@example.com", "", local=True, localname="cat"
f"cat@{DOMAIN}", "cat@example.com", "", local=True, localname="cat"
)
private_key, public_key = create_key_pair()
@ -75,7 +75,7 @@ class Signature(TestCase):
"HTTP_DIGEST": digest,
"HTTP_CONTENT_TYPE": "application/activity+json; charset=utf-8",
"HTTP_HOST": DOMAIN,
}
},
)
def send_test_request( # pylint: disable=too-many-arguments

View file

@ -13,6 +13,7 @@ from bookwyrm.suggested_users import suggested_users, get_annotated_users
@patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
@patch("bookwyrm.suggested_users.remove_user_task.delay")
@ -23,7 +24,7 @@ class SuggestedUsers(TestCase):
"""use a test csv"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
)
@ -235,12 +236,3 @@ class SuggestedUsers(TestCase):
)
user_1_annotated = result.get(id=user_1.id)
self.assertEqual(user_1_annotated.mutuals, 3)
def test_create_user_signal(self, *_):
"""build suggestions for new users"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") as mock:
models.User.objects.create_user(
"nutria", "nutria@nu.tria", "password", local=True, localname="nutria"
)
self.assertEqual(mock.call_count, 1)

View file

@ -16,7 +16,7 @@ class AnnouncementViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -16,7 +16,7 @@ class DashboardViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -17,7 +17,7 @@ class EmailBlocklistViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -19,7 +19,7 @@ class FederationViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -16,7 +16,7 @@ class IPBlocklistViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -18,7 +18,7 @@ class ReportViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -18,7 +18,7 @@ class UserAdminViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -28,7 +28,7 @@ class BookViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -21,7 +21,7 @@ class EditBookViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -18,7 +18,7 @@ class BookViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -19,7 +19,7 @@ class ImportViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -16,7 +16,7 @@ class ImportManualReviewViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -16,7 +16,7 @@ class ImportTroubleshootViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -22,7 +22,7 @@ class Inbox(TestCase):
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",

View file

@ -15,7 +15,7 @@ class InboxAdd(TestCase):
"""basic user and book data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",

View file

@ -15,7 +15,7 @@ class InboxActivities(TestCase):
"""basic user and book data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",

View file

@ -14,7 +14,7 @@ class InboxBlock(TestCase):
"""basic user and book data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -57,7 +57,7 @@ class InboxBlock(TestCase):
with patch(
"bookwyrm.activitystreams.remove_user_statuses_task.delay"
) as redis_mock:
) as redis_mock, patch("bookwyrm.lists_stream.remove_user_lists_task.delay"):
views.inbox.activity_task(activity)
self.assertTrue(redis_mock.called)
views.inbox.activity_task(activity)
@ -70,7 +70,9 @@ class InboxBlock(TestCase):
self.assertFalse(models.UserFollowRequest.objects.exists())
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
def test_handle_unblock(self, _):
@patch("bookwyrm.lists_stream.add_user_lists_task.delay")
@patch("bookwyrm.lists_stream.remove_user_lists_task.delay")
def test_handle_unblock(self, *_):
"""unblock a user"""
self.remote_user.blocks.add(self.local_user)

View file

@ -19,7 +19,7 @@ class InboxCreate(TestCase):
"""basic user and book data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",

View file

@ -15,7 +15,7 @@ class InboxActivities(TestCase):
"""basic user and book data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -51,7 +51,7 @@ class InboxActivities(TestCase):
"type": "Delete",
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"cc": ["https://example.com/user/mouse/followers"],
"id": "%s/activity" % self.status.remote_id,
"id": f"{self.status.remote_id}/activity",
"actor": self.remote_user.remote_id,
"object": {"id": self.status.remote_id, "type": "Tombstone"},
}
@ -80,7 +80,7 @@ class InboxActivities(TestCase):
"type": "Delete",
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"cc": ["https://example.com/user/mouse/followers"],
"id": "%s/activity" % self.status.remote_id,
"id": f"{self.status.remote_id}/activity",
"actor": self.remote_user.remote_id,
"object": {"id": self.status.remote_id, "type": "Tombstone"},
}
@ -152,5 +152,7 @@ class InboxActivities(TestCase):
"cc": [],
},
}
views.inbox.activity_task(activity)
with patch("bookwyrm.lists_stream.remove_list_task.delay") as mock:
views.inbox.activity_task(activity)
self.assertTrue(mock.called)
self.assertFalse(models.List.objects.exists())

View file

@ -15,7 +15,7 @@ class InboxRelationships(TestCase):
"""basic user and book data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -188,7 +188,8 @@ class InboxRelationships(TestCase):
self.assertIsNone(self.local_user.followers.first())
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
def test_follow_accept(self, _):
@patch("bookwyrm.lists_stream.add_user_lists_task.delay")
def test_follow_accept(self, *_):
"""a remote user approved a follow request from local"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
rel = models.UserFollowRequest.objects.create(

View file

@ -14,7 +14,7 @@ class InboxActivities(TestCase):
"""basic user and book data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",

View file

@ -14,7 +14,7 @@ class InboxRemove(TestCase):
"""basic user and book data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",

View file

@ -16,7 +16,7 @@ class InboxUpdate(TestCase):
"""basic user and book data"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -78,6 +78,7 @@ class InboxUpdate(TestCase):
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
@patch("bookwyrm.lists_stream.add_user_lists_task.delay")
def test_update_user(self, *_):
"""update an existing user"""
models.UserFollows.objects.create(

View file

@ -19,7 +19,7 @@ class InviteViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -18,7 +18,7 @@ class LandingViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -21,7 +21,7 @@ class LoginViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@your.domain.here",
"mouse@mouse.com",

View file

@ -21,7 +21,7 @@ class PasswordViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -16,6 +16,7 @@ from bookwyrm.tests.validate_html import validate_html
# pylint: disable=too-many-public-methods
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
class RegisterViews(TestCase):
"""login and password management"""
@ -24,7 +25,7 @@ class RegisterViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@your.domain.here",
"mouse@mouse.com",

View file

@ -18,7 +18,7 @@ class BlockViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",
@ -61,7 +61,9 @@ class BlockViews(TestCase):
request = self.factory.post("")
request.user = self.local_user
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"):
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"), patch(
"bookwyrm.lists_stream.remove_user_lists_task.delay"
):
view(request, self.remote_user.id)
block = models.UserBlocks.objects.get()
self.assertEqual(block.user_subject, self.local_user)
@ -76,7 +78,9 @@ class BlockViews(TestCase):
request = self.factory.post("")
request.user = self.local_user
with patch("bookwyrm.activitystreams.add_user_statuses_task.delay"):
with patch("bookwyrm.activitystreams.add_user_statuses_task.delay"), patch(
"bookwyrm.lists_stream.add_user_lists_task.delay"
):
views.unblock(request, self.remote_user.id)
self.assertFalse(models.UserBlocks.objects.exists())

View file

@ -17,7 +17,7 @@ class ChangePasswordViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -20,7 +20,7 @@ class DeleteUserViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -23,7 +23,7 @@ class EditUserViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -14,6 +14,7 @@ from bookwyrm.tests.validate_html import validate_html
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
class ShelfViews(TestCase):
@ -24,7 +25,7 @@ class ShelfViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -12,6 +12,7 @@ from bookwyrm import forms, models, views
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
class ShelfActionViews(TestCase):
@ -22,7 +23,7 @@ class ShelfActionViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",
@ -178,7 +179,7 @@ class ShelfActionViews(TestCase):
"""delete a brand new custom shelf"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
rat = models.User.objects.create_user(
"rat@local.com",
"rat@mouse.mouse",

View file

@ -26,7 +26,7 @@ class AnnualSummary(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -21,7 +21,7 @@ class AuthorViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -18,7 +18,7 @@ class DirectoryViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",
@ -34,6 +34,7 @@ class DirectoryViews(TestCase):
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
def test_directory_page(self, *_):
"""there are so many views, this just makes sure it LOADS"""

View file

@ -16,7 +16,7 @@ class DiscoverViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -10,8 +10,7 @@ from django.template.response import TemplateResponse
from django.test import TestCase
from django.test.client import RequestFactory
from bookwyrm import models
from bookwyrm import views
from bookwyrm import forms, models, views
from bookwyrm.activitypub import ActivitypubResponse
from bookwyrm.tests.validate_html import validate_html
@ -20,6 +19,7 @@ from bookwyrm.tests.validate_html import validate_html
@patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
@patch("bookwyrm.suggested_users.remove_user_task.delay")
class FeedViews(TestCase):
"""activity feed, statuses, dms"""
@ -29,7 +29,7 @@ class FeedViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",
@ -62,6 +62,25 @@ class FeedViews(TestCase):
validate_html(result.render())
self.assertEqual(result.status_code, 200)
@patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions")
def test_save_feed_settings(self, *_):
"""update display preferences"""
self.assertEqual(
self.local_user.feed_status_types,
["review", "comment", "quotation", "everything"],
)
view = views.Feed.as_view()
form = forms.FeedStatusTypesForm(instance=self.local_user)
form.data["feed_status_types"] = "review"
request = self.factory.post("", form.data)
request.user = self.local_user
result = view(request, "home")
self.assertEqual(result.status_code, 200)
self.local_user.refresh_from_db()
self.assertEqual(self.local_user.feed_status_types, ["review"])
def test_status_page(self, *_):
"""there are so many views, this just makes sure it LOADS"""
view = views.Status.as_view()

View file

@ -13,6 +13,7 @@ from bookwyrm.tests.validate_html import validate_html
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
@patch("bookwyrm.lists_stream.add_user_lists_task.delay")
class FollowViews(TestCase):
"""follows"""
@ -22,7 +23,7 @@ class FollowViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",
@ -56,7 +57,7 @@ class FollowViews(TestCase):
parent_work=self.work,
)
def test_handle_follow_remote(self, _):
def test_handle_follow_remote(self, *_):
"""send a follow request"""
request = self.factory.post("", {"user": self.remote_user.username})
request.user = self.local_user
@ -71,11 +72,11 @@ class FollowViews(TestCase):
self.assertEqual(rel.user_object, self.remote_user)
self.assertEqual(rel.status, "follow_request")
def test_handle_follow_local_manually_approves(self, _):
def test_handle_follow_local_manually_approves(self, *_):
"""send a follow request"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
rat = models.User.objects.create_user(
"rat@local.com",
"rat@rat.com",
@ -97,11 +98,11 @@ class FollowViews(TestCase):
self.assertEqual(rel.user_object, rat)
self.assertEqual(rel.status, "follow_request")
def test_handle_follow_local(self, _):
def test_handle_follow_local(self, *_):
"""send a follow request"""
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
rat = models.User.objects.create_user(
"rat@local.com",
"rat@rat.com",
@ -124,6 +125,7 @@ class FollowViews(TestCase):
self.assertEqual(rel.status, "follows")
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
@patch("bookwyrm.lists_stream.remove_user_lists_task.delay")
def test_handle_unfollow(self, *_):
"""send an unfollow"""
request = self.factory.post("", {"user": self.remote_user.username})
@ -140,7 +142,7 @@ class FollowViews(TestCase):
self.assertEqual(self.remote_user.followers.count(), 0)
def test_handle_accept(self, _):
def test_handle_accept(self, *_):
"""accept a follow request"""
self.local_user.manually_approves_followers = True
self.local_user.save(
@ -159,7 +161,7 @@ class FollowViews(TestCase):
# follow relationship should exist
self.assertEqual(self.local_user.followers.first(), self.remote_user)
def test_handle_reject(self, _):
def test_handle_reject(self, *_):
"""reject a follow request"""
self.local_user.manually_approves_followers = True
self.local_user.save(
@ -178,7 +180,7 @@ class FollowViews(TestCase):
# follow relationship should not exist
self.assertEqual(models.UserFollows.objects.filter(id=rel.id).count(), 0)
def test_ostatus_follow_request(self, _):
def test_ostatus_follow_request(self, *_):
"""check ostatus subscribe template loads"""
request = self.factory.get(
"", {"acct": "https%3A%2F%2Fexample.com%2Fusers%2Frat"}
@ -189,7 +191,7 @@ class FollowViews(TestCase):
validate_html(result.render())
self.assertEqual(result.status_code, 200)
def test_remote_follow_page(self, _):
def test_remote_follow_page(self, *_):
"""check remote follow page loads"""
request = self.factory.get("", {"acct": "mouse@local.com"})
request.user = self.remote_user
@ -198,7 +200,7 @@ class FollowViews(TestCase):
validate_html(result.render())
self.assertEqual(result.status_code, 200)
def test_ostatus_follow_success(self, _):
def test_ostatus_follow_success(self, *_):
"""check remote follow success page loads"""
request = self.factory.get("")
request.user = self.remote_user
@ -208,7 +210,7 @@ class FollowViews(TestCase):
validate_html(result.render())
self.assertEqual(result.status_code, 200)
def test_remote_follow(self, _):
def test_remote_follow(self, *_):
"""check follow from remote page loads"""
request = self.factory.post("", {"user": self.remote_user.id})
request.user = self.remote_user

View file

@ -17,7 +17,7 @@ class GetStartedViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -20,7 +20,7 @@ class GoalViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -20,7 +20,7 @@ class GroupViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -23,7 +23,7 @@ class ViewsHelpers(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
with patch("bookwyrm.suggested_users.rerank_user_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",

View file

@ -17,7 +17,7 @@ class InteractionViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -18,7 +18,7 @@ class IsbnViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",
@ -49,3 +49,13 @@ class IsbnViews(TestCase):
self.assertEqual(len(data), 1)
self.assertEqual(data[0]["title"], "Test Book")
self.assertEqual(data[0]["key"], f"https://{DOMAIN}/book/{self.book.id}")
def test_isbn_html_response(self):
"""searches local data only and returns book data in json format"""
view = views.Isbn.as_view()
request = self.factory.get("")
with patch("bookwyrm.views.isbn.is_api_request") as is_api:
is_api.return_value = False
response = view(request, isbn="1234567890123")
self.assertEqual(response.status_code, 200)
response.render()

View file

@ -21,7 +21,7 @@ class ListViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",
@ -72,10 +72,13 @@ class ListViews(TestCase):
models.SiteSettings.objects.create()
def test_lists_page(self):
@patch("bookwyrm.lists_stream.ListsStream.get_list_stream")
def test_lists_page(self, _):
"""there are so many views, this just makes sure it LOADS"""
view = views.Lists.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
), patch("bookwyrm.lists_stream.add_list_task.delay"):
models.List.objects.create(name="Public list", user=self.local_user)
models.List.objects.create(
name="Private list", privacy="direct", user=self.local_user
@ -346,16 +349,16 @@ class ListViews(TestCase):
def test_curate_page(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.Curate.as_view()
request = self.factory.get("")
request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
models.ListItem.objects.create(
user=self.local_user,
book_list=self.list,
user=self.local_user,
book=self.book,
approved=False,
order=1,
)
request = self.factory.get("")
request.user = self.local_user
result = view(request, self.list.id)
self.assertIsInstance(result, TemplateResponse)

View file

@ -18,7 +18,7 @@ class ListActionViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",
@ -90,8 +90,9 @@ class ListActionViews(TestCase):
request.user = self.local_user
with patch(
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
) as mock:
) as mock, patch("bookwyrm.lists_stream.remove_list_task.delay") as redis_mock:
views.delete_list(request, self.list.id)
self.assertTrue(redis_mock.called)
activity = json.loads(mock.call_args[1]["args"][1])
self.assertEqual(activity["type"], "Delete")
self.assertEqual(activity["actor"], self.local_user.remote_id)
@ -123,10 +124,7 @@ class ListActionViews(TestCase):
request = self.factory.post(
"",
{
"item": pending.id,
"approved": "true",
},
{"item": pending.id, "approved": "true"},
)
request.user = self.local_user
@ -553,12 +551,7 @@ class ListActionViews(TestCase):
)
self.assertTrue(self.list.listitem_set.exists())
request = self.factory.post(
"",
{
"item": item.id,
},
)
request = self.factory.post("", {"item": item.id})
request.user = self.local_user
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
@ -572,14 +565,22 @@ class ListActionViews(TestCase):
book_list=self.list, user=self.local_user, book=self.book, order=1
)
self.assertTrue(self.list.listitem_set.exists())
request = self.factory.post(
"",
{
"item": item.id,
},
)
request = self.factory.post("", {"item": item.id})
request.user = self.rat
with self.assertRaises(PermissionDenied):
views.list.remove_book(request, self.list.id)
self.assertTrue(self.list.listitem_set.exists())
def test_save_unsave_list(self):
"""bookmark a list"""
self.assertFalse(self.local_user.saved_lists.exists())
request = self.factory.post("")
request.user = self.local_user
views.save_list(request, self.list.id)
self.local_user.refresh_from_db()
self.assertEqual(self.local_user.saved_lists.first(), self.list)
views.unsave_list(request, self.list.id)
self.local_user.refresh_from_db()
self.assertFalse(self.local_user.saved_lists.exists())

View file

@ -17,7 +17,7 @@ class NotificationViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -20,7 +20,7 @@ class OutboxView(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -20,7 +20,7 @@ class ReadingViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -27,7 +27,7 @@ class ReadThrough(TestCase):
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.user = models.User.objects.create_user(
"cinco", "cinco@example.com", "seissiete", local=True, localname="cinco"
)

View file

@ -15,7 +15,7 @@ class RssFeedView(TestCase):
def setUp(self):
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"rss_user", "rss@test.rss", "password", local=True
)

View file

@ -23,7 +23,7 @@ class Views(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -13,6 +13,7 @@ from bookwyrm.tests.validate_html import validate_html
# pylint: disable=invalid-name
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
@patch("bookwyrm.activitystreams.remove_status_task.delay")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class StatusViews(TestCase):
@ -23,7 +24,7 @@ class StatusViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",

View file

@ -2,7 +2,7 @@
import json
from unittest.mock import patch
from django.http import JsonResponse
from django.http import Http404, JsonResponse
from django.test import TestCase
from django.test.client import RequestFactory
@ -17,7 +17,7 @@ class UpdateViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",
@ -54,6 +54,7 @@ class UpdateViews(TestCase):
"bookwyrm.activitystreams.ActivityStream.get_unread_count"
) as mock_count:
with patch(
# pylint:disable=line-too-long
"bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type"
) as mock_count_by_status:
mock_count.return_value = 3
@ -64,3 +65,11 @@ class UpdateViews(TestCase):
data = json.loads(result.getvalue())
self.assertEqual(data["count"], 3)
self.assertEqual(data["count_by_type"]["review"], 5)
def test_get_unread_status_count_invalid_stream(self):
"""there are so many views, this just makes sure it LOADS"""
request = self.factory.get("")
request.user = self.local_user
with self.assertRaises(Http404):
views.get_unread_status_count(request, "fish")

View file

@ -20,7 +20,7 @@ class UserViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",

View file

@ -18,7 +18,7 @@ class WellknownViews(TestCase):
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.mouse",