New version of black, new whitespace

This commit is contained in:
Mouse Reeve
2021-04-26 09:15:42 -07:00
parent ef83eb33b0
commit 3ade2d3bb1
152 changed files with 1289 additions and 1289 deletions

View File

@ -12,10 +12,10 @@ from bookwyrm import models, views
# pylint: disable=too-many-public-methods
class Inbox(TestCase):
""" readthrough tests """
"""readthrough tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
self.client = Client()
self.factory = RequestFactory()
local_user = models.User.objects.create_user(
@ -48,12 +48,12 @@ class Inbox(TestCase):
models.SiteSettings.objects.create()
def test_inbox_invalid_get(self):
""" shouldn't try to handle if the user is not found """
"""shouldn't try to handle if the user is not found"""
result = self.client.get("/inbox", content_type="application/json")
self.assertIsInstance(result, HttpResponseNotAllowed)
def test_inbox_invalid_user(self):
""" shouldn't try to handle if the user is not found """
"""shouldn't try to handle if the user is not found"""
result = self.client.post(
"/user/bleh/inbox",
'{"type": "Test", "object": "exists"}',
@ -62,7 +62,7 @@ class Inbox(TestCase):
self.assertIsInstance(result, HttpResponseNotFound)
def test_inbox_invalid_bad_signature(self):
""" bad request for invalid signature """
"""bad request for invalid signature"""
with patch("bookwyrm.views.inbox.has_valid_signature") as mock_valid:
mock_valid.return_value = False
result = self.client.post(
@ -73,7 +73,7 @@ class Inbox(TestCase):
self.assertEqual(result.status_code, 401)
def test_inbox_invalid_bad_signature_delete(self):
""" invalid signature for Delete is okay though """
"""invalid signature for Delete is okay though"""
with patch("bookwyrm.views.inbox.has_valid_signature") as mock_valid:
mock_valid.return_value = False
result = self.client.post(
@ -84,7 +84,7 @@ class Inbox(TestCase):
self.assertEqual(result.status_code, 200)
def test_inbox_unknown_type(self):
""" never heard of that activity type, don't have a handler for it """
"""never heard of that activity type, don't have a handler for it"""
with patch("bookwyrm.views.inbox.has_valid_signature") as mock_valid:
result = self.client.post(
"/inbox",
@ -95,7 +95,7 @@ class Inbox(TestCase):
self.assertIsInstance(result, HttpResponseNotFound)
def test_inbox_success(self):
""" a known type, for which we start a task """
"""a known type, for which we start a task"""
activity = self.create_json
activity["object"] = {
"id": "https://example.com/list/22",
@ -121,7 +121,7 @@ class Inbox(TestCase):
self.assertEqual(result.status_code, 200)
def test_is_blocked_user_agent(self):
""" check for blocked servers """
"""check for blocked servers"""
request = self.factory.post(
"",
HTTP_USER_AGENT="http.rb/4.4.1 (Mastodon/3.3.0; +https://mastodon.social/)",
@ -134,7 +134,7 @@ class Inbox(TestCase):
self.assertTrue(views.inbox.is_blocked_user_agent(request))
def test_is_blocked_activity(self):
""" check for blocked servers """
"""check for blocked servers"""
activity = {"actor": "https://mastodon.social/user/whaatever/else"}
self.assertFalse(views.inbox.is_blocked_activity(activity))
@ -144,7 +144,7 @@ class Inbox(TestCase):
self.assertTrue(views.inbox.is_blocked_activity(activity))
def test_create_by_deactivated_user(self):
""" don't let deactivated users post """
"""don't let deactivated users post"""
self.remote_user.delete(broadcast=False)
self.assertTrue(self.remote_user.deleted)
datafile = pathlib.Path(__file__).parent.joinpath("../../data/ap_note.json")

View File

@ -9,10 +9,10 @@ from bookwyrm import models, views
# pylint: disable=too-many-public-methods
class InboxAdd(TestCase):
""" inbox tests """
"""inbox tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -42,7 +42,7 @@ class InboxAdd(TestCase):
models.SiteSettings.objects.create()
def test_handle_add_book_to_shelf(self):
""" shelving a book """
"""shelving a book"""
shelf = models.Shelf.objects.create(user=self.remote_user, name="Test Shelf")
shelf.remote_id = "https://bookwyrm.social/user/mouse/shelf/to-read"
shelf.save()
@ -65,7 +65,7 @@ class InboxAdd(TestCase):
@responses.activate
def test_handle_add_book_to_list(self):
""" listing a book """
"""listing a book"""
responses.add(
responses.GET,
"https://bookwyrm.social/user/mouse/list/to-read",

View File

@ -9,10 +9,10 @@ from bookwyrm import models, views
# pylint: disable=too-many-public-methods
class InboxActivities(TestCase):
""" inbox tests """
"""inbox tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -52,7 +52,7 @@ class InboxActivities(TestCase):
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
def test_boost(self, redis_mock):
""" boost a status """
"""boost a status"""
self.assertEqual(models.Notification.objects.count(), 0)
activity = {
"type": "Announce",
@ -82,7 +82,7 @@ class InboxActivities(TestCase):
@responses.activate
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
def test_boost_remote_status(self, redis_mock):
""" boost a status from a remote server """
"""boost a status from a remote server"""
work = models.Work.objects.create(title="work title")
book = models.Edition.objects.create(
title="Test",
@ -131,7 +131,7 @@ class InboxActivities(TestCase):
@responses.activate
def test_discarded_boost(self):
""" test a boost of a mastodon status that will be discarded """
"""test a boost of a mastodon status that will be discarded"""
status = models.Status(
content="hi",
user=self.remote_user,
@ -154,7 +154,7 @@ class InboxActivities(TestCase):
self.assertEqual(models.Boost.objects.count(), 0)
def test_unboost(self):
""" undo a boost """
"""undo a boost"""
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
boost = models.Boost.objects.create(
boosted_status=self.status, user=self.remote_user
@ -183,7 +183,7 @@ class InboxActivities(TestCase):
self.assertFalse(models.Boost.objects.exists())
def test_unboost_unknown_boost(self):
""" undo a boost """
"""undo a boost"""
activity = {
"type": "Undo",
"actor": "hi",

View File

@ -8,10 +8,10 @@ from bookwyrm import models, views
# pylint: disable=too-many-public-methods
class InboxBlock(TestCase):
""" inbox tests """
"""inbox tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -35,7 +35,7 @@ class InboxBlock(TestCase):
models.SiteSettings.objects.create()
def test_handle_blocks(self):
""" create a "block" database entry from an activity """
"""create a "block" database entry from an activity"""
self.local_user.followers.add(self.remote_user)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.UserFollowRequest.objects.create(
@ -67,7 +67,7 @@ class InboxBlock(TestCase):
self.assertFalse(models.UserFollowRequest.objects.exists())
def test_handle_unblock(self):
""" unblock a user """
"""unblock a user"""
self.remote_user.blocks.add(self.local_user)
block = models.UserBlocks.objects.get()

View File

@ -11,10 +11,10 @@ from bookwyrm.activitypub import ActivitySerializerError
# pylint: disable=too-many-public-methods
class InboxCreate(TestCase):
""" readthrough tests """
"""readthrough tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -53,7 +53,7 @@ class InboxCreate(TestCase):
models.SiteSettings.objects.create()
def test_create_status(self):
""" the "it justs works" mode """
"""the "it justs works" mode"""
self.assertEqual(models.Status.objects.count(), 1)
datafile = pathlib.Path(__file__).parent.joinpath(
@ -84,7 +84,7 @@ class InboxCreate(TestCase):
self.assertEqual(models.Status.objects.count(), 2)
def test_create_status_remote_note_with_mention(self):
""" should only create it under the right circumstances """
"""should only create it under the right circumstances"""
self.assertEqual(models.Status.objects.count(), 1)
self.assertFalse(
models.Notification.objects.filter(user=self.local_user).exists()
@ -107,7 +107,7 @@ class InboxCreate(TestCase):
self.assertEqual(models.Notification.objects.get().notification_type, "MENTION")
def test_create_status_remote_note_with_reply(self):
""" should only create it under the right circumstances """
"""should only create it under the right circumstances"""
self.assertEqual(models.Status.objects.count(), 1)
self.assertFalse(models.Notification.objects.filter(user=self.local_user))
@ -128,7 +128,7 @@ class InboxCreate(TestCase):
self.assertEqual(models.Notification.objects.get().notification_type, "REPLY")
def test_create_list(self):
""" a new list """
"""a new list"""
activity = self.create_json
activity["object"] = {
"id": "https://example.com/list/22",
@ -152,7 +152,7 @@ class InboxCreate(TestCase):
self.assertEqual(book_list.remote_id, "https://example.com/list/22")
def test_create_unsupported_type(self):
""" ignore activities we know we can't handle """
"""ignore activities we know we can't handle"""
activity = self.create_json
activity["object"] = {
"id": "https://example.com/status/887",
@ -162,7 +162,7 @@ class InboxCreate(TestCase):
views.inbox.activity_task(activity)
def test_create_unknown_type(self):
""" ignore activities we know we've never heard of """
"""ignore activities we know we've never heard of"""
activity = self.create_json
activity["object"] = {
"id": "https://example.com/status/887",

View File

@ -9,10 +9,10 @@ from bookwyrm import models, views
# pylint: disable=too-many-public-methods
class InboxActivities(TestCase):
""" inbox tests """
"""inbox tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -50,7 +50,7 @@ class InboxActivities(TestCase):
models.SiteSettings.objects.create()
def test_delete_status(self):
""" remove a status """
"""remove a status"""
self.assertFalse(self.status.deleted)
activity = {
"type": "Delete",
@ -71,7 +71,7 @@ class InboxActivities(TestCase):
self.assertIsInstance(status.deleted_date, datetime)
def test_delete_status_notifications(self):
""" remove a status with related notifications """
"""remove a status with related notifications"""
models.Notification.objects.create(
related_status=self.status,
user=self.local_user,
@ -106,7 +106,7 @@ class InboxActivities(TestCase):
self.assertEqual(models.Notification.objects.get(), notif)
def test_delete_user(self):
""" delete a user """
"""delete a user"""
self.assertTrue(models.User.objects.get(username="rat@example.com").is_active)
activity = {
"@context": "https://www.w3.org/ns/activitystreams",
@ -121,7 +121,7 @@ class InboxActivities(TestCase):
self.assertFalse(models.User.objects.get(username="rat@example.com").is_active)
def test_delete_user_unknown(self):
""" don't worry about it if we don't know the user """
"""don't worry about it if we don't know the user"""
self.assertEqual(models.User.objects.filter(is_active=True).count(), 2)
activity = {
"@context": "https://www.w3.org/ns/activitystreams",

View File

@ -9,10 +9,10 @@ from bookwyrm import models, views
# pylint: disable=too-many-public-methods
class InboxRelationships(TestCase):
""" inbox tests """
"""inbox tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -36,7 +36,7 @@ class InboxRelationships(TestCase):
models.SiteSettings.objects.create()
def test_follow(self):
""" remote user wants to follow local user """
"""remote user wants to follow local user"""
activity = {
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.com/users/rat/follows/123",
@ -65,7 +65,7 @@ class InboxRelationships(TestCase):
self.assertEqual(follow.user_subject, self.remote_user)
def test_follow_duplicate(self):
""" remote user wants to follow local user twice """
"""remote user wants to follow local user twice"""
activity = {
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.com/users/rat/follows/123",
@ -92,7 +92,7 @@ class InboxRelationships(TestCase):
self.assertEqual(follow.user_subject, self.remote_user)
def test_follow_manually_approved(self):
""" needs approval before following """
"""needs approval before following"""
activity = {
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.com/users/rat/follows/123",
@ -122,7 +122,7 @@ class InboxRelationships(TestCase):
self.assertEqual(list(follow), [])
def test_undo_follow_request(self):
""" the requester cancels a follow request """
"""the requester cancels a follow request"""
self.local_user.manually_approves_followers = True
self.local_user.save(broadcast=False)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
@ -152,7 +152,7 @@ class InboxRelationships(TestCase):
self.assertFalse(self.local_user.follower_requests.exists())
def test_unfollow(self):
""" remove a relationship """
"""remove a relationship"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
rel = models.UserFollows.objects.create(
user_subject=self.remote_user, user_object=self.local_user
@ -177,7 +177,7 @@ class InboxRelationships(TestCase):
self.assertIsNone(self.local_user.followers.first())
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.delay"):
rel = models.UserFollowRequest.objects.create(
user_subject=self.local_user, user_object=self.remote_user
@ -208,7 +208,7 @@ class InboxRelationships(TestCase):
self.assertEqual(follows.first(), self.local_user)
def test_follow_reject(self):
""" turn down a follow request """
"""turn down a follow request"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
rel = models.UserFollowRequest.objects.create(
user_subject=self.local_user, user_object=self.remote_user

View File

@ -8,10 +8,10 @@ from bookwyrm import models, views
# pylint: disable=too-many-public-methods
class InboxActivities(TestCase):
""" inbox tests """
"""inbox tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -50,7 +50,7 @@ class InboxActivities(TestCase):
models.SiteSettings.objects.create()
def test_handle_favorite(self):
""" fav a status """
"""fav a status"""
activity = {
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.com/fav/1",
@ -68,7 +68,7 @@ class InboxActivities(TestCase):
self.assertEqual(fav.user, self.remote_user)
def test_ignore_favorite(self):
""" don't try to save an unknown status """
"""don't try to save an unknown status"""
activity = {
"@context": "https://www.w3.org/ns/activitystreams",
"id": "https://example.com/fav/1",
@ -83,7 +83,7 @@ class InboxActivities(TestCase):
self.assertFalse(models.Favorite.objects.exists())
def test_handle_unfavorite(self):
""" fav a status """
"""fav a status"""
activity = {
"id": "https://example.com/fav/1#undo",
"type": "Undo",

View File

@ -8,10 +8,10 @@ from bookwyrm import models, views
# pylint: disable=too-many-public-methods
class InboxRemove(TestCase):
""" inbox tests """
"""inbox tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -41,7 +41,7 @@ class InboxRemove(TestCase):
models.SiteSettings.objects.create()
def test_handle_unshelve_book(self):
""" remove a book from a shelf """
"""remove a book from a shelf"""
shelf = models.Shelf.objects.create(user=self.remote_user, name="Test Shelf")
shelf.remote_id = "https://bookwyrm.social/user/mouse/shelf/to-read"
shelf.save()
@ -70,7 +70,7 @@ class InboxRemove(TestCase):
self.assertFalse(shelf.books.exists())
def test_handle_remove_book_from_list(self):
""" listing a book """
"""listing a book"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
booklist = models.List.objects.create(
name="test list",

View File

@ -10,10 +10,10 @@ from bookwyrm import models, views
# pylint: disable=too-many-public-methods
class InboxUpdate(TestCase):
""" inbox tests """
"""inbox tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
self.local_user = models.User.objects.create_user(
"mouse@example.com",
"mouse@mouse.com",
@ -45,7 +45,7 @@ class InboxUpdate(TestCase):
models.SiteSettings.objects.create()
def test_update_list(self):
""" a new list """
"""a new list"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
book_list = models.List.objects.create(
name="hi", remote_id="https://example.com/list/22", user=self.local_user
@ -79,7 +79,7 @@ class InboxUpdate(TestCase):
self.assertEqual(book_list.remote_id, "https://example.com/list/22")
def test_update_user(self):
""" update an existing user """
"""update an existing user"""
models.UserFollows.objects.create(
user_subject=self.local_user,
user_object=self.remote_user,
@ -116,7 +116,7 @@ class InboxUpdate(TestCase):
self.assertTrue(self.local_user in self.remote_user.followers.all())
def test_update_edition(self):
""" update an existing edition """
"""update an existing edition"""
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_edition.json")
bookdata = json.loads(datafile.read_bytes())
@ -146,7 +146,7 @@ class InboxUpdate(TestCase):
self.assertEqual(book.last_edited_by, self.remote_user)
def test_update_work(self):
""" update an existing edition """
"""update an existing edition"""
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_work.json")
bookdata = json.loads(datafile.read_bytes())