mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 10:01:04 +00:00
Moore moocks
This commit is contained in:
parent
5d2324a4a0
commit
f35855ce69
15 changed files with 109 additions and 95 deletions
|
@ -2,6 +2,7 @@
|
|||
from collections import namedtuple
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.db.models import Q
|
||||
from django.test import TestCase
|
||||
|
||||
from bookwyrm import models
|
||||
|
@ -10,6 +11,8 @@ from bookwyrm.suggested_users import suggested_users, get_annotated_users
|
|||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
|
||||
class SuggestedUsers(TestCase):
|
||||
"""using redis to build activity streams"""
|
||||
|
||||
|
@ -41,8 +44,6 @@ class SuggestedUsers(TestCase):
|
|||
self.assertEqual(counts["mutuals"], 3)
|
||||
self.assertEqual(counts["shared_books"], 27)
|
||||
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
|
||||
def test_get_objects_for_store(self, *_):
|
||||
"""list of people to follow for a given user"""
|
||||
|
||||
|
@ -96,6 +97,7 @@ class SuggestedUsers(TestCase):
|
|||
"fishword",
|
||||
local=True,
|
||||
localname="fish",
|
||||
discoverable=True,
|
||||
)
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
# 1 shared follow
|
||||
|
@ -112,8 +114,8 @@ class SuggestedUsers(TestCase):
|
|||
user=user_1, book=self.book, shelf=user_1.shelf_set.first()
|
||||
)
|
||||
|
||||
result = views.helpers.get_annotated_users(self.local_user)
|
||||
self.assertEqual(result.count(), 3)
|
||||
result = get_annotated_users(self.local_user)
|
||||
self.assertEqual(result.count(), 2)
|
||||
self.assertTrue(user_1 in result)
|
||||
self.assertFalse(user_2 in result)
|
||||
self.assertTrue(self.local_user in result)
|
||||
|
|
|
@ -19,13 +19,14 @@ class Inbox(TestCase):
|
|||
self.client = Client()
|
||||
self.factory = RequestFactory()
|
||||
|
||||
local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
local_user.remote_id = "https://example.com/user/mouse"
|
||||
local_user.save(broadcast=False)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
|
|
|
@ -13,13 +13,14 @@ class InboxAdd(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
local_user.remote_id = "https://example.com/user/mouse"
|
||||
local_user.save(broadcast=False)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
|
|
|
@ -13,15 +13,16 @@ class InboxActivities(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
|
|
@ -12,15 +12,16 @@ class InboxBlock(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
|
|
@ -16,15 +16,16 @@ class InboxCreate(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
|
|
@ -13,15 +13,16 @@ class InboxActivities(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
|
|
@ -13,15 +13,16 @@ class InboxRelationships(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
@ -102,7 +103,7 @@ class InboxRelationships(TestCase):
|
|||
}
|
||||
|
||||
self.local_user.manually_approves_followers = True
|
||||
self.local_user.save(broadcast=False)
|
||||
self.local_user.save(broadcast=False, update_fields=["manually_approves_followers"])
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
views.inbox.activity_task(activity)
|
||||
|
@ -124,7 +125,7 @@ class InboxRelationships(TestCase):
|
|||
def test_undo_follow_request(self):
|
||||
"""the requester cancels a follow request"""
|
||||
self.local_user.manually_approves_followers = True
|
||||
self.local_user.save(broadcast=False)
|
||||
self.local_user.save(broadcast=False, update_fields=["manually_approves_followers"])
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
request = models.UserFollowRequest.objects.create(
|
||||
user_subject=self.remote_user, user_object=self.local_user
|
||||
|
|
|
@ -12,15 +12,16 @@ class InboxActivities(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
|
|
@ -12,15 +12,16 @@ class InboxRemove(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
|
|
@ -14,15 +14,16 @@ class InboxUpdate(TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""basic user and book data"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse@example.com",
|
||||
"mouse@mouse.com",
|
||||
"mouseword",
|
||||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||
self.local_user.save(broadcast=False)
|
||||
self.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
import json
|
||||
from unittest.mock import patch
|
||||
import pathlib
|
||||
from django.db.models import Q
|
||||
from django.http import Http404
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
|
|
|
@ -27,7 +27,8 @@ class LandingViews(TestCase):
|
|||
self.anonymous_user.is_authenticated = False
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_home_page(self):
|
||||
@patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions")
|
||||
def test_home_page(self, _):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Home.as_view()
|
||||
request = self.factory.get("")
|
||||
|
|
|
@ -116,6 +116,7 @@ class ReportViews(TestCase):
|
|||
report.refresh_from_db()
|
||||
self.assertFalse(report.resolved)
|
||||
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
def test_suspend_user(self):
|
||||
"""toggle whether a user is able to log in"""
|
||||
self.assertTrue(self.rat.is_active)
|
||||
|
|
|
@ -10,6 +10,7 @@ from bookwyrm.activitypub import ActivitypubResponse
|
|||
|
||||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
|
||||
class ShelfViews(TestCase):
|
||||
"""tag views"""
|
||||
|
||||
|
@ -37,7 +38,7 @@ class ShelfViews(TestCase):
|
|||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_shelf_page(self, _):
|
||||
def test_shelf_page(self, *_):
|
||||
"""there are so many views, this just makes sure it LOADS"""
|
||||
view = views.Shelf.as_view()
|
||||
shelf = self.local_user.shelf_set.first()
|
||||
|
@ -64,7 +65,7 @@ class ShelfViews(TestCase):
|
|||
self.assertIsInstance(result, ActivitypubResponse)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_edit_shelf_privacy(self, _):
|
||||
def test_edit_shelf_privacy(self, *_):
|
||||
"""set name or privacy on shelf"""
|
||||
view = views.Shelf.as_view()
|
||||
shelf = self.local_user.shelf_set.get(identifier="to-read")
|
||||
|
@ -84,7 +85,7 @@ class ShelfViews(TestCase):
|
|||
|
||||
self.assertEqual(shelf.privacy, "unlisted")
|
||||
|
||||
def test_edit_shelf_name(self, _):
|
||||
def test_edit_shelf_name(self, *_):
|
||||
"""change the name of an editable shelf"""
|
||||
view = views.Shelf.as_view()
|
||||
shelf = models.Shelf.objects.create(name="Test Shelf", user=self.local_user)
|
||||
|
@ -101,7 +102,7 @@ class ShelfViews(TestCase):
|
|||
self.assertEqual(shelf.name, "cool name")
|
||||
self.assertEqual(shelf.identifier, "testshelf-%d" % shelf.id)
|
||||
|
||||
def test_edit_shelf_name_not_editable(self, _):
|
||||
def test_edit_shelf_name_not_editable(self, *_):
|
||||
"""can't change the name of an non-editable shelf"""
|
||||
view = views.Shelf.as_view()
|
||||
shelf = self.local_user.shelf_set.get(identifier="to-read")
|
||||
|
@ -116,7 +117,7 @@ class ShelfViews(TestCase):
|
|||
|
||||
self.assertEqual(shelf.name, "To Read")
|
||||
|
||||
def test_handle_shelve(self, _):
|
||||
def test_handle_shelve(self, *_):
|
||||
"""shelve a book"""
|
||||
request = self.factory.post(
|
||||
"", {"book": self.book.id, "shelf": self.shelf.identifier}
|
||||
|
@ -134,7 +135,7 @@ class ShelfViews(TestCase):
|
|||
# make sure the book is on the shelf
|
||||
self.assertEqual(self.shelf.books.get(), self.book)
|
||||
|
||||
def test_handle_shelve_to_read(self, _):
|
||||
def test_handle_shelve_to_read(self, *_):
|
||||
"""special behavior for the to-read shelf"""
|
||||
shelf = models.Shelf.objects.get(identifier="to-read")
|
||||
request = self.factory.post(
|
||||
|
@ -147,7 +148,7 @@ class ShelfViews(TestCase):
|
|||
# make sure the book is on the shelf
|
||||
self.assertEqual(shelf.books.get(), self.book)
|
||||
|
||||
def test_handle_shelve_reading(self, _):
|
||||
def test_handle_shelve_reading(self, *_):
|
||||
"""special behavior for the reading shelf"""
|
||||
shelf = models.Shelf.objects.get(identifier="reading")
|
||||
request = self.factory.post(
|
||||
|
@ -160,7 +161,7 @@ class ShelfViews(TestCase):
|
|||
# make sure the book is on the shelf
|
||||
self.assertEqual(shelf.books.get(), self.book)
|
||||
|
||||
def test_handle_shelve_read(self, _):
|
||||
def test_handle_shelve_read(self, *_):
|
||||
"""special behavior for the read shelf"""
|
||||
shelf = models.Shelf.objects.get(identifier="read")
|
||||
request = self.factory.post(
|
||||
|
@ -173,7 +174,7 @@ class ShelfViews(TestCase):
|
|||
# make sure the book is on the shelf
|
||||
self.assertEqual(shelf.books.get(), self.book)
|
||||
|
||||
def test_handle_unshelve(self, _):
|
||||
def test_handle_unshelve(self, *_):
|
||||
"""remove a book from a shelf"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
models.ShelfBook.objects.create(
|
||||
|
|
Loading…
Reference in a new issue