Fixes calls to add lists

This commit is contained in:
Mouse Reeve 2021-12-30 11:58:27 -08:00
parent 4de406afe1
commit cc37d7404e
2 changed files with 39 additions and 1 deletions

View file

@ -27,7 +27,7 @@ class ListsStream(RedisStore):
def add_user_lists(self, viewer, user): def add_user_lists(self, viewer, user):
"""add a user's lists to another user's feed""" """add a user's lists to another user's feed"""
# only add the lists that the viewer should be able to see # only add the lists that the viewer should be able to see
lists = models.List.filter(user=user).privacy_filter(viewer) lists = models.List.privacy_filter(viewer).filter(user=user)
self.bulk_add_objects_to_store(lists, self.stream_id(viewer)) self.bulk_add_objects_to_store(lists, self.stream_id(viewer))
def remove_user_lists(self, viewer, user): def remove_user_lists(self, viewer, user):

View file

@ -1,5 +1,7 @@
""" testing activitystreams """ """ testing activitystreams """
from datetime import datetime
from unittest.mock import patch from unittest.mock import patch
from django.test import TestCase from django.test import TestCase
from bookwyrm import lists_stream, models from bookwyrm import lists_stream, models
@ -46,6 +48,42 @@ class ListsStream(TestCase):
f"{self.local_user.id}-lists", 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, *_): def test_get_audience(self, *_):
"""get a list of users that should see a list""" """get a list of users that should see a list"""
book_list = models.List.objects.create( book_list = models.List.objects.create(