Updates mocks

This commit is contained in:
Mouse Reeve 2021-08-03 10:25:53 -07:00
parent 88967e589b
commit be044bce0d
45 changed files with 473 additions and 393 deletions

View file

@ -148,9 +148,9 @@ def update_suggestions_on_follow(sender, instance, created, *args, **kwargs):
# pylint: disable=unused-argument # pylint: disable=unused-argument
def update_suggestions_on_block(sender, instance, *args, **kwargs): def update_suggestions_on_block(sender, instance, *args, **kwargs):
"""remove blocked users from recs""" """remove blocked users from recs"""
if instance.user_subject.local: if instance.user_subject.local and instance.user_object.discoverable:
remove_suggestion_task.delay(instance.user_subject.id, instance.user_object.id) remove_suggestion_task.delay(instance.user_subject.id, instance.user_object.id)
if instance.user_object.local: if instance.user_object.local and instance.user_subject.discoverable:
remove_suggestion_task.delay(instance.user_object.id, instance.user_subject.id) remove_suggestion_task.delay(instance.user_object.id, instance.user_subject.id)

View file

@ -31,9 +31,10 @@ class LibrarythingImport(TestCase):
# Librarything generates latin encoded exports... # Librarything generates latin encoded exports...
self.csv = open(datafile, "r", encoding=self.importer.encoding) self.csv = open(datafile, "r", encoding=self.importer.encoding)
self.user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mmai", "mmai@mmai.mmai", "password", local=True self.user = models.User.objects.create_user(
) "mmai", "mmai@mmai.mmai", "password", local=True
)
models.Connector.objects.create( models.Connector.objects.create(
identifier=DOMAIN, identifier=DOMAIN,
@ -197,7 +198,7 @@ class LibrarythingImport(TestCase):
self.assertEqual(readthrough.finish_date, make_date(2007, 5, 8)) self.assertEqual(readthrough.finish_date, make_date(2007, 5, 8))
@patch("bookwyrm.activitystreams.ActivityStream.add_status") @patch("bookwyrm.activitystreams.ActivityStream.add_status")
def test_handle_imported_book_review(self, _): def test_handle_imported_book_review(self, *_):
"""librarything review import""" """librarything review import"""
import_job = models.ImportJob.objects.create(user=self.user) import_job = models.ImportJob.objects.create(user=self.user)
datafile = pathlib.Path(__file__).parent.joinpath("../data/librarything.tsv") datafile = pathlib.Path(__file__).parent.joinpath("../data/librarything.tsv")

View file

@ -12,16 +12,17 @@ class Activitystreams(TestCase):
def setUp(self): def setUp(self):
"""we need some stuff""" """we need some stuff"""
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" 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", self.another_user = models.User.objects.create_user(
"nutria@nutria.nutria", "nutria",
"password", "nutria@nutria.nutria",
local=True, "password",
localname="nutria", local=True,
) localname="nutria",
)
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",

View file

@ -27,9 +27,10 @@ class ActivitypubMixins(TestCase):
def setUp(self): def setUp(self):
"""shared data""" """shared data"""
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse" self.local_user = models.User.objects.create_user(
) "mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
)
self.local_user.remote_id = "http://example.com/a/b" self.local_user.remote_id = "http://example.com/a/b"
self.local_user.save(broadcast=False) self.local_user.save(broadcast=False)
with patch("bookwyrm.models.user.set_remote_server.delay"): with patch("bookwyrm.models.user.set_remote_server.delay"):

View file

@ -13,9 +13,10 @@ class BaseModel(TestCase):
def setUp(self): def setUp(self):
"""shared data""" """shared data"""
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse" self.local_user = models.User.objects.create_user(
) "mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
)
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",

View file

