Merge pull request #1613 from bookwyrm-social/list-not-loading
Use a redis cache to store lists for user
This commit is contained in:
commit
e1a617f742
@ -397,9 +397,15 @@ def populate_streams_on_account_create(sender, instance, created, *args, **kwarg
|
|||||||
"""build a user's feeds when they join"""
|
"""build a user's feeds when they join"""
|
||||||
if not created or not instance.local:
|
if not created or not instance.local:
|
||||||
return
|
return
|
||||||
|
transaction.on_commit(
|
||||||
|
lambda: populate_streams_on_account_create_command(instance.id)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def populate_streams_on_account_create_command(instance_id):
|
||||||
|
"""wait for the transaction to complete"""
|
||||||
for stream in streams:
|
for stream in streams:
|
||||||
populate_stream_task.delay(stream, instance.id)
|
populate_stream_task.delay(stream, instance_id)
|
||||||
|
|
||||||
|
|
||||||
@receiver(signals.pre_save, sender=models.ShelfBook)
|
@receiver(signals.pre_save, sender=models.ShelfBook)
|
||||||
|
251
bookwyrm/lists_stream.py
Normal file
251
bookwyrm/lists_stream.py
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
""" access the list streams stored in redis """
|
||||||
|
from django.dispatch import receiver
|
||||||
|
from django.db import transaction
|
||||||
|
from django.db.models import signals, Count, Q
|
||||||
|
|
||||||
|
from bookwyrm import models
|
||||||
|
from bookwyrm.redis_store import RedisStore
|
||||||
|
from bookwyrm.tasks import app, MEDIUM, HIGH
|
||||||
|
|
||||||
|
|
||||||
|
class ListsStream(RedisStore):
|
||||||
|
"""all the lists you can see"""
|
||||||
|
|
||||||
|
def stream_id(self, user): # pylint: disable=no-self-use
|
||||||
|
"""the redis key for this user's instance of this stream"""
|
||||||
|
if isinstance(user, int):
|
||||||
|
# allows the function to take an int or an obj
|
||||||
|
return f"{user}-lists"
|
||||||
|
return f"{user.id}-lists"
|
||||||
|
|
||||||
|
def get_rank(self, obj): # pylint: disable=no-self-use
|
||||||
|
"""lists are sorted by updated date"""
|
||||||
|
return obj.updated_date.timestamp()
|
||||||
|
|
||||||
|
def add_list(self, book_list):
|
||||||
|
"""add a list to users' feeds"""
|
||||||
|
# the pipeline contains all the add-to-stream activities
|
||||||
|
self.add_object_to_related_stores(book_list)
|
||||||
|
|
||||||
|
def add_user_lists(self, viewer, user):
|
||||||
|
"""add a user's lists to another user's feed"""
|
||||||
|
# only add the lists that the viewer should be able to see
|
||||||
|
lists = models.List.privacy_filter(viewer).filter(user=user)
|
||||||
|
self.bulk_add_objects_to_store(lists, self.stream_id(viewer))
|
||||||
|
|
||||||
|
def remove_user_lists(self, viewer, user, exclude_privacy=None):
|
||||||
|
"""remove a user's list from another user's feed"""
|
||||||
|
# remove all so that followers only lists are removed
|
||||||
|
lists = user.list_set
|
||||||
|
if exclude_privacy:
|
||||||
|
lists = lists.exclude(privacy=exclude_privacy)
|
||||||
|
self.bulk_remove_objects_from_store(lists.all(), self.stream_id(viewer))
|
||||||
|
|
||||||
|
def get_list_stream(self, user):
|
||||||
|
"""load the lists to be displayed"""
|
||||||
|
lists = self.get_store(self.stream_id(user))
|
||||||
|
return (
|
||||||
|
models.List.objects.filter(id__in=lists)
|
||||||
|
.annotate(item_count=Count("listitem", filter=Q(listitem__approved=True)))
|
||||||
|
# hide lists with no approved books
|
||||||
|
.filter(item_count__gt=0)
|
||||||
|
.select_related("user")
|
||||||
|
.prefetch_related("listitem_set")
|
||||||
|
.order_by("-updated_date")
|
||||||
|
.distinct()
|
||||||
|
)
|
||||||
|
|
||||||
|
def populate_lists(self, user):
|
||||||
|
"""go from zero to a timeline"""
|
||||||
|
self.populate_store(self.stream_id(user))
|
||||||
|
|
||||||
|
def get_audience(self, book_list): # pylint: disable=no-self-use
|
||||||
|
"""given a list, what users should see it"""
|
||||||
|
# everybody who could plausibly see this list
|
||||||
|
audience = models.User.objects.filter(
|
||||||
|
is_active=True,
|
||||||
|
local=True, # we only create feeds for users of this instance
|
||||||
|
).exclude( # not blocked
|
||||||
|
Q(id__in=book_list.user.blocks.all()) | Q(blocks=book_list.user)
|
||||||
|
)
|
||||||
|
|
||||||
|
group = book_list.group
|
||||||
|
# only visible to the poster and mentioned users
|
||||||
|
if book_list.privacy == "direct":
|
||||||
|
if group:
|
||||||
|
audience = audience.filter(
|
||||||
|
Q(id=book_list.user.id) # if the user is the post's author
|
||||||
|
| ~Q(groups=group.memberships) # if the user is in the group
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
audience = audience.filter(
|
||||||
|
Q(id=book_list.user.id) # if the user is the post's author
|
||||||
|
)
|
||||||
|
# only visible to the poster's followers and tagged users
|
||||||
|
elif book_list.privacy == "followers":
|
||||||
|
if group:
|
||||||
|
audience = audience.filter(
|
||||||
|
Q(id=book_list.user.id) # if the user is the list's owner
|
||||||
|
| Q(following=book_list.user) # if the user is following the pwmer
|
||||||
|
# if a user is in the group
|
||||||
|
| Q(memberships__group__id=book_list.group.id)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
audience = audience.filter(
|
||||||
|
Q(id=book_list.user.id) # if the user is the list's owner
|
||||||
|
| Q(following=book_list.user) # if the user is following the pwmer
|
||||||
|
)
|
||||||
|
return audience.distinct()
|
||||||
|
|
||||||
|
def get_stores_for_object(self, obj):
|
||||||
|
return [self.stream_id(u) for u in self.get_audience(obj)]
|
||||||
|
|
||||||
|
def get_lists_for_user(self, user): # pylint: disable=no-self-use
|
||||||
|
"""given a user, what lists should they see on this stream"""
|
||||||
|
return models.List.privacy_filter(
|
||||||
|
user,
|
||||||
|
privacy_levels=["public", "followers"],
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_objects_for_store(self, store):
|
||||||
|
user = models.User.objects.get(id=store.split("-")[0])
|
||||||
|
return self.get_lists_for_user(user)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(signals.post_save, sender=models.List)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def add_list_on_create(sender, instance, created, *args, **kwargs):
|
||||||
|
"""add newly created lists streamsstreams"""
|
||||||
|
if not created:
|
||||||
|
return
|
||||||
|
# when creating new things, gotta wait on the transaction
|
||||||
|
transaction.on_commit(lambda: add_list_on_create_command(instance.id))
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(signals.post_delete, sender=models.List)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def remove_list_on_delete(sender, instance, *args, **kwargs):
|
||||||
|
"""remove deleted lists to streams"""
|
||||||
|
remove_list_task.delay(instance.id)
|
||||||
|
|
||||||
|
|
||||||
|
def add_list_on_create_command(instance_id):
|
||||||
|
"""runs this code only after the database commit completes"""
|
||||||
|
add_list_task.delay(instance_id)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(signals.post_save, sender=models.UserFollows)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def add_lists_on_follow(sender, instance, created, *args, **kwargs):
|
||||||
|
"""add a newly followed user's lists to feeds"""
|
||||||
|
if not created or not instance.user_subject.local:
|
||||||
|
return
|
||||||
|
add_user_lists_task.delay(instance.user_subject.id, instance.user_object.id)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(signals.post_delete, sender=models.UserFollows)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def remove_lists_on_unfollow(sender, instance, *args, **kwargs):
|
||||||
|
"""remove lists from a feed on unfollow"""
|
||||||
|
if not instance.user_subject.local:
|
||||||
|
return
|
||||||
|
# remove all but public lists
|
||||||
|
remove_user_lists_task.delay(
|
||||||
|
instance.user_subject.id, instance.user_object.id, exclude_privacy="public"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(signals.post_save, sender=models.UserBlocks)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def remove_lists_on_block(sender, instance, *args, **kwargs):
|
||||||
|
"""remove lists from all feeds on block"""
|
||||||
|
# blocks apply ot all feeds
|
||||||
|
if instance.user_subject.local:
|
||||||
|
remove_user_lists_task.delay(instance.user_subject.id, instance.user_object.id)
|
||||||
|
|
||||||
|
# and in both directions
|
||||||
|
if instance.user_object.local:
|
||||||
|
remove_user_lists_task.delay(instance.user_object.id, instance.user_subject.id)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(signals.post_delete, sender=models.UserBlocks)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def add_lists_on_unblock(sender, instance, *args, **kwargs):
|
||||||
|
"""add lists back to all feeds on unblock"""
|
||||||
|
# make sure there isn't a block in the other direction
|
||||||
|
if models.UserBlocks.objects.filter(
|
||||||
|
user_subject=instance.user_object,
|
||||||
|
user_object=instance.user_subject,
|
||||||
|
).exists():
|
||||||
|
return
|
||||||
|
|
||||||
|
# add lists back to streams with lists from anyone
|
||||||
|
if instance.user_subject.local:
|
||||||
|
add_user_lists_task.delay(
|
||||||
|
instance.user_subject.id,
|
||||||
|
instance.user_object.id,
|
||||||
|
)
|
||||||
|
|
||||||
|
# add lists back to streams with lists from anyone
|
||||||
|
if instance.user_object.local:
|
||||||
|
add_user_lists_task.delay(
|
||||||
|
instance.user_object.id,
|
||||||
|
instance.user_subject.id,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(signals.post_save, sender=models.User)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def populate_lists_on_account_create(sender, instance, created, *args, **kwargs):
|
||||||
|
"""build a user's feeds when they join"""
|
||||||
|
if not created or not instance.local:
|
||||||
|
return
|
||||||
|
transaction.on_commit(lambda: add_list_on_account_create_command(instance.id))
|
||||||
|
|
||||||
|
|
||||||
|
def add_list_on_account_create_command(user_id):
|
||||||
|
"""wait for the transaction to complete"""
|
||||||
|
populate_lists_task.delay(user_id)
|
||||||
|
|
||||||
|
|
||||||
|
# ---- TASKS
|
||||||
|
@app.task(queue=MEDIUM)
|
||||||
|
def populate_lists_task(user_id):
|
||||||
|
"""background task for populating an empty list stream"""
|
||||||
|
user = models.User.objects.get(id=user_id)
|
||||||
|
ListsStream().populate_lists(user)
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(queue=MEDIUM)
|
||||||
|
def remove_list_task(list_id):
|
||||||
|
"""remove a list from any stream it might be in"""
|
||||||
|
stores = models.User.objects.filter(local=True, is_active=True).values_list(
|
||||||
|
"id", flat=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# delete for every store
|
||||||
|
stores = [ListsStream().stream_id(idx) for idx in stores]
|
||||||
|
ListsStream().remove_object_from_related_stores(list_id, stores=stores)
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(queue=HIGH)
|
||||||
|
def add_list_task(list_id):
|
||||||
|
"""add a list to any stream it should be in"""
|
||||||
|
book_list = models.List.objects.get(id=list_id)
|
||||||
|
ListsStream().add_list(book_list)
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(queue=MEDIUM)
|
||||||
|
def remove_user_lists_task(viewer_id, user_id, exclude_privacy=None):
|
||||||
|
"""remove all lists by a user from a viewer's stream"""
|
||||||
|
viewer = models.User.objects.get(id=viewer_id)
|
||||||
|
user = models.User.objects.get(id=user_id)
|
||||||
|
ListsStream().remove_user_lists(viewer, user, exclude_privacy=exclude_privacy)
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(queue=MEDIUM)
|
||||||
|
def add_user_lists_task(viewer_id, user_id):
|
||||||
|
"""add all lists by a user to a viewer's stream"""
|
||||||
|
viewer = models.User.objects.get(id=viewer_id)
|
||||||
|
user = models.User.objects.get(id=user_id)
|
||||||
|
ListsStream().add_user_lists(viewer, user)
|
34
bookwyrm/management/commands/populate_lists_streams.py
Normal file
34
bookwyrm/management/commands/populate_lists_streams.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
""" Re-create list streams """
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from bookwyrm import lists_stream, models
|
||||||
|
|
||||||
|
|
||||||
|
def populate_lists_streams():
|
||||||
|
"""build all the lists streams for all the users"""
|
||||||
|
print("Populating lists streams")
|
||||||
|
users = models.User.objects.filter(
|
||||||
|
local=True,
|
||||||
|
is_active=True,
|
||||||
|
).order_by("-last_active_date")
|
||||||
|
print("This may take a long time! Please be patient.")
|
||||||
|
for user in users:
|
||||||
|
print(".", end="")
|
||||||
|
lists_stream.populate_lists_task.delay(user.id)
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""start all over with lists streams"""
|
||||||
|
|
||||||
|
help = "Populate list streams for all users"
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument(
|
||||||
|
"--stream",
|
||||||
|
default=None,
|
||||||
|
help="Specifies which time of stream to populate",
|
||||||
|
)
|
||||||
|
|
||||||
|
# pylint: disable=no-self-use,unused-argument
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
"""run feed builder"""
|
||||||
|
populate_lists_streams()
|
@ -1,6 +1,6 @@
|
|||||||
""" Re-create user streams """
|
""" Re-create user streams """
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from bookwyrm import activitystreams, models
|
from bookwyrm import activitystreams, lists_stream, models
|
||||||
|
|
||||||
|
|
||||||
def populate_streams(stream=None):
|
def populate_streams(stream=None):
|
||||||
@ -13,6 +13,8 @@ def populate_streams(stream=None):
|
|||||||
).order_by("-last_active_date")
|
).order_by("-last_active_date")
|
||||||
print("This may take a long time! Please be patient.")
|
print("This may take a long time! Please be patient.")
|
||||||
for user in users:
|
for user in users:
|
||||||
|
print(".", end="")
|
||||||
|
lists_stream.populate_lists_task.delay(user.id)
|
||||||
for stream_key in streams:
|
for stream_key in streams:
|
||||||
print(".", end="")
|
print(".", end="")
|
||||||
activitystreams.populate_stream_task.delay(stream_key, user.id)
|
activitystreams.populate_stream_task.delay(stream_key, user.id)
|
||||||
|
@ -30,6 +30,7 @@ class RedisStore(ABC):
|
|||||||
# add the status to the feed
|
# add the status to the feed
|
||||||
pipeline.zadd(store, value)
|
pipeline.zadd(store, value)
|
||||||
# trim the store
|
# trim the store
|
||||||
|
if self.max_length:
|
||||||
pipeline.zremrangebyrank(store, 0, -1 * self.max_length)
|
pipeline.zremrangebyrank(store, 0, -1 * self.max_length)
|
||||||
if not execute:
|
if not execute:
|
||||||
return pipeline
|
return pipeline
|
||||||
@ -38,10 +39,15 @@ class RedisStore(ABC):
|
|||||||
|
|
||||||
def remove_object_from_related_stores(self, obj, stores=None):
|
def remove_object_from_related_stores(self, obj, stores=None):
|
||||||
"""remove an object from all stores"""
|
"""remove an object from all stores"""
|
||||||
|
# if the stoers are provided, the object can just be an id
|
||||||
|
if stores and isinstance(obj, int):
|
||||||
|
obj_id = obj
|
||||||
|
else:
|
||||||
|
obj_id = obj.id
|
||||||
stores = self.get_stores_for_object(obj) if stores is None else stores
|
stores = self.get_stores_for_object(obj) if stores is None else stores
|
||||||
pipeline = r.pipeline()
|
pipeline = r.pipeline()
|
||||||
for store in stores:
|
for store in stores:
|
||||||
pipeline.zrem(store, -1, obj.id)
|
pipeline.zrem(store, -1, obj_id)
|
||||||
pipeline.execute()
|
pipeline.execute()
|
||||||
|
|
||||||
def bulk_add_objects_to_store(self, objs, store):
|
def bulk_add_objects_to_store(self, objs, store):
|
||||||
@ -49,7 +55,7 @@ class RedisStore(ABC):
|
|||||||
pipeline = r.pipeline()
|
pipeline = r.pipeline()
|
||||||
for obj in objs[: self.max_length]:
|
for obj in objs[: self.max_length]:
|
||||||
pipeline.zadd(store, self.get_value(obj))
|
pipeline.zadd(store, self.get_value(obj))
|
||||||
if objs:
|
if objs and self.max_length:
|
||||||
pipeline.zremrangebyrank(store, 0, -1 * self.max_length)
|
pipeline.zremrangebyrank(store, 0, -1 * self.max_length)
|
||||||
pipeline.execute()
|
pipeline.execute()
|
||||||
|
|
||||||
@ -73,7 +79,7 @@ class RedisStore(ABC):
|
|||||||
pipeline.zadd(store, self.get_value(obj))
|
pipeline.zadd(store, self.get_value(obj))
|
||||||
|
|
||||||
# only trim the store if objects were added
|
# only trim the store if objects were added
|
||||||
if queryset.exists():
|
if queryset.exists() and self.max_length:
|
||||||
pipeline.zremrangebyrank(store, 0, -1 * self.max_length)
|
pipeline.zremrangebyrank(store, 0, -1 * self.max_length)
|
||||||
pipeline.execute()
|
pipeline.execute()
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
env = Env()
|
env = Env()
|
||||||
env.read_env()
|
env.read_env()
|
||||||
DOMAIN = env("DOMAIN")
|
DOMAIN = env("DOMAIN")
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.1"
|
||||||
|
|
||||||
PAGE_LENGTH = env("PAGE_LENGTH", 15)
|
PAGE_LENGTH = env("PAGE_LENGTH", 15)
|
||||||
DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English")
|
DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English")
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import math
|
import math
|
||||||
import logging
|
import logging
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
from django.db import transaction
|
||||||
from django.db.models import signals, Count, Q, Case, When, IntegerField
|
from django.db.models import signals, Count, Q, Case, When, IntegerField
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
@ -192,7 +193,7 @@ def update_user(sender, instance, created, update_fields=None, **kwargs):
|
|||||||
"""an updated user, neat"""
|
"""an updated user, neat"""
|
||||||
# a new user is found, create suggestions for them
|
# a new user is found, create suggestions for them
|
||||||
if created and instance.local:
|
if created and instance.local:
|
||||||
rerank_suggestions_task.delay(instance.id)
|
transaction.on_commit(lambda: update_new_user_command(instance.id))
|
||||||
|
|
||||||
# we know what fields were updated and discoverability didn't change
|
# we know what fields were updated and discoverability didn't change
|
||||||
if not instance.bookwyrm_user or (
|
if not instance.bookwyrm_user or (
|
||||||
@ -212,6 +213,11 @@ def update_user(sender, instance, created, update_fields=None, **kwargs):
|
|||||||
remove_user_task.delay(instance.id)
|
remove_user_task.delay(instance.id)
|
||||||
|
|
||||||
|
|
||||||
|
def update_new_user_command(instance_id):
|
||||||
|
"""wait for transaction to complete"""
|
||||||
|
rerank_suggestions_task.delay(instance_id)
|
||||||
|
|
||||||
|
|
||||||
@receiver(signals.post_save, sender=models.FederatedServer)
|
@receiver(signals.post_save, sender=models.FederatedServer)
|
||||||
def domain_level_update(sender, instance, created, update_fields=None, **kwargs):
|
def domain_level_update(sender, instance, created, update_fields=None, **kwargs):
|
||||||
"""remove users on a domain block"""
|
"""remove users on a domain block"""
|
||||||
|
@ -31,7 +31,7 @@ class BaseActivity(TestCase):
|
|||||||
"""we're probably going to re-use this so why copy/paste"""
|
"""we're probably going to re-use this so why copy/paste"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,7 @@ class Activitystreams(TestCase):
|
|||||||
"""use a test csv"""
|
"""use a test csv"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,7 @@ class Activitystreams(TestCase):
|
|||||||
"""use a test csv"""
|
"""use a test csv"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,7 @@ class Activitystreams(TestCase):
|
|||||||
"""use a test csv"""
|
"""use a test csv"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,7 @@ class Activitystreams(TestCase):
|
|||||||
"""use a test csv"""
|
"""use a test csv"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
|
@ -5,6 +5,8 @@ from bookwyrm import activitystreams, models
|
|||||||
|
|
||||||
|
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@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):
|
class ActivitystreamsSignals(TestCase):
|
||||||
"""using redis to build activity streams"""
|
"""using redis to build activity streams"""
|
||||||
|
|
||||||
@ -12,7 +14,7 @@ class ActivitystreamsSignals(TestCase):
|
|||||||
"""use a test csv"""
|
"""use a test csv"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
@ -32,11 +34,11 @@ class ActivitystreamsSignals(TestCase):
|
|||||||
work = models.Work.objects.create(title="test work")
|
work = models.Work.objects.create(title="test work")
|
||||||
self.book = models.Edition.objects.create(title="test book", parent_work=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"""
|
"""a new statuses has entered"""
|
||||||
activitystreams.add_status_on_create(models.User, self.local_user, False)
|
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"""
|
"""a new statuses has entered"""
|
||||||
with patch("bookwyrm.activitystreams.remove_status_task.delay"):
|
with patch("bookwyrm.activitystreams.remove_status_task.delay"):
|
||||||
status = models.Status.objects.create(
|
status = models.Status.objects.create(
|
||||||
@ -48,7 +50,7 @@ class ActivitystreamsSignals(TestCase):
|
|||||||
args = mock.call_args[0]
|
args = mock.call_args[0]
|
||||||
self.assertEqual(args[0], status.id)
|
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"""
|
"""a new statuses has entered"""
|
||||||
status = models.Status.objects.create(
|
status = models.Status.objects.create(
|
||||||
user=self.remote_user, content="hi", privacy="public"
|
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["args"][0], status.id)
|
||||||
self.assertEqual(args["queue"], "high_priority")
|
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"""
|
"""create streams for a user"""
|
||||||
with patch("bookwyrm.activitystreams.populate_stream_task.delay") as mock:
|
with patch("bookwyrm.activitystreams.populate_stream_task.delay") as mock:
|
||||||
activitystreams.populate_streams_on_account_create(
|
activitystreams.populate_streams_on_account_create_command(
|
||||||
models.User, self.local_user, True
|
self.local_user.id
|
||||||
)
|
)
|
||||||
self.assertEqual(mock.call_count, 3)
|
self.assertEqual(mock.call_count, 3)
|
||||||
args = mock.call_args[0]
|
args = mock.call_args[0]
|
||||||
self.assertEqual(args[0], "books")
|
self.assertEqual(args[0], "books")
|
||||||
self.assertEqual(args[1], self.local_user.id)
|
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"""
|
"""don't show statuses from blocked users"""
|
||||||
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") as mock:
|
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay") as mock:
|
||||||
models.UserBlocks.objects.create(
|
models.UserBlocks.objects.create(
|
||||||
@ -83,7 +85,7 @@ class ActivitystreamsSignals(TestCase):
|
|||||||
self.assertEqual(args[0], self.local_user.id)
|
self.assertEqual(args[0], self.local_user.id)
|
||||||
self.assertEqual(args[1], self.remote_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"""
|
"""re-add statuses on unblock"""
|
||||||
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"):
|
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"):
|
||||||
block = models.UserBlocks.objects.create(
|
block = models.UserBlocks.objects.create(
|
||||||
@ -100,7 +102,7 @@ class ActivitystreamsSignals(TestCase):
|
|||||||
self.assertEqual(args[1], self.remote_user.id)
|
self.assertEqual(args[1], self.remote_user.id)
|
||||||
self.assertEqual(kwargs["stream_list"], ["local", "books"])
|
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"""
|
"""re-add statuses on unblock"""
|
||||||
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"):
|
with patch("bookwyrm.activitystreams.remove_user_statuses_task.delay"):
|
||||||
block = models.UserBlocks.objects.create(
|
block = models.UserBlocks.objects.create(
|
||||||
|
@ -11,7 +11,7 @@ class Activitystreams(TestCase):
|
|||||||
"""use a test csv"""
|
"""use a test csv"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
|
@ -30,7 +30,7 @@ class GoodreadsImport(TestCase):
|
|||||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||||
)
|
)
|
||||||
|
@ -33,7 +33,7 @@ class GenericImporter(TestCase):
|
|||||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||||
)
|
)
|
||||||
|
@ -32,7 +32,7 @@ class LibrarythingImport(TestCase):
|
|||||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mmai", "mmai@mmai.mmai", "password", local=True
|
"mmai", "mmai@mmai.mmai", "password", local=True
|
||||||
)
|
)
|
||||||
|
@ -30,7 +30,7 @@ class OpenLibraryImport(TestCase):
|
|||||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||||
)
|
)
|
||||||
|
@ -30,7 +30,7 @@ class StorygraphImport(TestCase):
|
|||||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||||
)
|
)
|
||||||
|
1
bookwyrm/tests/lists_stream/__init__.py
Normal file
1
bookwyrm/tests/lists_stream/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from . import *
|
109
bookwyrm/tests/lists_stream/test_signals.py
Normal file
109
bookwyrm/tests/lists_stream/test_signals.py
Normal 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)
|
171
bookwyrm/tests/lists_stream/test_stream.py
Normal file
171
bookwyrm/tests/lists_stream/test_stream.py
Normal 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)
|
109
bookwyrm/tests/lists_stream/test_tasks.py
Normal file
109
bookwyrm/tests/lists_stream/test_tasks.py
Normal 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)
|
54
bookwyrm/tests/management/test_populate_lists_streams.py
Normal file
54
bookwyrm/tests/management/test_populate_lists_streams.py
Normal 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
|
@ -14,7 +14,7 @@ class Activitystreams(TestCase):
|
|||||||
"""we need some stuff"""
|
"""we need some stuff"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
@ -25,6 +25,14 @@ class Activitystreams(TestCase):
|
|||||||
local=True,
|
local=True,
|
||||||
localname="nutria",
|
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"):
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
self.remote_user = models.User.objects.create_user(
|
self.remote_user = models.User.objects.create_user(
|
||||||
"rat",
|
"rat",
|
||||||
@ -44,6 +52,11 @@ class Activitystreams(TestCase):
|
|||||||
user=self.local_user, content="hi", book=self.book
|
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()
|
populate_streams()
|
||||||
self.assertEqual(redis_mock.call_count, 6) # 2 users x 3 streams
|
self.assertEqual(redis_mock.call_count, 6) # 2 users x 3 streams
|
||||||
|
self.assertEqual(list_mock.call_count, 2) # 2 users
|
||||||
|
@ -29,7 +29,7 @@ class ActivitypubMixins(TestCase):
|
|||||||
"""shared data"""
|
"""shared data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
"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["id"], "https://example.com/status/1/activity")
|
||||||
self.assertEqual(activity["actor"], self.local_user.remote_id)
|
self.assertEqual(activity["actor"], self.local_user.remote_id)
|
||||||
self.assertEqual(activity["type"], "Delete")
|
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(
|
self.assertEqual(
|
||||||
activity["cc"], ["https://www.w3.org/ns/activitystreams#Public"]
|
activity["cc"], ["https://www.w3.org/ns/activitystreams#Public"]
|
||||||
)
|
)
|
||||||
@ -374,7 +374,7 @@ class ActivitypubMixins(TestCase):
|
|||||||
for number in range(0, 2 * PAGE_LENGTH):
|
for number in range(0, 2 * PAGE_LENGTH):
|
||||||
models.Status.objects.create(
|
models.Status.objects.create(
|
||||||
user=self.local_user,
|
user=self.local_user,
|
||||||
content="test status {:d}".format(number),
|
content=f"test status {number}",
|
||||||
)
|
)
|
||||||
page_1 = to_ordered_collection_page(
|
page_1 = to_ordered_collection_page(
|
||||||
models.Status.objects.all(), "http://fish.com/", page=1
|
models.Status.objects.all(), "http://fish.com/", page=1
|
||||||
@ -400,7 +400,7 @@ class ActivitypubMixins(TestCase):
|
|||||||
for number in range(0, 2 * PAGE_LENGTH):
|
for number in range(0, 2 * PAGE_LENGTH):
|
||||||
models.Status.objects.create(
|
models.Status.objects.create(
|
||||||
user=self.local_user,
|
user=self.local_user,
|
||||||
content="test status {:d}".format(number),
|
content=f"test status {number}",
|
||||||
)
|
)
|
||||||
|
|
||||||
MockSelf = namedtuple("Self", ("remote_id"))
|
MockSelf = namedtuple("Self", ("remote_id"))
|
||||||
|
@ -16,7 +16,7 @@ class BaseModel(TestCase):
|
|||||||
"""shared data"""
|
"""shared data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
|
@ -27,6 +27,7 @@ from bookwyrm.settings import DOMAIN
|
|||||||
# pylint: disable=too-many-public-methods
|
# pylint: disable=too-many-public-methods
|
||||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||||
|
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
|
||||||
class ModelFields(TestCase):
|
class ModelFields(TestCase):
|
||||||
"""overwrites standard model feilds to work with activitypub"""
|
"""overwrites standard model feilds to work with activitypub"""
|
||||||
|
|
||||||
|
@ -14,21 +14,15 @@ class Group(TestCase):
|
|||||||
|
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.owner_user = models.User.objects.create_user(
|
self.owner_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
"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(
|
self.rat = models.User.objects.create_user(
|
||||||
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
"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(
|
self.badger = models.User.objects.create_user(
|
||||||
"badger",
|
"badger",
|
||||||
"badger@badger.badger",
|
"badger@badger.badger",
|
||||||
@ -37,9 +31,6 @@ class Group(TestCase):
|
|||||||
localname="badger",
|
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(
|
self.capybara = models.User.objects.create_user(
|
||||||
"capybara",
|
"capybara",
|
||||||
"capybara@capybara.capybara",
|
"capybara@capybara.capybara",
|
||||||
|
@ -20,7 +20,7 @@ class ImportJob(TestCase):
|
|||||||
"""data is from a goodreads export of The Raven Tower"""
|
"""data is from a goodreads export of The Raven Tower"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True
|
"mouse", "mouse@mouse.mouse", "password", local=True
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
""" testing models """
|
""" testing models """
|
||||||
|
from uuid import UUID
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
from bookwyrm import models, settings
|
from bookwyrm import models, settings
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ class List(TestCase):
|
|||||||
"""look, a list"""
|
"""look, a list"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
@ -27,7 +27,7 @@ class List(TestCase):
|
|||||||
book_list = models.List.objects.create(
|
book_list = models.List.objects.create(
|
||||||
name="Test List", user=self.local_user
|
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)
|
self.assertEqual(book_list.get_remote_id(), expected_id)
|
||||||
|
|
||||||
def test_to_activity(self, _):
|
def test_to_activity(self, _):
|
||||||
|
@ -15,7 +15,7 @@ class ReadThrough(TestCase):
|
|||||||
"""look, a shelf"""
|
"""look, a shelf"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
""" testing models """
|
""" testing models """
|
||||||
import json
|
import json
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
from django.db import IntegrityError
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
|
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
@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):
|
class Relationship(TestCase):
|
||||||
"""following, blocking, stuff like that"""
|
"""following, blocking, stuff like that"""
|
||||||
|
|
||||||
@ -24,14 +28,39 @@ class Relationship(TestCase):
|
|||||||
)
|
)
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
self.local_user.remote_id = "http://local.com/user/mouse"
|
self.local_user.remote_id = "http://local.com/user/mouse"
|
||||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
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"""
|
"""convert a follow request into a follow"""
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||||
@ -42,19 +71,19 @@ class Relationship(TestCase):
|
|||||||
activity = json.loads(mock.call_args[1]["args"][1])
|
activity = json.loads(mock.call_args[1]["args"][1])
|
||||||
self.assertEqual(activity["type"], "Follow")
|
self.assertEqual(activity["type"], "Follow")
|
||||||
self.assertEqual(
|
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")
|
self.assertEqual(request.status, "follow_request")
|
||||||
|
|
||||||
rel = models.UserFollows.from_request(request)
|
rel = models.UserFollows.from_request(request)
|
||||||
self.assertEqual(
|
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.status, "follows")
|
||||||
self.assertEqual(rel.user_subject, self.local_user)
|
self.assertEqual(rel.user_subject, self.local_user)
|
||||||
self.assertEqual(rel.user_object, self.remote_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"""
|
"""store a specific remote id for a relationship provided by remote"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||||
request = models.UserFollowRequest.objects.create(
|
request = models.UserFollowRequest.objects.create(
|
||||||
@ -72,7 +101,7 @@ class Relationship(TestCase):
|
|||||||
self.assertEqual(rel.user_object, self.remote_user)
|
self.assertEqual(rel.user_object, self.remote_user)
|
||||||
|
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@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"""
|
"""accept a request and make it a relationship"""
|
||||||
models.UserFollowRequest.objects.create(
|
models.UserFollowRequest.objects.create(
|
||||||
user_subject=self.local_user,
|
user_subject=self.local_user,
|
||||||
@ -84,7 +113,7 @@ class Relationship(TestCase):
|
|||||||
self.assertEqual(activity["type"], "Follow")
|
self.assertEqual(activity["type"], "Follow")
|
||||||
|
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@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"""
|
"""accept a request and make it a relationship"""
|
||||||
self.local_user.manually_approves_followers = True
|
self.local_user.manually_approves_followers = True
|
||||||
self.local_user.save(
|
self.local_user.save(
|
||||||
@ -110,7 +139,7 @@ class Relationship(TestCase):
|
|||||||
self.assertEqual(rel.user_object, self.local_user)
|
self.assertEqual(rel.user_object, self.local_user)
|
||||||
|
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@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"""
|
"""accept a request and make it a relationship"""
|
||||||
self.local_user.manually_approves_followers = True
|
self.local_user.manually_approves_followers = True
|
||||||
self.local_user.save(
|
self.local_user.save(
|
||||||
|
@ -9,6 +9,7 @@ from bookwyrm import models, settings
|
|||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.populate_stream_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.add_book_statuses_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
|
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
|
||||||
class Shelf(TestCase):
|
class Shelf(TestCase):
|
||||||
@ -18,7 +19,7 @@ class Shelf(TestCase):
|
|||||||
"""look, a shelf"""
|
"""look, a shelf"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
@ -31,7 +32,7 @@ class Shelf(TestCase):
|
|||||||
shelf = models.Shelf.objects.create(
|
shelf = models.Shelf.objects.create(
|
||||||
name="Test Shelf", identifier="test-shelf", user=self.local_user
|
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)
|
self.assertEqual(shelf.get_remote_id(), expected_id)
|
||||||
|
|
||||||
def test_to_activity(self, *_):
|
def test_to_activity(self, *_):
|
||||||
|
@ -16,7 +16,7 @@ class SiteModels(TestCase):
|
|||||||
"""we need basic test data and mocks"""
|
"""we need basic test data and mocks"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -28,7 +28,7 @@ class Status(TestCase):
|
|||||||
"""useful things for creating a status"""
|
"""useful things for creating a status"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||||
)
|
)
|
||||||
|
@ -15,7 +15,7 @@ class User(TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
"mouse@%s" % DOMAIN,
|
"mouse@%s" % DOMAIN,
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -16,7 +16,7 @@ class BookWyrmTags(TestCase):
|
|||||||
"""create some filler objects"""
|
"""create some filler objects"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -16,7 +16,7 @@ class InteractionTags(TestCase):
|
|||||||
"""create some filler objects"""
|
"""create some filler objects"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -17,7 +17,7 @@ class StatusDisplayTags(TestCase):
|
|||||||
"""create some filler objects"""
|
"""create some filler objects"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -17,7 +17,7 @@ class UtilitiesTags(TestCase):
|
|||||||
"""create some filler objects"""
|
"""create some filler objects"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
@ -50,3 +50,10 @@ class UtilitiesTags(TestCase):
|
|||||||
"""uuid functionality"""
|
"""uuid functionality"""
|
||||||
uuid = utilities.get_uuid("hi")
|
uuid = utilities.get_uuid("hi")
|
||||||
self.assertTrue(re.match(r"hi[A-Za-z0-9\-]", uuid))
|
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")
|
||||||
|
@ -16,7 +16,7 @@ class Emailing(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -32,7 +32,7 @@ class PreviewImages(TestCase):
|
|||||||
)
|
)
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"possum@local.com",
|
"possum@local.com",
|
||||||
"possum@possum.possum",
|
"possum@possum.possum",
|
||||||
|
@ -39,19 +39,19 @@ class Signature(TestCase):
|
|||||||
"""create users and test data"""
|
"""create users and test data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.mouse = models.User.objects.create_user(
|
self.mouse = models.User.objects.create_user(
|
||||||
"mouse@%s" % DOMAIN,
|
f"mouse@{DOMAIN}",
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"",
|
"",
|
||||||
local=True,
|
local=True,
|
||||||
localname="mouse",
|
localname="mouse",
|
||||||
)
|
)
|
||||||
self.rat = models.User.objects.create_user(
|
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(
|
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()
|
private_key, public_key = create_key_pair()
|
||||||
@ -75,7 +75,7 @@ class Signature(TestCase):
|
|||||||
"HTTP_DIGEST": digest,
|
"HTTP_DIGEST": digest,
|
||||||
"HTTP_CONTENT_TYPE": "application/activity+json; charset=utf-8",
|
"HTTP_CONTENT_TYPE": "application/activity+json; charset=utf-8",
|
||||||
"HTTP_HOST": DOMAIN,
|
"HTTP_HOST": DOMAIN,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def send_test_request( # pylint: disable=too-many-arguments
|
def send_test_request( # pylint: disable=too-many-arguments
|
||||||
|
@ -13,6 +13,7 @@ from bookwyrm.suggested_users import suggested_users, get_annotated_users
|
|||||||
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
||||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.populate_stream_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.add_book_statuses_task.delay")
|
||||||
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
|
||||||
@patch("bookwyrm.suggested_users.remove_user_task.delay")
|
@patch("bookwyrm.suggested_users.remove_user_task.delay")
|
||||||
@ -23,7 +24,7 @@ class SuggestedUsers(TestCase):
|
|||||||
"""use a test csv"""
|
"""use a test csv"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse"
|
"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)
|
user_1_annotated = result.get(id=user_1.id)
|
||||||
self.assertEqual(user_1_annotated.mutuals, 3)
|
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)
|
|
||||||
|
@ -16,7 +16,7 @@ class AnnouncementViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -16,7 +16,7 @@ class DashboardViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -17,7 +17,7 @@ class EmailBlocklistViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -19,7 +19,7 @@ class FederationViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -16,7 +16,7 @@ class IPBlocklistViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -18,7 +18,7 @@ class ReportViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -18,7 +18,7 @@ class UserAdminViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -28,7 +28,7 @@ class BookViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -21,7 +21,7 @@ class EditBookViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -18,7 +18,7 @@ class BookViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -19,7 +19,7 @@ class ImportViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -16,7 +16,7 @@ class ImportManualReviewViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -16,7 +16,7 @@ class ImportTroubleshootViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -22,7 +22,7 @@ class Inbox(TestCase):
|
|||||||
|
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
local_user = models.User.objects.create_user(
|
local_user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -15,7 +15,7 @@ class InboxAdd(TestCase):
|
|||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
local_user = models.User.objects.create_user(
|
local_user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -15,7 +15,7 @@ class InboxActivities(TestCase):
|
|||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -14,7 +14,7 @@ class InboxBlock(TestCase):
|
|||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
@ -57,7 +57,7 @@ class InboxBlock(TestCase):
|
|||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.activitystreams.remove_user_statuses_task.delay"
|
"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)
|
views.inbox.activity_task(activity)
|
||||||
self.assertTrue(redis_mock.called)
|
self.assertTrue(redis_mock.called)
|
||||||
views.inbox.activity_task(activity)
|
views.inbox.activity_task(activity)
|
||||||
@ -70,7 +70,9 @@ class InboxBlock(TestCase):
|
|||||||
self.assertFalse(models.UserFollowRequest.objects.exists())
|
self.assertFalse(models.UserFollowRequest.objects.exists())
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
|
@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"""
|
"""unblock a user"""
|
||||||
self.remote_user.blocks.add(self.local_user)
|
self.remote_user.blocks.add(self.local_user)
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class InboxCreate(TestCase):
|
|||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -15,7 +15,7 @@ class InboxActivities(TestCase):
|
|||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
@ -51,7 +51,7 @@ class InboxActivities(TestCase):
|
|||||||
"type": "Delete",
|
"type": "Delete",
|
||||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
"cc": ["https://example.com/user/mouse/followers"],
|
"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,
|
"actor": self.remote_user.remote_id,
|
||||||
"object": {"id": self.status.remote_id, "type": "Tombstone"},
|
"object": {"id": self.status.remote_id, "type": "Tombstone"},
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ class InboxActivities(TestCase):
|
|||||||
"type": "Delete",
|
"type": "Delete",
|
||||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
"cc": ["https://example.com/user/mouse/followers"],
|
"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,
|
"actor": self.remote_user.remote_id,
|
||||||
"object": {"id": self.status.remote_id, "type": "Tombstone"},
|
"object": {"id": self.status.remote_id, "type": "Tombstone"},
|
||||||
}
|
}
|
||||||
@ -152,5 +152,7 @@ class InboxActivities(TestCase):
|
|||||||
"cc": [],
|
"cc": [],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
with patch("bookwyrm.lists_stream.remove_list_task.delay") as mock:
|
||||||
views.inbox.activity_task(activity)
|
views.inbox.activity_task(activity)
|
||||||
|
self.assertTrue(mock.called)
|
||||||
self.assertFalse(models.List.objects.exists())
|
self.assertFalse(models.List.objects.exists())
|
||||||
|
@ -15,7 +15,7 @@ class InboxRelationships(TestCase):
|
|||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
@ -188,7 +188,8 @@ class InboxRelationships(TestCase):
|
|||||||
self.assertIsNone(self.local_user.followers.first())
|
self.assertIsNone(self.local_user.followers.first())
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
@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"""
|
"""a remote user approved a follow request from local"""
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||||
rel = models.UserFollowRequest.objects.create(
|
rel = models.UserFollowRequest.objects.create(
|
||||||
|
@ -14,7 +14,7 @@ class InboxActivities(TestCase):
|
|||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -14,7 +14,7 @@ class InboxRemove(TestCase):
|
|||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -16,7 +16,7 @@ class InboxUpdate(TestCase):
|
|||||||
"""basic user and book data"""
|
"""basic user and book data"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@example.com",
|
"mouse@example.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
@ -78,6 +78,7 @@ class InboxUpdate(TestCase):
|
|||||||
|
|
||||||
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
||||||
|
@patch("bookwyrm.lists_stream.add_user_lists_task.delay")
|
||||||
def test_update_user(self, *_):
|
def test_update_user(self, *_):
|
||||||
"""update an existing user"""
|
"""update an existing user"""
|
||||||
models.UserFollows.objects.create(
|
models.UserFollows.objects.create(
|
||||||
|
@ -19,7 +19,7 @@ class InviteViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -18,7 +18,7 @@ class LandingViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -21,7 +21,7 @@ class LoginViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@your.domain.here",
|
"mouse@your.domain.here",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -21,7 +21,7 @@ class PasswordViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -16,6 +16,7 @@ from bookwyrm.tests.validate_html import validate_html
|
|||||||
# pylint: disable=too-many-public-methods
|
# pylint: disable=too-many-public-methods
|
||||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
|
||||||
|
@patch("bookwyrm.lists_stream.populate_lists_task.delay")
|
||||||
class RegisterViews(TestCase):
|
class RegisterViews(TestCase):
|
||||||
"""login and password management"""
|
"""login and password management"""
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ class RegisterViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@your.domain.here",
|
"mouse@your.domain.here",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -18,7 +18,7 @@ class BlockViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
@ -61,7 +61,9 @@ class BlockViews(TestCase):
|
|||||||
|
|
||||||
request = self.factory.post("")
|
request = self.factory.post("")
|
||||||
request.user = self.local_user
|
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)
|
view(request, self.remote_user.id)
|
||||||
block = models.UserBlocks.objects.get()
|
block = models.UserBlocks.objects.get()
|
||||||
self.assertEqual(block.user_subject, self.local_user)
|
self.assertEqual(block.user_subject, self.local_user)
|
||||||
@ -76,7 +78,9 @@ class BlockViews(TestCase):
|
|||||||
request = self.factory.post("")
|
request = self.factory.post("")
|
||||||
request.user = self.local_user
|
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)
|
views.unblock(request, self.remote_user.id)
|
||||||
|
|
||||||
self.assertFalse(models.UserBlocks.objects.exists())
|
self.assertFalse(models.UserBlocks.objects.exists())
|
||||||
|
@ -17,7 +17,7 @@ class ChangePasswordViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -20,7 +20,7 @@ class DeleteUserViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -23,7 +23,7 @@ class EditUserViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -14,6 +14,7 @@ from bookwyrm.tests.validate_html import validate_html
|
|||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.populate_stream_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.add_book_statuses_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
|
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
|
||||||
class ShelfViews(TestCase):
|
class ShelfViews(TestCase):
|
||||||
@ -24,7 +25,7 @@ class ShelfViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -12,6 +12,7 @@ from bookwyrm import forms, models, views
|
|||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.populate_stream_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.add_book_statuses_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
|
@patch("bookwyrm.activitystreams.remove_book_statuses_task.delay")
|
||||||
class ShelfActionViews(TestCase):
|
class ShelfActionViews(TestCase):
|
||||||
@ -22,7 +23,7 @@ class ShelfActionViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
@ -178,7 +179,7 @@ class ShelfActionViews(TestCase):
|
|||||||
"""delete a brand new custom shelf"""
|
"""delete a brand new custom shelf"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
rat = models.User.objects.create_user(
|
rat = models.User.objects.create_user(
|
||||||
"rat@local.com",
|
"rat@local.com",
|
||||||
"rat@mouse.mouse",
|
"rat@mouse.mouse",
|
||||||
|
@ -26,7 +26,7 @@ class AnnualSummary(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -21,7 +21,7 @@ class AuthorViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -18,7 +18,7 @@ class DirectoryViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
@ -34,6 +34,7 @@ class DirectoryViews(TestCase):
|
|||||||
|
|
||||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.populate_stream_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")
|
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
|
||||||
def test_directory_page(self, *_):
|
def test_directory_page(self, *_):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
@ -16,7 +16,7 @@ class DiscoverViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -10,8 +10,7 @@ from django.template.response import TemplateResponse
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import forms, models, views
|
||||||
from bookwyrm import views
|
|
||||||
from bookwyrm.activitypub import ActivitypubResponse
|
from bookwyrm.activitypub import ActivitypubResponse
|
||||||
from bookwyrm.tests.validate_html import validate_html
|
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.activitystreams.add_status_task.delay")
|
||||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.populate_stream_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")
|
@patch("bookwyrm.suggested_users.remove_user_task.delay")
|
||||||
class FeedViews(TestCase):
|
class FeedViews(TestCase):
|
||||||
"""activity feed, statuses, dms"""
|
"""activity feed, statuses, dms"""
|
||||||
@ -29,7 +29,7 @@ class FeedViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
@ -62,6 +62,25 @@ class FeedViews(TestCase):
|
|||||||
validate_html(result.render())
|
validate_html(result.render())
|
||||||
self.assertEqual(result.status_code, 200)
|
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, *_):
|
def test_status_page(self, *_):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
view = views.Status.as_view()
|
view = views.Status.as_view()
|
||||||
|
@ -13,6 +13,7 @@ from bookwyrm.tests.validate_html import validate_html
|
|||||||
|
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
@patch("bookwyrm.activitystreams.add_user_statuses_task.delay")
|
||||||
|
@patch("bookwyrm.lists_stream.add_user_lists_task.delay")
|
||||||
class FollowViews(TestCase):
|
class FollowViews(TestCase):
|
||||||
"""follows"""
|
"""follows"""
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ class FollowViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
@ -56,7 +57,7 @@ class FollowViews(TestCase):
|
|||||||
parent_work=self.work,
|
parent_work=self.work,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_handle_follow_remote(self, _):
|
def test_handle_follow_remote(self, *_):
|
||||||
"""send a follow request"""
|
"""send a follow request"""
|
||||||
request = self.factory.post("", {"user": self.remote_user.username})
|
request = self.factory.post("", {"user": self.remote_user.username})
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
@ -71,11 +72,11 @@ class FollowViews(TestCase):
|
|||||||
self.assertEqual(rel.user_object, self.remote_user)
|
self.assertEqual(rel.user_object, self.remote_user)
|
||||||
self.assertEqual(rel.status, "follow_request")
|
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"""
|
"""send a follow request"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
rat = models.User.objects.create_user(
|
rat = models.User.objects.create_user(
|
||||||
"rat@local.com",
|
"rat@local.com",
|
||||||
"rat@rat.com",
|
"rat@rat.com",
|
||||||
@ -97,11 +98,11 @@ class FollowViews(TestCase):
|
|||||||
self.assertEqual(rel.user_object, rat)
|
self.assertEqual(rel.user_object, rat)
|
||||||
self.assertEqual(rel.status, "follow_request")
|
self.assertEqual(rel.status, "follow_request")
|
||||||
|
|
||||||
def test_handle_follow_local(self, _):
|
def test_handle_follow_local(self, *_):
|
||||||
"""send a follow request"""
|
"""send a follow request"""
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
rat = models.User.objects.create_user(
|
rat = models.User.objects.create_user(
|
||||||
"rat@local.com",
|
"rat@local.com",
|
||||||
"rat@rat.com",
|
"rat@rat.com",
|
||||||
@ -124,6 +125,7 @@ class FollowViews(TestCase):
|
|||||||
self.assertEqual(rel.status, "follows")
|
self.assertEqual(rel.status, "follows")
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
|
@patch("bookwyrm.activitystreams.remove_user_statuses_task.delay")
|
||||||
|
@patch("bookwyrm.lists_stream.remove_user_lists_task.delay")
|
||||||
def test_handle_unfollow(self, *_):
|
def test_handle_unfollow(self, *_):
|
||||||
"""send an unfollow"""
|
"""send an unfollow"""
|
||||||
request = self.factory.post("", {"user": self.remote_user.username})
|
request = self.factory.post("", {"user": self.remote_user.username})
|
||||||
@ -140,7 +142,7 @@ class FollowViews(TestCase):
|
|||||||
|
|
||||||
self.assertEqual(self.remote_user.followers.count(), 0)
|
self.assertEqual(self.remote_user.followers.count(), 0)
|
||||||
|
|
||||||
def test_handle_accept(self, _):
|
def test_handle_accept(self, *_):
|
||||||
"""accept a follow request"""
|
"""accept a follow request"""
|
||||||
self.local_user.manually_approves_followers = True
|
self.local_user.manually_approves_followers = True
|
||||||
self.local_user.save(
|
self.local_user.save(
|
||||||
@ -159,7 +161,7 @@ class FollowViews(TestCase):
|
|||||||
# follow relationship should exist
|
# follow relationship should exist
|
||||||
self.assertEqual(self.local_user.followers.first(), self.remote_user)
|
self.assertEqual(self.local_user.followers.first(), self.remote_user)
|
||||||
|
|
||||||
def test_handle_reject(self, _):
|
def test_handle_reject(self, *_):
|
||||||
"""reject a follow request"""
|
"""reject a follow request"""
|
||||||
self.local_user.manually_approves_followers = True
|
self.local_user.manually_approves_followers = True
|
||||||
self.local_user.save(
|
self.local_user.save(
|
||||||
@ -178,7 +180,7 @@ class FollowViews(TestCase):
|
|||||||
# follow relationship should not exist
|
# follow relationship should not exist
|
||||||
self.assertEqual(models.UserFollows.objects.filter(id=rel.id).count(), 0)
|
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"""
|
"""check ostatus subscribe template loads"""
|
||||||
request = self.factory.get(
|
request = self.factory.get(
|
||||||
"", {"acct": "https%3A%2F%2Fexample.com%2Fusers%2Frat"}
|
"", {"acct": "https%3A%2F%2Fexample.com%2Fusers%2Frat"}
|
||||||
@ -189,7 +191,7 @@ class FollowViews(TestCase):
|
|||||||
validate_html(result.render())
|
validate_html(result.render())
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
def test_remote_follow_page(self, _):
|
def test_remote_follow_page(self, *_):
|
||||||
"""check remote follow page loads"""
|
"""check remote follow page loads"""
|
||||||
request = self.factory.get("", {"acct": "mouse@local.com"})
|
request = self.factory.get("", {"acct": "mouse@local.com"})
|
||||||
request.user = self.remote_user
|
request.user = self.remote_user
|
||||||
@ -198,7 +200,7 @@ class FollowViews(TestCase):
|
|||||||
validate_html(result.render())
|
validate_html(result.render())
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
def test_ostatus_follow_success(self, _):
|
def test_ostatus_follow_success(self, *_):
|
||||||
"""check remote follow success page loads"""
|
"""check remote follow success page loads"""
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
request.user = self.remote_user
|
request.user = self.remote_user
|
||||||
@ -208,7 +210,7 @@ class FollowViews(TestCase):
|
|||||||
validate_html(result.render())
|
validate_html(result.render())
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
def test_remote_follow(self, _):
|
def test_remote_follow(self, *_):
|
||||||
"""check follow from remote page loads"""
|
"""check follow from remote page loads"""
|
||||||
request = self.factory.post("", {"user": self.remote_user.id})
|
request = self.factory.post("", {"user": self.remote_user.id})
|
||||||
request.user = self.remote_user
|
request.user = self.remote_user
|
||||||
|
@ -17,7 +17,7 @@ class GetStartedViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -20,7 +20,7 @@ class GoalViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -20,7 +20,7 @@ class GroupViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -23,7 +23,7 @@ class ViewsHelpers(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
with patch("bookwyrm.suggested_users.rerank_user_task.delay"):
|
with patch("bookwyrm.suggested_users.rerank_user_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
|
@ -17,7 +17,7 @@ class InteractionViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -18,7 +18,7 @@ class IsbnViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
@ -49,3 +49,13 @@ class IsbnViews(TestCase):
|
|||||||
self.assertEqual(len(data), 1)
|
self.assertEqual(len(data), 1)
|
||||||
self.assertEqual(data[0]["title"], "Test Book")
|
self.assertEqual(data[0]["title"], "Test Book")
|
||||||
self.assertEqual(data[0]["key"], f"https://{DOMAIN}/book/{self.book.id}")
|
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()
|
||||||
|
@ -21,7 +21,7 @@ class ListViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
@ -72,10 +72,13 @@ class ListViews(TestCase):
|
|||||||
|
|
||||||
models.SiteSettings.objects.create()
|
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"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
view = views.Lists.as_view()
|
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="Public list", user=self.local_user)
|
||||||
models.List.objects.create(
|
models.List.objects.create(
|
||||||
name="Private list", privacy="direct", user=self.local_user
|
name="Private list", privacy="direct", user=self.local_user
|
||||||
@ -346,16 +349,16 @@ class ListViews(TestCase):
|
|||||||
def test_curate_page(self):
|
def test_curate_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
view = views.Curate.as_view()
|
view = views.Curate.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
request.user = self.local_user
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
||||||
models.ListItem.objects.create(
|
models.ListItem.objects.create(
|
||||||
user=self.local_user,
|
|
||||||
book_list=self.list,
|
book_list=self.list,
|
||||||
|
user=self.local_user,
|
||||||
book=self.book,
|
book=self.book,
|
||||||
approved=False,
|
approved=False,
|
||||||
order=1,
|
order=1,
|
||||||
)
|
)
|
||||||
request = self.factory.get("")
|
|
||||||
request.user = self.local_user
|
|
||||||
|
|
||||||
result = view(request, self.list.id)
|
result = view(request, self.list.id)
|
||||||
self.assertIsInstance(result, TemplateResponse)
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
@ -18,7 +18,7 @@ class ListActionViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
@ -90,8 +90,9 @@ class ListActionViews(TestCase):
|
|||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
"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)
|
views.delete_list(request, self.list.id)
|
||||||
|
self.assertTrue(redis_mock.called)
|
||||||
activity = json.loads(mock.call_args[1]["args"][1])
|
activity = json.loads(mock.call_args[1]["args"][1])
|
||||||
self.assertEqual(activity["type"], "Delete")
|
self.assertEqual(activity["type"], "Delete")
|
||||||
self.assertEqual(activity["actor"], self.local_user.remote_id)
|
self.assertEqual(activity["actor"], self.local_user.remote_id)
|
||||||
@ -123,10 +124,7 @@ class ListActionViews(TestCase):
|
|||||||
|
|
||||||
request = self.factory.post(
|
request = self.factory.post(
|
||||||
"",
|
"",
|
||||||
{
|
{"item": pending.id, "approved": "true"},
|
||||||
"item": pending.id,
|
|
||||||
"approved": "true",
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
@ -553,12 +551,7 @@ class ListActionViews(TestCase):
|
|||||||
)
|
)
|
||||||
self.assertTrue(self.list.listitem_set.exists())
|
self.assertTrue(self.list.listitem_set.exists())
|
||||||
|
|
||||||
request = self.factory.post(
|
request = self.factory.post("", {"item": item.id})
|
||||||
"",
|
|
||||||
{
|
|
||||||
"item": item.id,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"):
|
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
|
book_list=self.list, user=self.local_user, book=self.book, order=1
|
||||||
)
|
)
|
||||||
self.assertTrue(self.list.listitem_set.exists())
|
self.assertTrue(self.list.listitem_set.exists())
|
||||||
request = self.factory.post(
|
request = self.factory.post("", {"item": item.id})
|
||||||
"",
|
|
||||||
{
|
|
||||||
"item": item.id,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
request.user = self.rat
|
request.user = self.rat
|
||||||
|
|
||||||
with self.assertRaises(PermissionDenied):
|
with self.assertRaises(PermissionDenied):
|
||||||
views.list.remove_book(request, self.list.id)
|
views.list.remove_book(request, self.list.id)
|
||||||
self.assertTrue(self.list.listitem_set.exists())
|
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())
|
||||||
|
@ -17,7 +17,7 @@ class NotificationViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.mouse",
|
"mouse@mouse.mouse",
|
||||||
|
@ -20,7 +20,7 @@ class OutboxView(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -20,7 +20,7 @@ class ReadingViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -27,7 +27,7 @@ class ReadThrough(TestCase):
|
|||||||
|
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
"cinco", "cinco@example.com", "seissiete", local=True, localname="cinco"
|
"cinco", "cinco@example.com", "seissiete", local=True, localname="cinco"
|
||||||
)
|
)
|
||||||
|
@ -15,7 +15,7 @@ class RssFeedView(TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"rss_user", "rss@test.rss", "password", local=True
|
"rss_user", "rss@test.rss", "password", local=True
|
||||||
)
|
)
|
||||||
|
@ -23,7 +23,7 @@ class Views(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
@ -13,6 +13,7 @@ from bookwyrm.tests.validate_html import validate_html
|
|||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||||
@patch("bookwyrm.activitystreams.populate_stream_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.activitystreams.remove_status_task.delay")
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||||
class StatusViews(TestCase):
|
class StatusViews(TestCase):
|
||||||
@ -23,7 +24,7 @@ class StatusViews(TestCase):
|
|||||||
self.factory = RequestFactory()
|
self.factory = RequestFactory()
|
||||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
||||||
"bookwyrm.activitystreams.populate_stream_task.delay"
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
||||||
):
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
||||||
self.local_user = models.User.objects.create_user(
|
self.local_user = models.User.objects.create_user(
|
||||||
"mouse@local.com",
|
"mouse@local.com",
|
||||||
"mouse@mouse.com",
|
"mouse@mouse.com",
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user