@ -59,9 +59,10 @@ class ImportJob(TestCase):
unknown_read_data["Exclusive Shelf"] = "read" unknown_read_data["Exclusive Shelf"] = "read"
unknown_read_data["Date Read"] = "" unknown_read_data["Date Read"] = ""
user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" user = models.User.objects.create_user(
) "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)
job = models.ImportJob.objects.create(user=user) job = models.ImportJob.objects.create(user=user)
self.item_1 = models.ImportItem.objects.create( self.item_1 = models.ImportItem.objects.create(
job=job, index=1, data=currently_reading_data job=job, index=1, data=currently_reading_data

View file

@ -11,9 +11,10 @@ class List(TestCase):
def setUp(self): def setUp(self):
"""look, a list""" """look, a list"""
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" self.local_user = models.User.objects.create_user(
) "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)
work = models.Work.objects.create(title="hello") work = models.Work.objects.create(title="hello")
self.book = models.Edition.objects.create(title="hi", parent_work=work) self.book = models.Edition.objects.create(title="hi", parent_work=work)

View file

@ -1,4 +1,5 @@
""" testing models """ """ testing models """
from unittest.mock import patch
from django.test import TestCase from django.test import TestCase
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
@ -10,9 +11,10 @@ class ReadThrough(TestCase):
def setUp(self): def setUp(self):
"""look, a shelf""" """look, a shelf"""
self.user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" self.user = models.User.objects.create_user(
) "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)
self.work = models.Work.objects.create(title="Example Work") self.work = models.Work.objects.create(title="Example Work")
self.edition = models.Edition.objects.create( self.edition = models.Edition.objects.create(

View file

@ -7,18 +7,20 @@ from bookwyrm import models, settings
# pylint: disable=unused-argument # pylint: disable=unused-argument
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
class Shelf(TestCase): class Shelf(TestCase):
"""some activitypub oddness ahead""" """some activitypub oddness ahead"""
def setUp(self): def setUp(self):
"""look, a shelf""" """look, a shelf"""
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" self.local_user = models.User.objects.create_user(
) "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)
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_remote_id(self): def test_remote_id(self, _):
"""shelves use custom remote ids""" """shelves use custom remote ids"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(
@ -27,7 +29,7 @@ class Shelf(TestCase):
expected_id = "https://%s/user/mouse/books/test-shelf" % settings.DOMAIN expected_id = "https://%s/user/mouse/books/test-shelf" % settings.DOMAIN
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, _):
"""jsonify it""" """jsonify it"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(
@ -41,7 +43,7 @@ class Shelf(TestCase):
self.assertEqual(activity_json["name"], "Test Shelf") self.assertEqual(activity_json["name"], "Test Shelf")
self.assertEqual(activity_json["owner"], self.local_user.remote_id) self.assertEqual(activity_json["owner"], self.local_user.remote_id)
def test_create_update_shelf(self): def test_create_update_shelf(self, _):
"""create and broadcast shelf creation""" """create and broadcast shelf creation"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock:
@ -62,7 +64,7 @@ class Shelf(TestCase):
self.assertEqual(activity["object"]["name"], "arthur russel") self.assertEqual(activity["object"]["name"], "arthur russel")
self.assertEqual(shelf.name, "arthur russel") self.assertEqual(shelf.name, "arthur russel")
def test_shelve(self): def test_shelve(self, _):
"""create and broadcast shelf creation""" """create and broadcast shelf creation"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
shelf = models.Shelf.objects.create( shelf = models.Shelf.objects.create(

View file

@ -22,9 +22,10 @@ class Status(TestCase):
def setUp(self): def setUp(self):
"""useful things for creating a status""" """useful things for creating a status"""
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse" self.local_user = models.User.objects.create_user(
) "mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
)
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",

View file

@ -11,15 +11,16 @@ from bookwyrm.settings import DOMAIN
# pylint: disable=missing-function-docstring # pylint: disable=missing-function-docstring
class User(TestCase): class User(TestCase):
def setUp(self): def setUp(self):
self.user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@%s" % DOMAIN, self.user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@%s" % DOMAIN,
"mouseword", "mouse@mouse.mouse",
local=True, "mouseword",
localname="mouse", local=True,
name="hi", localname="mouse",
bookwyrm_user=False, name="hi",
) bookwyrm_user=False,
)
def test_computed_fields(self): def test_computed_fields(self):
"""username instead of id here""" """username instead of id here"""

View file

@ -12,13 +12,14 @@ class AnnouncementViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
models.SiteSettings.objects.create() models.SiteSettings.objects.create()

View file

@ -13,25 +13,27 @@ 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")
class AuthenticationViews(TestCase): class AuthenticationViews(TestCase):
"""login and password management""" """login and password management"""
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"password", "mouse@mouse.com",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
self.anonymous_user = AnonymousUser self.anonymous_user = AnonymousUser
self.anonymous_user.is_authenticated = False self.anonymous_user.is_authenticated = False
self.settings = models.SiteSettings.objects.create(id=1) self.settings = models.SiteSettings.objects.create(id=1)
def test_login_get(self): def test_login_get(self, _):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
login = views.Login.as_view() login = views.Login.as_view()
request = self.factory.get("") request = self.factory.get("")
@ -47,7 +49,7 @@ class AuthenticationViews(TestCase):
self.assertEqual(result.url, "/") self.assertEqual(result.url, "/")
self.assertEqual(result.status_code, 302) self.assertEqual(result.status_code, 302)
def test_register(self): def test_register(self, _):
"""create a user""" """create a user"""
view = views.Register.as_view() view = views.Register.as_view()
self.assertEqual(models.User.objects.count(), 1) self.assertEqual(models.User.objects.count(), 1)
@ -68,7 +70,7 @@ class AuthenticationViews(TestCase):
self.assertEqual(nutria.localname, "nutria-user.user_nutria") self.assertEqual(nutria.localname, "nutria-user.user_nutria")
self.assertEqual(nutria.local, True) self.assertEqual(nutria.local, True)
def test_register_trailing_space(self): def test_register_trailing_space(self, _):
"""django handles this so weirdly""" """django handles this so weirdly"""
view = views.Register.as_view() view = views.Register.as_view()
request = self.factory.post( request = self.factory.post(
@ -84,7 +86,7 @@ class AuthenticationViews(TestCase):
self.assertEqual(nutria.localname, "nutria") self.assertEqual(nutria.localname, "nutria")
self.assertEqual(nutria.local, True) self.assertEqual(nutria.local, True)
def test_register_invalid_email(self): def test_register_invalid_email(self, _):
"""gotta have an email""" """gotta have an email"""
view = views.Register.as_view() view = views.Register.as_view()
self.assertEqual(models.User.objects.count(), 1) self.assertEqual(models.User.objects.count(), 1)
@ -95,7 +97,7 @@ class AuthenticationViews(TestCase):
self.assertEqual(models.User.objects.count(), 1) self.assertEqual(models.User.objects.count(), 1)
response.render() response.render()
def test_register_invalid_username(self): def test_register_invalid_username(self, _):
"""gotta have an email""" """gotta have an email"""
view = views.Register.as_view() view = views.Register.as_view()
self.assertEqual(models.User.objects.count(), 1) self.assertEqual(models.User.objects.count(), 1)
@ -123,7 +125,7 @@ class AuthenticationViews(TestCase):
self.assertEqual(models.User.objects.count(), 1) self.assertEqual(models.User.objects.count(), 1)
response.render() response.render()
def test_register_closed_instance(self): def test_register_closed_instance(self, _):
"""you can't just register""" """you can't just register"""
view = views.Register.as_view() view = views.Register.as_view()
self.settings.allow_registration = False self.settings.allow_registration = False
@ -135,7 +137,7 @@ class AuthenticationViews(TestCase):
with self.assertRaises(PermissionDenied): with self.assertRaises(PermissionDenied):
view(request) view(request)
def test_register_invite(self): def test_register_invite(self, _):
"""you can't just register""" """you can't just register"""
view = views.Register.as_view() view = views.Register.as_view()
self.settings.allow_registration = False self.settings.allow_registration = False

View file

@ -17,14 +17,15 @@ class AuthorViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
self.group = Group.objects.create(name="editor") self.group = Group.objects.create(name="editor")
self.group.permissions.add( self.group.permissions.add(
Permission.objects.create( Permission.objects.create(

View file

@ -14,13 +14,14 @@ class BlockViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
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",

View file

@ -23,14 +23,15 @@ class BookViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
self.group = Group.objects.create(name="editor") self.group = Group.objects.create(name="editor")
self.group.permissions.add( self.group.permissions.add(
Permission.objects.create( Permission.objects.create(

View file

@ -1,4 +1,7 @@
""" test for app action functionality """ """ test for app action functionality """
from unittest.mock import patch
from django.contrib.auth.models import AnonymousUser
from django.template.response import TemplateResponse 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
@ -12,15 +15,25 @@ class DirectoryViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
self.rat = models.User.objects.create_user( )
models.SiteSettings.objects.create()
self.anonymous_user = AnonymousUser
self.anonymous_user.is_authenticated = False
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.suggested_users.rerank_user_task.delay")
def test_directory_page(self, *_):
"""there are so many views, this just makes sure it LOADS"""
models.User.objects.create_user(
"rat@local.com", "rat@local.com",
"rat@rat.com", "rat@rat.com",
"ratword", "ratword",
@ -29,10 +42,16 @@ class DirectoryViews(TestCase):
remote_id="https://example.com/users/rat", remote_id="https://example.com/users/rat",
discoverable=True, discoverable=True,
) )
view = views.Directory.as_view()
request = self.factory.get("")
request.user = self.local_user
models.SiteSettings.objects.create() result = view(request)
self.assertIsInstance(result, TemplateResponse)
result.render()
self.assertEqual(result.status_code, 200)
def test_directory_page(self): def test_directory_page_empty(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.Directory.as_view() view = views.Directory.as_view()
request = self.factory.get("") request = self.factory.get("")
@ -42,3 +61,12 @@ class DirectoryViews(TestCase):
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
result.render() result.render()
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_directory_page_logged_out(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.Directory.as_view()
request = self.factory.get("")
request.user = self.anonymous_user
result = view(request)
self.assertEqual(result.status_code, 302)

View file

@ -21,16 +21,17 @@ class EditUserViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
self.rat = models.User.objects.create_user( )
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" self.rat = models.User.objects.create_user(
) "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
)
self.book = models.Edition.objects.create(title="test") self.book = models.Edition.objects.create(title="test")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):

View file

@ -15,13 +15,14 @@ class FederationViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
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",

View file

@ -22,13 +22,14 @@ class FeedViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
parent_work=models.Work.objects.create(title="hi"), parent_work=models.Work.objects.create(title="hi"),
title="Example Edition", title="Example Edition",

View file

@ -10,20 +10,21 @@ from django.test.client import RequestFactory
from bookwyrm import models, views from bookwyrm import models, views
class BookViews(TestCase): class FollowViews(TestCase):
"""books books books""" """follows"""
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
with patch("bookwyrm.models.user.set_remote_server"): with patch("bookwyrm.models.user.set_remote_server"):
self.remote_user = models.User.objects.create_user( self.remote_user = models.User.objects.create_user(
"rat", "rat",
@ -66,15 +67,16 @@ class BookViews(TestCase):
def test_handle_follow_local_manually_approves(self): def test_handle_follow_local_manually_approves(self):
"""send a follow request""" """send a follow request"""
rat = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"rat@local.com", rat = models.User.objects.create_user(
"rat@rat.com", "rat@local.com",
"ratword", "rat@rat.com",
local=True, "ratword",
localname="rat", local=True,
remote_id="https://example.com/users/rat", localname="rat",
manually_approves_followers=True, remote_id="https://example.com/users/rat",
) manually_approves_followers=True,
)
request = self.factory.post("", {"user": rat}) request = self.factory.post("", {"user": rat})
request.user = self.local_user request.user = self.local_user
self.assertEqual(models.UserFollowRequest.objects.count(), 0) self.assertEqual(models.UserFollowRequest.objects.count(), 0)
@ -89,14 +91,15 @@ class BookViews(TestCase):
def test_handle_follow_local(self): def test_handle_follow_local(self):
"""send a follow request""" """send a follow request"""
rat = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"rat@local.com", rat = models.User.objects.create_user(
"rat@rat.com", "rat@local.com",
"ratword", "rat@rat.com",
local=True, "ratword",
localname="rat", local=True,
remote_id="https://example.com/users/rat", localname="rat",
) remote_id="https://example.com/users/rat",
)
request = self.factory.post("", {"user": rat}) request = self.factory.post("", {"user": rat})
request.user = self.local_user request.user = self.local_user
self.assertEqual(models.UserFollowRequest.objects.count(), 0) self.assertEqual(models.UserFollowRequest.objects.count(), 0)

View file

@ -13,13 +13,14 @@ class GetStartedViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
parent_work=models.Work.objects.create(title="hi"), parent_work=models.Work.objects.create(title="hi"),
title="Example Edition", title="Example Edition",

View file

@ -16,22 +16,23 @@ class GoalViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
self.rat = models.User.objects.create_user( )
"rat@local.com", self.rat = models.User.objects.create_user(
"rat@rat.com", "rat@local.com",
"ratword", "rat@rat.com",
local=True, "ratword",
localname="rat", local=True,
remote_id="https://example.com/users/rat", localname="rat",
) remote_id="https://example.com/users/rat",
)
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="Example Edition", title="Example Edition",
remote_id="https://example.com/book/1", remote_id="https://example.com/book/1",

View file

@ -13,21 +13,23 @@ from bookwyrm.settings import USER_AGENT
@patch("bookwyrm.activitystreams.ActivityStream.add_status") @patch("bookwyrm.activitystreams.ActivityStream.add_status")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
class ViewsHelpers(TestCase): class ViewsHelpers(TestCase):
"""viewing and creating statuses""" """viewing and creating statuses"""
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
discoverable=True, local=True,
localname="mouse", discoverable=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
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",
@ -53,12 +55,12 @@ class ViewsHelpers(TestCase):
name="Test Shelf", identifier="test-shelf", user=self.local_user name="Test Shelf", identifier="test-shelf", user=self.local_user
) )
def test_get_edition(self, _): def test_get_edition(self, *_):
"""given an edition or a work, returns an edition""" """given an edition or a work, returns an edition"""
self.assertEqual(views.helpers.get_edition(self.book.id), self.book) self.assertEqual(views.helpers.get_edition(self.book.id), self.book)
self.assertEqual(views.helpers.get_edition(self.work.id), self.book) self.assertEqual(views.helpers.get_edition(self.work.id), self.book)
def test_get_user_from_username(self, _): def test_get_user_from_username(self, *_):
"""works for either localname or username""" """works for either localname or username"""
self.assertEqual( self.assertEqual(
views.helpers.get_user_from_username(self.local_user, "mouse"), views.helpers.get_user_from_username(self.local_user, "mouse"),
@ -71,7 +73,7 @@ class ViewsHelpers(TestCase):
with self.assertRaises(Http404): with self.assertRaises(Http404):
views.helpers.get_user_from_username(self.local_user, "mojfse@example.com") views.helpers.get_user_from_username(self.local_user, "mojfse@example.com")
def test_is_api_request(self, _): def test_is_api_request(self, *_):
"""should it return html or json""" """should it return html or json"""
request = self.factory.get("/path") request = self.factory.get("/path")
request.headers = {"Accept": "application/json"} request.headers = {"Accept": "application/json"}
@ -85,12 +87,12 @@ class ViewsHelpers(TestCase):
request.headers = {"Accept": "Praise"} request.headers = {"Accept": "Praise"}
self.assertFalse(views.helpers.is_api_request(request)) self.assertFalse(views.helpers.is_api_request(request))
def test_is_api_request_no_headers(self, _): def test_is_api_request_no_headers(self, *_):
"""should it return html or json""" """should it return html or json"""
request = self.factory.get("/path") request = self.factory.get("/path")
self.assertFalse(views.helpers.is_api_request(request)) self.assertFalse(views.helpers.is_api_request(request))
def test_is_bookwyrm_request(self, _): def test_is_bookwyrm_request(self, *_):
"""checks if a request came from a bookwyrm instance""" """checks if a request came from a bookwyrm instance"""
request = self.factory.get("", {"q": "Test Book"}) request = self.factory.get("", {"q": "Test Book"})
self.assertFalse(views.helpers.is_bookwyrm_request(request)) self.assertFalse(views.helpers.is_bookwyrm_request(request))
@ -105,7 +107,7 @@ class ViewsHelpers(TestCase):
request = self.factory.get("", {"q": "Test Book"}, HTTP_USER_AGENT=USER_AGENT) request = self.factory.get("", {"q": "Test Book"}, HTTP_USER_AGENT=USER_AGENT)
self.assertTrue(views.helpers.is_bookwyrm_request(request)) self.assertTrue(views.helpers.is_bookwyrm_request(request))
def test_existing_user(self, _): def test_existing_user(self, *_):
"""simple database lookup by username""" """simple database lookup by username"""
result = views.helpers.handle_remote_webfinger("@mouse@local.com") result = views.helpers.handle_remote_webfinger("@mouse@local.com")
self.assertEqual(result, self.local_user) self.assertEqual(result, self.local_user)
@ -117,7 +119,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(result, self.local_user) self.assertEqual(result, self.local_user)
@responses.activate @responses.activate
def test_load_user(self, _): def test_load_user(self, *_):
"""find a remote user using webfinger""" """find a remote user using webfinger"""
username = "mouse@example.com" username = "mouse@example.com"
wellknown = { wellknown = {
@ -147,7 +149,7 @@ class ViewsHelpers(TestCase):
self.assertIsInstance(result, models.User) self.assertIsInstance(result, models.User)
self.assertEqual(result.username, "mouse@example.com") self.assertEqual(result.username, "mouse@example.com")
def test_user_on_blocked_server(self, _): def test_user_on_blocked_server(self, *_):
"""find a remote user using webfinger""" """find a remote user using webfinger"""
models.FederatedServer.objects.create( models.FederatedServer.objects.create(
server_name="example.com", status="blocked" server_name="example.com", status="blocked"
@ -156,7 +158,7 @@ class ViewsHelpers(TestCase):
result = views.helpers.handle_remote_webfinger("@mouse@example.com") result = views.helpers.handle_remote_webfinger("@mouse@example.com")
self.assertIsNone(result) self.assertIsNone(result)
def test_handle_reading_status_to_read(self, _): def test_handle_reading_status_to_read(self, *_):
"""posts shelve activities""" """posts shelve activities"""
shelf = self.local_user.shelf_set.get(identifier="to-read") shelf = self.local_user.shelf_set.get(identifier="to-read")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
@ -168,7 +170,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(status.mention_books.first(), self.book) self.assertEqual(status.mention_books.first(), self.book)
self.assertEqual(status.content, "wants to read") self.assertEqual(status.content, "wants to read")
def test_handle_reading_status_reading(self, _): def test_handle_reading_status_reading(self, *_):
"""posts shelve activities""" """posts shelve activities"""
shelf = self.local_user.shelf_set.get(identifier="reading") shelf = self.local_user.shelf_set.get(identifier="reading")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
@ -180,7 +182,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(status.mention_books.first(), self.book) self.assertEqual(status.mention_books.first(), self.book)
self.assertEqual(status.content, "started reading") self.assertEqual(status.content, "started reading")
def test_handle_reading_status_read(self, _): def test_handle_reading_status_read(self, *_):
"""posts shelve activities""" """posts shelve activities"""
shelf = self.local_user.shelf_set.get(identifier="read") shelf = self.local_user.shelf_set.get(identifier="read")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
@ -192,7 +194,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(status.mention_books.first(), self.book) self.assertEqual(status.mention_books.first(), self.book)
self.assertEqual(status.content, "finished reading") self.assertEqual(status.content, "finished reading")
def test_handle_reading_status_other(self, _): def test_handle_reading_status_other(self, *_):
"""posts shelve activities""" """posts shelve activities"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
views.helpers.handle_reading_status( views.helpers.handle_reading_status(
@ -200,7 +202,7 @@ class ViewsHelpers(TestCase):
) )
self.assertFalse(models.GeneratedNote.objects.exists()) self.assertFalse(models.GeneratedNote.objects.exists())
def test_get_annotated_users(self, _): def test_get_annotated_users(self, *_):
"""list of people you might know""" """list of people you might know"""
user_1 = models.User.objects.create_user( user_1 = models.User.objects.create_user(
"nutria@local.com", "nutria@local.com",
@ -247,7 +249,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(remote_user_annotated.mutuals, 0) self.assertEqual(remote_user_annotated.mutuals, 0)
self.assertEqual(remote_user_annotated.shared_books, 0) self.assertEqual(remote_user_annotated.shared_books, 0)
def test_get_annotated_users_counts(self, _): def test_get_annotated_users_counts(self, *_):
"""correct counting for multiple shared attributed""" """correct counting for multiple shared attributed"""
user_1 = models.User.objects.create_user( user_1 = models.User.objects.create_user(
"nutria@local.com", "nutria@local.com",

View file

@ -14,13 +14,14 @@ class ImportViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
models.SiteSettings.objects.create() models.SiteSettings.objects.create()
def test_import_page(self): def test_import_page(self):

View file

@ -15,14 +15,15 @@ class InteractionViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
with patch("bookwyrm.models.user.set_remote_server"): with patch("bookwyrm.models.user.set_remote_server"):
self.remote_user = models.User.objects.create_user( self.remote_user = models.User.objects.create_user(
"rat", "rat",

View file

@ -16,13 +16,14 @@ class InviteViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
models.SiteSettings.objects.create() models.SiteSettings.objects.create()
def test_invite_page(self): def test_invite_page(self):

View file

@ -16,14 +16,15 @@ class IsbnViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
self.work = models.Work.objects.create(title="Test Work") self.work = models.Work.objects.create(title="Test Work")
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="Test Book", title="Test Book",

View file

@ -15,13 +15,14 @@ class LandingViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
self.anonymous_user = AnonymousUser self.anonymous_user = AnonymousUser
self.anonymous_user.is_authenticated = False self.anonymous_user.is_authenticated = False
models.SiteSettings.objects.create() models.SiteSettings.objects.create()

View file

@ -17,22 +17,23 @@ class ListViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
self.rat = models.User.objects.create_user( )
"rat@local.com", self.rat = models.User.objects.create_user(
"rat@rat.com", "rat@local.com",
"ratword", "rat@rat.com",
local=True, "ratword",
localname="rat", local=True,
remote_id="https://example.com/users/rat", localname="rat",
) remote_id="https://example.com/users/rat",
)
work = models.Work.objects.create(title="Work") work = models.Work.objects.create(title="Work")
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="Example Edition", title="Example Edition",

View file

@ -15,22 +15,23 @@ class ListActionViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
self.rat = models.User.objects.create_user( )
"rat@local.com", self.rat = models.User.objects.create_user(
"rat@rat.com", "rat@local.com",
"ratword", "rat@rat.com",
local=True, "ratword",
localname="rat", local=True,
remote_id="https://example.com/users/rat", localname="rat",
) remote_id="https://example.com/users/rat",
)
work = models.Work.objects.create(title="Work") work = models.Work.objects.create(title="Work")
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(

View file

@ -1,4 +1,5 @@
""" test for app action functionality """ """ test for app action functionality """
from unittest.mock import patch
from django.template.response import TemplateResponse 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
@ -13,13 +14,14 @@ class NotificationViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
models.SiteSettings.objects.create() models.SiteSettings.objects.create()
def test_notifications_page(self): def test_notifications_page(self):

View file

@ -18,14 +18,15 @@ class OutboxView(TestCase):
def setUp(self): def setUp(self):
"""we'll need some data""" """we'll need some data"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
work = models.Work.objects.create(title="Test Work") work = models.Work.objects.create(title="Test Work")
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="Example Edition", title="Example Edition",

View file

@ -15,13 +15,14 @@ class PasswordViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"password", "mouse@mouse.com",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
self.anonymous_user = AnonymousUser self.anonymous_user = AnonymousUser
self.anonymous_user.is_authenticated = False self.anonymous_user.is_authenticated = False
models.SiteSettings.objects.create(id=1) models.SiteSettings.objects.create(id=1)

View file

@ -15,14 +15,15 @@ class ReadingViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
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",

View file

@ -21,9 +21,10 @@ class ReadThrough(TestCase):
title="Example Edition", parent_work=self.work title="Example Edition", parent_work=self.work
) )
self.user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"cinco", "cinco@example.com", "seissiete", local=True, localname="cinco" self.user = models.User.objects.create_user(
) "cinco", "cinco@example.com", "seissiete", local=True, localname="cinco"
)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
self.client.force_login(self.user) self.client.force_login(self.user)

View file

@ -1,4 +1,5 @@
""" test for app action functionality """ """ test for app action functionality """
from unittest.mock import patch
from django.template.response import TemplateResponse 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
@ -12,20 +13,21 @@ class ReportViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
self.rat = models.User.objects.create_user( )
"rat@local.com", self.rat = models.User.objects.create_user(
"rat@mouse.mouse", "rat@local.com",
"password", "rat@mouse.mouse",
local=True, "password",
localname="rat", local=True,
) localname="rat",
)
models.SiteSettings.objects.create() models.SiteSettings.objects.create()
def test_reports_page(self): def test_reports_page(self):

View file

@ -14,9 +14,10 @@ class RssFeedView(TestCase):
"""test data""" """test data"""
self.site = models.SiteSettings.objects.create() self.site = models.SiteSettings.objects.create()
self.user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"rss_user", "rss@test.rss", "password", local=True self.user = models.User.objects.create_user(
) "rss_user", "rss@test.rss", "password", local=True
)
work = models.Work.objects.create(title="Test Work") work = models.Work.objects.create(title="Test Work")
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(

View file

@ -19,14 +19,15 @@ class Views(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
self.work = models.Work.objects.create(title="Test Work") self.work = models.Work.objects.create(title="Test Work")
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="Test Book", title="Test Book",

View file

@ -16,14 +16,15 @@ class ShelfViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
self.work = models.Work.objects.create(title="Test Work") self.work = models.Work.objects.create(title="Test Work")
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="Example Edition", title="Example Edition",

View file

@ -10,20 +10,22 @@ from bookwyrm.settings import DOMAIN
# pylint: disable=invalid-name # pylint: disable=invalid-name
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") @patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
class StatusViews(TestCase): class StatusViews(TestCase):
"""viewing and creating statuses""" """viewing and creating statuses"""
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.com", "mouse@local.com",
"mouseword", "mouse@mouse.com",
local=True, "mouseword",
localname="mouse", local=True,
remote_id="https://example.com/users/mouse", localname="mouse",
) remote_id="https://example.com/users/mouse",
)
with patch("bookwyrm.models.user.set_remote_server"): with patch("bookwyrm.models.user.set_remote_server"):
self.remote_user = models.User.objects.create_user( self.remote_user = models.User.objects.create_user(
"rat", "rat",
@ -43,7 +45,7 @@ class StatusViews(TestCase):
) )
models.SiteSettings.objects.create() models.SiteSettings.objects.create()
def test_handle_status(self, _): def test_handle_status(self, *_):
"""create a status""" """create a status"""
view = views.CreateStatus.as_view() view = views.CreateStatus.as_view()
form = forms.CommentForm( form = forms.CommentForm(
@ -66,7 +68,7 @@ class StatusViews(TestCase):
self.assertEqual(status.user, self.local_user) self.assertEqual(status.user, self.local_user)
self.assertEqual(status.book, self.book) self.assertEqual(status.book, self.book)
def test_handle_status_reply(self, _): def test_handle_status_reply(self, *_):
"""create a status in reply to an existing status""" """create a status in reply to an existing status"""
view = views.CreateStatus.as_view() view = views.CreateStatus.as_view()
user = models.User.objects.create_user( user = models.User.objects.create_user(
@ -96,7 +98,7 @@ class StatusViews(TestCase):
self.assertEqual(status.user, user) self.assertEqual(status.user, user)
self.assertEqual(models.Notification.objects.get().user, self.local_user) self.assertEqual(models.Notification.objects.get().user, self.local_user)
def test_handle_status_mentions(self, _): def test_handle_status_mentions(self, *_):
"""@mention a user in a post""" """@mention a user in a post"""
view = views.CreateStatus.as_view() view = views.CreateStatus.as_view()
user = models.User.objects.create_user( user = models.User.objects.create_user(
@ -128,7 +130,7 @@ class StatusViews(TestCase):
status.content, '<p>hi <a href="%s">@rat</a></p>' % user.remote_id status.content, '<p>hi <a href="%s">@rat</a></p>' % user.remote_id
) )
def test_handle_status_reply_with_mentions(self, _): def test_handle_status_reply_with_mentions(self, *_):
"""reply to a post with an @mention'ed user""" """reply to a post with an @mention'ed user"""
view = views.CreateStatus.as_view() view = views.CreateStatus.as_view()
user = models.User.objects.create_user( user = models.User.objects.create_user(
@ -172,7 +174,7 @@ class StatusViews(TestCase):
self.assertFalse(self.remote_user in reply.mention_users.all()) self.assertFalse(self.remote_user in reply.mention_users.all())
self.assertTrue(self.local_user in reply.mention_users.all()) self.assertTrue(self.local_user in reply.mention_users.all())
def test_delete_and_redraft(self, _): def test_delete_and_redraft(self, *_):
"""delete and re-draft a status""" """delete and re-draft a status"""
view = views.DeleteAndRedraft.as_view() view = views.DeleteAndRedraft.as_view()
request = self.factory.post("") request = self.factory.post("")
@ -193,7 +195,7 @@ class StatusViews(TestCase):
status.refresh_from_db() status.refresh_from_db()
self.assertTrue(status.deleted) self.assertTrue(status.deleted)
def test_delete_and_redraft_invalid_status_type_rating(self, _): def test_delete_and_redraft_invalid_status_type_rating(self, *_):
"""you can't redraft generated statuses""" """you can't redraft generated statuses"""
view = views.DeleteAndRedraft.as_view() view = views.DeleteAndRedraft.as_view()
request = self.factory.post("") request = self.factory.post("")
@ -213,7 +215,7 @@ class StatusViews(TestCase):
status.refresh_from_db() status.refresh_from_db()
self.assertFalse(status.deleted) self.assertFalse(status.deleted)
def test_delete_and_redraft_invalid_status_type_generated_note(self, _): def test_delete_and_redraft_invalid_status_type_generated_note(self, *_):
"""you can't redraft generated statuses""" """you can't redraft generated statuses"""
view = views.DeleteAndRedraft.as_view() view = views.DeleteAndRedraft.as_view()
request = self.factory.post("") request = self.factory.post("")
@ -233,7 +235,7 @@ class StatusViews(TestCase):
status.refresh_from_db() status.refresh_from_db()
self.assertFalse(status.deleted) self.assertFalse(status.deleted)
def test_find_mentions(self, _): def test_find_mentions(self, *_):
"""detect and look up @ mentions of users""" """detect and look up @ mentions of users"""
user = models.User.objects.create_user( user = models.User.objects.create_user(
"nutria@%s" % DOMAIN, "nutria@%s" % DOMAIN,
@ -279,7 +281,7 @@ class StatusViews(TestCase):
("@nutria@%s" % DOMAIN, user), ("@nutria@%s" % DOMAIN, user),
) )
def test_format_links(self, _): def test_format_links(self, *_):
"""find and format urls into a tags""" """find and format urls into a tags"""
url = "http://www.fish.com/" url = "http://www.fish.com/"
self.assertEqual( self.assertEqual(
@ -302,7 +304,7 @@ class StatusViews(TestCase):
"?q=arkady+strugatsky&mode=everything</a>" % url, "?q=arkady+strugatsky&mode=everything</a>" % url,
) )
def test_to_markdown(self, _): def test_to_markdown(self, *_):
"""this is mostly handled in other places, but nonetheless""" """this is mostly handled in other places, but nonetheless"""
text = "_hi_ and http://fish.com is <marquee>rad</marquee>" text = "_hi_ and http://fish.com is <marquee>rad</marquee>"
result = views.status.to_markdown(text) result = views.status.to_markdown(text)
@ -311,7 +313,7 @@ class StatusViews(TestCase):
'<p><em>hi</em> and <a href="http://fish.com">fish.com</a> ' "is rad</p>", '<p><em>hi</em> and <a href="http://fish.com">fish.com</a> ' "is rad</p>",
) )
def test_to_markdown_detect_url(self, _): def test_to_markdown_detect_url(self, *_):
"""this is mostly handled in other places, but nonetheless""" """this is mostly handled in other places, but nonetheless"""
text = "http://fish.com/@hello#okay" text = "http://fish.com/@hello#okay"
result = views.status.to_markdown(text) result = views.status.to_markdown(text)
@ -320,7 +322,7 @@ class StatusViews(TestCase):
'<p><a href="http://fish.com/@hello#okay">fish.com/@hello#okay</a></p>', '<p><a href="http://fish.com/@hello#okay">fish.com/@hello#okay</a></p>',
) )
def test_to_markdown_link(self, _): def test_to_markdown_link(self, *_):
"""this is mostly handled in other places, but nonetheless""" """this is mostly handled in other places, but nonetheless"""
text = "[hi](http://fish.com) is <marquee>rad</marquee>" text = "[hi](http://fish.com) is <marquee>rad</marquee>"
result = views.status.to_markdown(text) result = views.status.to_markdown(text)
@ -346,7 +348,7 @@ class StatusViews(TestCase):
status.refresh_from_db() status.refresh_from_db()
self.assertTrue(status.deleted) self.assertTrue(status.deleted)
def test_handle_delete_status_permission_denied(self, _): def test_handle_delete_status_permission_denied(self, *_):
"""marks a status as deleted""" """marks a status as deleted"""
view = views.DeleteStatus.as_view() view = views.DeleteStatus.as_view()
with patch("bookwyrm.activitystreams.ActivityStream.add_status"): with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
@ -360,7 +362,7 @@ class StatusViews(TestCase):
status.refresh_from_db() status.refresh_from_db()
self.assertFalse(status.deleted) self.assertFalse(status.deleted)
def test_handle_delete_status_moderator(self, mock): def test_handle_delete_status_moderator(self, mock, _):
"""marks a status as deleted""" """marks a status as deleted"""
view = views.DeleteStatus.as_view() view = views.DeleteStatus.as_view()
with patch("bookwyrm.activitystreams.ActivityStream.add_status"): with patch("bookwyrm.activitystreams.ActivityStream.add_status"):

View file

@ -15,13 +15,14 @@ class UpdateViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
models.SiteSettings.objects.create() models.SiteSettings.objects.create()
def test_get_notification_count(self): def test_get_notification_count(self):

View file

@ -17,16 +17,17 @@ class UserViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
self.rat = models.User.objects.create_user( )
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" self.rat = models.User.objects.create_user(
) "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
)
self.book = models.Edition.objects.create(title="test") self.book = models.Edition.objects.create(title="test")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.ShelfBook.objects.create( models.ShelfBook.objects.create(

View file

@ -14,13 +14,14 @@ class UserAdminViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
)
models.SiteSettings.objects.create() models.SiteSettings.objects.create()
def test_user_admin_list_page(self): def test_user_admin_list_page(self):

View file

@ -16,16 +16,17 @@ class UserViews(TestCase):
def setUp(self): def setUp(self):
"""we need basic test data and mocks""" """we need basic test data and mocks"""
self.factory = RequestFactory() self.factory = RequestFactory()
self.local_user = models.User.objects.create_user( with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"):
"mouse@local.com", self.local_user = models.User.objects.create_user(
"mouse@mouse.mouse", "mouse@local.com",
"password", "mouse@mouse.mouse",
local=True, "password",
localname="mouse", local=True,
) localname="mouse",
models.User.objects.create_user( )
"rat@local.com", "rat@rat.rat", "password", local=True, localname="rat" models.User.objects.create_user(
) "rat@local.com", "rat@rat.rat", "password", local=True, localname="rat"
)
with patch("bookwyrm.models.user.set_remote_server.delay"): with patch("bookwyrm.models.user.set_remote_server.delay"):
models.User.objects.create_user( models.User.objects.create_user(
"rat", "rat",