1
0
Fork 0

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())

View file

@ -14,10 +14,10 @@ from bookwyrm.settings import DOMAIN
# pylint: disable=too-many-public-methods
class AuthenticationViews(TestCase):
""" login and password management """
"""login and password management"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -31,7 +31,7 @@ class AuthenticationViews(TestCase):
self.settings = models.SiteSettings.objects.create(id=1)
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()
request = self.factory.get("")
request.user = self.anonymous_user
@ -47,7 +47,7 @@ class AuthenticationViews(TestCase):
self.assertEqual(result.status_code, 302)
def test_register(self):
""" create a user """
"""create a user"""
view = views.Register.as_view()
self.assertEqual(models.User.objects.count(), 1)
request = self.factory.post(
@ -68,7 +68,7 @@ class AuthenticationViews(TestCase):
self.assertEqual(nutria.local, True)
def test_register_trailing_space(self):
""" django handles this so weirdly """
"""django handles this so weirdly"""
view = views.Register.as_view()
request = self.factory.post(
"register/",
@ -84,7 +84,7 @@ class AuthenticationViews(TestCase):
self.assertEqual(nutria.local, True)
def test_register_invalid_email(self):
""" gotta have an email """
"""gotta have an email"""
view = views.Register.as_view()
self.assertEqual(models.User.objects.count(), 1)
request = self.factory.post(
@ -95,7 +95,7 @@ class AuthenticationViews(TestCase):
response.render()
def test_register_invalid_username(self):
""" gotta have an email """
"""gotta have an email"""
view = views.Register.as_view()
self.assertEqual(models.User.objects.count(), 1)
request = self.factory.post(
@ -123,7 +123,7 @@ class AuthenticationViews(TestCase):
response.render()
def test_register_closed_instance(self):
""" you can't just register """
"""you can't just register"""
view = views.Register.as_view()
self.settings.allow_registration = False
self.settings.save()
@ -135,7 +135,7 @@ class AuthenticationViews(TestCase):
view(request)
def test_register_invite(self):
""" you can't just register """
"""you can't just register"""
view = views.Register.as_view()
self.settings.allow_registration = False
self.settings.save()

View file

@ -12,10 +12,10 @@ from bookwyrm.activitypub import ActivitypubResponse
class AuthorViews(TestCase):
""" author views"""
"""author views"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -42,7 +42,7 @@ class AuthorViews(TestCase):
models.SiteSettings.objects.create()
def test_author_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Author.as_view()
author = models.Author.objects.create(name="Jessica")
request = self.factory.get("")
@ -62,7 +62,7 @@ class AuthorViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_edit_author_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.EditAuthor.as_view()
author = models.Author.objects.create(name="Test Author")
request = self.factory.get("")
@ -76,7 +76,7 @@ class AuthorViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_edit_author(self):
""" edit an author """
"""edit an author"""
view = views.EditAuthor.as_view()
author = models.Author.objects.create(name="Test Author")
self.local_user.groups.add(self.group)
@ -93,7 +93,7 @@ class AuthorViews(TestCase):
self.assertEqual(author.last_edited_by, self.local_user)
def test_edit_author_non_editor(self):
""" edit an author with invalid post data"""
"""edit an author with invalid post data"""
view = views.EditAuthor.as_view()
author = models.Author.objects.create(name="Test Author")
form = forms.AuthorForm(instance=author)
@ -108,7 +108,7 @@ class AuthorViews(TestCase):
self.assertEqual(author.name, "Test Author")
def test_edit_author_invalid_form(self):
""" edit an author with invalid post data"""
"""edit an author with invalid post data"""
view = views.EditAuthor.as_view()
author = models.Author.objects.create(name="Test Author")
self.local_user.groups.add(self.group)

View file

@ -9,10 +9,10 @@ from bookwyrm import models, views
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
class BlockViews(TestCase):
""" view user and edit profile """
"""view user and edit profile"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -34,7 +34,7 @@ class BlockViews(TestCase):
models.SiteSettings.objects.create()
def test_block_get(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.Block.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -44,7 +44,7 @@ class BlockViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_block_post(self, _):
""" create a "block" database entry from an activity """
"""create a "block" database entry from an activity"""
view = views.Block.as_view()
self.local_user.followers.add(self.remote_user)
models.UserFollowRequest.objects.create(
@ -65,7 +65,7 @@ class BlockViews(TestCase):
self.assertFalse(models.UserFollowRequest.objects.exists())
def test_unblock(self, _):
""" undo a block """
"""undo a block"""
self.local_user.blocks.add(self.remote_user)
request = self.factory.post("")
request.user = self.local_user

View file

@ -18,10 +18,10 @@ from bookwyrm.activitypub import ActivitypubResponse
class BookViews(TestCase):
""" books books books """
"""books books books"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -81,7 +81,7 @@ class BookViews(TestCase):
)
def test_book_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Book.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -100,7 +100,7 @@ class BookViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_edit_book_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.EditBook.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -111,7 +111,7 @@ class BookViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_edit_book(self):
""" lets a user edit a book """
"""lets a user edit a book"""
view = views.EditBook.as_view()
self.local_user.groups.add(self.group)
form = forms.EditionForm(instance=self.book)
@ -125,7 +125,7 @@ class BookViews(TestCase):
self.assertEqual(self.book.title, "New Title")
def test_edit_book_add_author(self):
""" lets a user edit a book with new authors """
"""lets a user edit a book with new authors"""
view = views.EditBook.as_view()
self.local_user.groups.add(self.group)
form = forms.EditionForm(instance=self.book)
@ -143,7 +143,7 @@ class BookViews(TestCase):
self.assertEqual(self.book.title, "Example Edition")
def test_edit_book_add_new_author_confirm(self):
""" lets a user edit a book confirmed with new authors """
"""lets a user edit a book confirmed with new authors"""
view = views.ConfirmEditBook.as_view()
self.local_user.groups.add(self.group)
form = forms.EditionForm(instance=self.book)
@ -162,7 +162,7 @@ class BookViews(TestCase):
self.assertEqual(self.book.authors.first().name, "Sappho")
def test_edit_book_remove_author(self):
""" remove an author from a book """
"""remove an author from a book"""
author = models.Author.objects.create(name="Sappho")
self.book.authors.add(author)
form = forms.EditionForm(instance=self.book)
@ -182,7 +182,7 @@ class BookViews(TestCase):
self.assertFalse(self.book.authors.exists())
def test_create_book(self):
""" create an entirely new book and work """
"""create an entirely new book and work"""
view = views.ConfirmEditBook.as_view()
self.local_user.groups.add(self.group)
form = forms.EditionForm()
@ -196,7 +196,7 @@ class BookViews(TestCase):
self.assertEqual(book.parent_work.title, "New Title")
def test_create_book_existing_work(self):
""" create an entirely new book and work """
"""create an entirely new book and work"""
view = views.ConfirmEditBook.as_view()
self.local_user.groups.add(self.group)
form = forms.EditionForm()
@ -211,7 +211,7 @@ class BookViews(TestCase):
self.assertEqual(book.parent_work, self.work)
def test_create_book_with_author(self):
""" create an entirely new book and work """
"""create an entirely new book and work"""
view = views.ConfirmEditBook.as_view()
self.local_user.groups.add(self.group)
form = forms.EditionForm()
@ -229,7 +229,7 @@ class BookViews(TestCase):
self.assertEqual(book.authors.first(), book.parent_work.authors.first())
def test_switch_edition(self):
""" updates user's relationships to a book """
"""updates user's relationships to a book"""
work = models.Work.objects.create(title="test work")
edition1 = models.Edition.objects.create(title="first ed", parent_work=work)
edition2 = models.Edition.objects.create(title="second ed", parent_work=work)
@ -253,7 +253,7 @@ class BookViews(TestCase):
self.assertEqual(models.ReadThrough.objects.get().book, edition2)
def test_editions_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Editions.as_view()
request = self.factory.get("")
with patch("bookwyrm.views.books.is_api_request") as is_api:
@ -271,7 +271,7 @@ class BookViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_upload_cover_file(self):
""" add a cover via file upload """
"""add a cover via file upload"""
self.assertFalse(self.book.cover)
image_file = pathlib.Path(__file__).parent.joinpath(
"../../static/images/default_avi.jpg"
@ -296,7 +296,7 @@ class BookViews(TestCase):
@responses.activate
def test_upload_cover_url(self):
""" add a cover via url """
"""add a cover via url"""
self.assertFalse(self.book.cover)
image_file = pathlib.Path(__file__).parent.joinpath(
"../../static/images/default_avi.jpg"

View file

@ -7,10 +7,10 @@ from bookwyrm import models, views
# pylint: disable=unused-argument
class DirectoryViews(TestCase):
""" tag views"""
"""tag views"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -32,7 +32,7 @@ class DirectoryViews(TestCase):
models.SiteSettings.objects.create()
def test_directory_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Directory.as_view()
request = self.factory.get("")
request.user = self.local_user

View file

@ -10,10 +10,10 @@ from bookwyrm import forms, models, views
class FederationViews(TestCase):
""" every response to a get request, html or json """
"""every response to a get request, html or json"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -35,7 +35,7 @@ class FederationViews(TestCase):
models.SiteSettings.objects.create()
def test_federation_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Federation.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -46,7 +46,7 @@ class FederationViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_server_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
server = models.FederatedServer.objects.create(server_name="hi.there.com")
view = views.FederatedServer.as_view()
request = self.factory.get("")
@ -59,7 +59,7 @@ class FederationViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_server_page_block(self):
""" block a server """
"""block a server"""
server = models.FederatedServer.objects.create(server_name="hi.there.com")
self.remote_user.federated_server = server
self.remote_user.save()
@ -79,7 +79,7 @@ class FederationViews(TestCase):
self.assertFalse(self.remote_user.is_active)
def test_server_page_unblock(self):
""" unblock a server """
"""unblock a server"""
server = models.FederatedServer.objects.create(
server_name="hi.there.com", status="blocked"
)
@ -100,7 +100,7 @@ class FederationViews(TestCase):
self.assertTrue(self.remote_user.is_active)
def test_add_view_get(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
# create mode
view = views.AddFederatedServer.as_view()
request = self.factory.get("")
@ -113,7 +113,7 @@ class FederationViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_add_view_post_create(self):
""" create a server entry """
"""create a server entry"""
form = forms.ServerForm()
form.data["server_name"] = "remote.server"
form.data["application_type"] = "coolsoft"
@ -131,7 +131,7 @@ class FederationViews(TestCase):
self.assertEqual(server.status, "blocked")
def test_import_blocklist(self):
""" load a json file with a list of servers to block """
"""load a json file with a list of servers to block"""
server = models.FederatedServer.objects.create(server_name="hi.there.com")
self.remote_user.federated_server = server
self.remote_user.save()

View file

@ -17,10 +17,10 @@ from bookwyrm.activitypub import ActivitypubResponse
@patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream")
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
class FeedViews(TestCase):
""" activity feed, statuses, dms """
"""activity feed, statuses, dms"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -37,7 +37,7 @@ class FeedViews(TestCase):
models.SiteSettings.objects.create()
def test_feed(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.Feed.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -47,7 +47,7 @@ class FeedViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_status_page(self, *_):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Status.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
status = models.Status.objects.create(content="hi", user=self.local_user)
@ -67,7 +67,7 @@ class FeedViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_status_page_not_found(self, *_):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Status.as_view()
request = self.factory.get("")
@ -79,7 +79,7 @@ class FeedViews(TestCase):
self.assertEqual(result.status_code, 404)
def test_status_page_with_image(self, *_):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Status.as_view()
image_file = pathlib.Path(__file__).parent.joinpath(
@ -115,7 +115,7 @@ class FeedViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_replies_page(self, *_):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Replies.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
status = models.Status.objects.create(content="hi", user=self.local_user)
@ -135,7 +135,7 @@ class FeedViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_direct_messages_page(self, *_):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.DirectMessage.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -145,7 +145,7 @@ class FeedViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_get_suggested_book(self, *_):
""" gets books the ~*~ algorithm ~*~ thinks you want to post about """
"""gets books the ~*~ algorithm ~*~ thinks you want to post about"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.ShelfBook.objects.create(
book=self.book,

View file

@ -11,10 +11,10 @@ from bookwyrm import models, views
class BookViews(TestCase):
""" books books books """
"""books books books"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -50,7 +50,7 @@ class BookViews(TestCase):
)
def test_handle_follow_remote(self):
""" send a follow request """
"""send a follow request"""
request = self.factory.post("", {"user": self.remote_user.username})
request.user = self.local_user
self.assertEqual(models.UserFollowRequest.objects.count(), 0)
@ -65,7 +65,7 @@ class BookViews(TestCase):
self.assertEqual(rel.status, "follow_request")
def test_handle_follow_local_manually_approves(self):
""" send a follow request """
"""send a follow request"""
rat = models.User.objects.create_user(
"rat@local.com",
"rat@rat.com",
@ -88,7 +88,7 @@ class BookViews(TestCase):
self.assertEqual(rel.status, "follow_request")
def test_handle_follow_local(self):
""" send a follow request """
"""send a follow request"""
rat = models.User.objects.create_user(
"rat@local.com",
"rat@rat.com",
@ -111,7 +111,7 @@ class BookViews(TestCase):
self.assertEqual(rel.status, "follows")
def test_handle_unfollow(self):
""" send an unfollow """
"""send an unfollow"""
request = self.factory.post("", {"user": self.remote_user.username})
request.user = self.local_user
self.remote_user.followers.add(self.local_user)
@ -125,7 +125,7 @@ class BookViews(TestCase):
self.assertEqual(self.remote_user.followers.count(), 0)
def test_handle_accept(self):
""" accept a follow request """
"""accept a follow request"""
self.local_user.manually_approves_followers = True
self.local_user.save(broadcast=False)
request = self.factory.post("", {"user": self.remote_user.username})
@ -142,7 +142,7 @@ class BookViews(TestCase):
self.assertEqual(self.local_user.followers.first(), self.remote_user)
def test_handle_reject(self):
""" reject a follow request """
"""reject a follow request"""
self.local_user.manually_approves_followers = True
self.local_user.save(broadcast=False)
request = self.factory.post("", {"user": self.remote_user.username})

View file

@ -8,10 +8,10 @@ from bookwyrm import forms, models, views
class GetStartedViews(TestCase):
""" helping new users get oriented """
"""helping new users get oriented"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -31,7 +31,7 @@ class GetStartedViews(TestCase):
models.SiteSettings.objects.create()
def test_profile_view(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.GetStartedProfile.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -43,7 +43,7 @@ class GetStartedViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_profile_view_post(self):
""" save basic user details """
"""save basic user details"""
view = views.GetStartedProfile.as_view()
form = forms.LimitedEditUserForm(instance=self.local_user)
form.data["name"] = "New Name"
@ -61,7 +61,7 @@ class GetStartedViews(TestCase):
self.assertTrue(self.local_user.discoverable)
def test_books_view(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.GetStartedBooks.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -73,7 +73,7 @@ class GetStartedViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_books_view_with_query(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.GetStartedBooks.as_view()
request = self.factory.get("?query=Example")
request.user = self.local_user
@ -85,7 +85,7 @@ class GetStartedViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_books_view_post(self):
""" shelve some books """
"""shelve some books"""
view = views.GetStartedBooks.as_view()
data = {self.book.id: self.local_user.shelf_set.first().id}
request = self.factory.post("", data)
@ -103,7 +103,7 @@ class GetStartedViews(TestCase):
self.assertEqual(shelfbook.user, self.local_user)
def test_users_view(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.GetStartedUsers.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -115,7 +115,7 @@ class GetStartedViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_users_view_with_query(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.GetStartedUsers.as_view()
request = self.factory.get("?query=rat")
request.user = self.local_user

View file

@ -11,10 +11,10 @@ from bookwyrm import models, views
class GoalViews(TestCase):
""" viewing and creating statuses """
"""viewing and creating statuses"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -41,7 +41,7 @@ class GoalViews(TestCase):
models.SiteSettings.objects.create()
def test_goal_page_no_goal(self):
""" view a reading goal page for another's unset goal """
"""view a reading goal page for another's unset goal"""
view = views.Goal.as_view()
request = self.factory.get("")
request.user = self.rat
@ -50,7 +50,7 @@ class GoalViews(TestCase):
self.assertEqual(result.status_code, 404)
def test_goal_page_no_goal_self(self):
""" view a reading goal page for your own unset goal """
"""view a reading goal page for your own unset goal"""
view = views.Goal.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -60,7 +60,7 @@ class GoalViews(TestCase):
self.assertIsInstance(result, TemplateResponse)
def test_goal_page_anonymous(self):
""" can't view it without login """
"""can't view it without login"""
view = views.Goal.as_view()
request = self.factory.get("")
request.user = self.anonymous_user
@ -69,7 +69,7 @@ class GoalViews(TestCase):
self.assertEqual(result.status_code, 302)
def test_goal_page_public(self):
""" view a user's public goal """
"""view a user's public goal"""
models.ReadThrough.objects.create(
finish_date=timezone.now(),
user=self.local_user,
@ -91,7 +91,7 @@ class GoalViews(TestCase):
self.assertIsInstance(result, TemplateResponse)
def test_goal_page_private(self):
""" view a user's private goal """
"""view a user's private goal"""
models.AnnualGoal.objects.create(
user=self.local_user, year=2020, goal=15, privacy="followers"
)
@ -104,7 +104,7 @@ class GoalViews(TestCase):
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
def test_create_goal(self, _):
""" create a new goal """
"""create a new goal"""
view = views.Goal.as_view()
request = self.factory.post(
"",

View file

@ -13,10 +13,10 @@ from bookwyrm.settings import USER_AGENT
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
class ViewsHelpers(TestCase):
""" viewing and creating statuses """
"""viewing and creating statuses"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -53,12 +53,12 @@ class ViewsHelpers(TestCase):
)
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.work.id), self.book)
def test_get_user_from_username(self, _):
""" works for either localname or username """
"""works for either localname or username"""
self.assertEqual(
views.helpers.get_user_from_username(self.local_user, "mouse"),
self.local_user,
@ -71,7 +71,7 @@ class ViewsHelpers(TestCase):
views.helpers.get_user_from_username(self.local_user, "mojfse@example.com")
def test_is_api_request(self, _):
""" should it return html or json """
"""should it return html or json"""
request = self.factory.get("/path")
request.headers = {"Accept": "application/json"}
self.assertTrue(views.helpers.is_api_request(request))
@ -85,12 +85,12 @@ class ViewsHelpers(TestCase):
self.assertFalse(views.helpers.is_api_request(request))
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")
self.assertFalse(views.helpers.is_api_request(request))
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"})
self.assertFalse(views.helpers.is_bookwyrm_request(request))
@ -105,7 +105,7 @@ class ViewsHelpers(TestCase):
self.assertTrue(views.helpers.is_bookwyrm_request(request))
def test_existing_user(self, _):
""" simple database lookup by username """
"""simple database lookup by username"""
result = views.helpers.handle_remote_webfinger("@mouse@local.com")
self.assertEqual(result, self.local_user)
@ -117,7 +117,7 @@ class ViewsHelpers(TestCase):
@responses.activate
def test_load_user(self, _):
""" find a remote user using webfinger """
"""find a remote user using webfinger"""
username = "mouse@example.com"
wellknown = {
"subject": "acct:mouse@example.com",
@ -147,7 +147,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(result.username, "mouse@example.com")
def test_user_on_blocked_server(self, _):
""" find a remote user using webfinger """
"""find a remote user using webfinger"""
models.FederatedServer.objects.create(
server_name="example.com", status="blocked"
)
@ -156,7 +156,7 @@ class ViewsHelpers(TestCase):
self.assertIsNone(result)
def test_handle_reading_status_to_read(self, _):
""" posts shelve activities """
"""posts shelve activities"""
shelf = self.local_user.shelf_set.get(identifier="to-read")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
views.helpers.handle_reading_status(
@ -168,7 +168,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(status.content, "wants to read")
def test_handle_reading_status_reading(self, _):
""" posts shelve activities """
"""posts shelve activities"""
shelf = self.local_user.shelf_set.get(identifier="reading")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
views.helpers.handle_reading_status(
@ -180,7 +180,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(status.content, "started reading")
def test_handle_reading_status_read(self, _):
""" posts shelve activities """
"""posts shelve activities"""
shelf = self.local_user.shelf_set.get(identifier="read")
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
views.helpers.handle_reading_status(
@ -192,7 +192,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(status.content, "finished reading")
def test_handle_reading_status_other(self, _):
""" posts shelve activities """
"""posts shelve activities"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
views.helpers.handle_reading_status(
self.local_user, self.shelf, self.book, "public"
@ -200,7 +200,7 @@ class ViewsHelpers(TestCase):
self.assertFalse(models.GeneratedNote.objects.exists())
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(
"nutria@local.com",
"nutria@nutria.com",
@ -247,7 +247,7 @@ class ViewsHelpers(TestCase):
self.assertEqual(remote_user_annotated.shared_books, 0)
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(
"nutria@local.com",
"nutria@nutria.com",

View file

@ -9,10 +9,10 @@ from bookwyrm import views
class ImportViews(TestCase):
""" goodreads import views """
"""goodreads import views"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -24,7 +24,7 @@ class ImportViews(TestCase):
models.SiteSettings.objects.create()
def test_import_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Import.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -34,7 +34,7 @@ class ImportViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_import_status(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.ImportStatus.as_view()
import_job = models.ImportJob.objects.create(user=self.local_user)
request = self.factory.get("")
@ -47,7 +47,7 @@ class ImportViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_retry_import(self):
""" retry failed items """
"""retry failed items"""
view = views.ImportStatus.as_view()
import_job = models.ImportJob.objects.create(
user=self.local_user, privacy="unlisted"

View file

@ -9,10 +9,10 @@ from bookwyrm import models, views
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
class InteractionViews(TestCase):
""" viewing and creating statuses """
"""viewing and creating statuses"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -41,7 +41,7 @@ class InteractionViews(TestCase):
)
def test_favorite(self, _):
""" create and broadcast faving a status """
"""create and broadcast faving a status"""
view = views.Favorite.as_view()
request = self.factory.post("")
request.user = self.remote_user
@ -59,7 +59,7 @@ class InteractionViews(TestCase):
self.assertEqual(notification.related_user, self.remote_user)
def test_unfavorite(self, _):
""" unfav a status """
"""unfav a status"""
view = views.Unfavorite.as_view()
request = self.factory.post("")
request.user = self.remote_user
@ -76,7 +76,7 @@ class InteractionViews(TestCase):
self.assertEqual(models.Notification.objects.count(), 0)
def test_boost(self, _):
""" boost a status """
"""boost a status"""
view = views.Boost.as_view()
request = self.factory.post("")
request.user = self.remote_user
@ -98,7 +98,7 @@ class InteractionViews(TestCase):
self.assertEqual(notification.related_status, status)
def test_self_boost(self, _):
""" boost your own status """
"""boost your own status"""
view = views.Boost.as_view()
request = self.factory.post("")
request.user = self.local_user
@ -122,7 +122,7 @@ class InteractionViews(TestCase):
self.assertFalse(models.Notification.objects.exists())
def test_boost_unlisted(self, _):
""" boost a status """
"""boost a status"""
view = views.Boost.as_view()
request = self.factory.post("")
request.user = self.local_user
@ -137,7 +137,7 @@ class InteractionViews(TestCase):
self.assertEqual(boost.privacy, "unlisted")
def test_boost_private(self, _):
""" boost a status """
"""boost a status"""
view = views.Boost.as_view()
request = self.factory.post("")
request.user = self.local_user
@ -150,7 +150,7 @@ class InteractionViews(TestCase):
self.assertFalse(models.Boost.objects.exists())
def test_boost_twice(self, _):
""" boost a status """
"""boost a status"""
view = views.Boost.as_view()
request = self.factory.post("")
request.user = self.local_user
@ -162,7 +162,7 @@ class InteractionViews(TestCase):
self.assertEqual(models.Boost.objects.count(), 1)
def test_unboost(self, _):
""" undo a boost """
"""undo a boost"""
view = views.Unboost.as_view()
request = self.factory.post("")
request.user = self.remote_user

View file

@ -11,10 +11,10 @@ from bookwyrm import views
class InviteViews(TestCase):
""" every response to a get request, html or json """
"""every response to a get request, html or json"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -26,7 +26,7 @@ class InviteViews(TestCase):
models.SiteSettings.objects.create()
def test_invite_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Invite.as_view()
models.SiteInvite.objects.create(code="hi", user=self.local_user)
request = self.factory.get("")
@ -41,7 +41,7 @@ class InviteViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_manage_invites(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.ManageInvites.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -52,7 +52,7 @@ class InviteViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_invite_request(self):
""" request to join a server """
"""request to join a server"""
form = forms.InviteRequestForm()
form.data["email"] = "new@user.email"
@ -66,7 +66,7 @@ class InviteViews(TestCase):
self.assertEqual(req.email, "new@user.email")
def test_invite_request_email_taken(self):
""" request to join a server with an existing user email """
"""request to join a server with an existing user email"""
form = forms.InviteRequestForm()
form.data["email"] = "mouse@mouse.mouse"
@ -80,7 +80,7 @@ class InviteViews(TestCase):
self.assertFalse(models.InviteRequest.objects.exists())
def test_manage_invite_requests(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.ManageInviteRequests.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -98,7 +98,7 @@ class InviteViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_manage_invite_requests_send(self):
""" send an invite """
"""send an invite"""
req = models.InviteRequest.objects.create(email="fish@example.com")
view = views.ManageInviteRequests.as_view()
@ -113,7 +113,7 @@ class InviteViews(TestCase):
self.assertIsNotNone(req.invite)
def test_ignore_invite_request(self):
""" don't invite that jerk """
"""don't invite that jerk"""
req = models.InviteRequest.objects.create(email="fish@example.com")
view = views.ignore_invite_request

View file

@ -11,10 +11,10 @@ from bookwyrm.settings import DOMAIN
class IsbnViews(TestCase):
""" tag views"""
"""tag views"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -37,7 +37,7 @@ class IsbnViews(TestCase):
models.SiteSettings.objects.create()
def test_isbn_json_response(self):
""" searches local data only and returns book data in json format """
"""searches local data only and returns book data in json format"""
view = views.Isbn.as_view()
request = self.factory.get("")
with patch("bookwyrm.views.isbn.is_api_request") as is_api:

View file

@ -10,10 +10,10 @@ from bookwyrm import views
class LandingViews(TestCase):
""" pages you land on without really trying """
"""pages you land on without really trying"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -27,7 +27,7 @@ class LandingViews(TestCase):
models.SiteSettings.objects.create()
def test_home_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Home.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -43,7 +43,7 @@ class LandingViews(TestCase):
result.render()
def test_about_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.About.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -53,7 +53,7 @@ class LandingViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_discover(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.Discover.as_view()
request = self.factory.get("")
result = view(request)

View file

@ -12,10 +12,10 @@ from bookwyrm.activitypub import ActivitypubResponse
# pylint: disable=unused-argument
class ListViews(TestCase):
""" tag views"""
"""tag views"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -67,7 +67,7 @@ class ListViews(TestCase):
models.SiteSettings.objects.create()
def test_lists_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Lists.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.List.objects.create(name="Public list", user=self.local_user)
@ -90,7 +90,7 @@ class ListViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_lists_create(self):
""" create list view """
"""create list view"""
view = views.Lists.as_view()
request = self.factory.post(
"",
@ -118,7 +118,7 @@ class ListViews(TestCase):
self.assertEqual(new_list.curation, "open")
def test_list_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.List.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -153,7 +153,7 @@ class ListViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_list_edit(self):
""" edit a list """
"""edit a list"""
view = views.List.as_view()
request = self.factory.post(
"",
@ -185,7 +185,7 @@ class ListViews(TestCase):
self.assertEqual(self.list.curation, "curated")
def test_curate_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Curate.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.List.objects.create(name="Public list", user=self.local_user)
@ -205,7 +205,7 @@ class ListViews(TestCase):
self.assertEqual(result.status_code, 302)
def test_curate_approve(self):
""" approve a pending item """
"""approve a pending item"""
view = views.Curate.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
pending = models.ListItem.objects.create(
@ -240,7 +240,7 @@ class ListViews(TestCase):
self.assertTrue(pending.approved)
def test_curate_reject(self):
""" approve a pending item """
"""approve a pending item"""
view = views.Curate.as_view()
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
pending = models.ListItem.objects.create(
@ -266,7 +266,7 @@ class ListViews(TestCase):
self.assertFalse(models.ListItem.objects.exists())
def test_add_book(self):
""" put a book on a list """
"""put a book on a list"""
request = self.factory.post(
"",
{
@ -545,7 +545,7 @@ class ListViews(TestCase):
self.assertEqual(items[2].order, 3)
def test_add_book_outsider(self):
""" put a book on a list """
"""put a book on a list"""
self.list.curation = "open"
self.list.save(broadcast=False)
request = self.factory.post(
@ -571,7 +571,7 @@ class ListViews(TestCase):
self.assertTrue(item.approved)
def test_add_book_pending(self):
""" put a book on a list awaiting approval """
"""put a book on a list awaiting approval"""
self.list.curation = "curated"
self.list.save(broadcast=False)
request = self.factory.post(
@ -601,7 +601,7 @@ class ListViews(TestCase):
self.assertFalse(item.approved)
def test_add_book_self_curated(self):
""" put a book on a list automatically approved """
"""put a book on a list automatically approved"""
self.list.curation = "curated"
self.list.save(broadcast=False)
request = self.factory.post(
@ -627,7 +627,7 @@ class ListViews(TestCase):
self.assertTrue(item.approved)
def test_remove_book(self):
""" take an item off a list """
"""take an item off a list"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
item = models.ListItem.objects.create(
@ -651,7 +651,7 @@ class ListViews(TestCase):
self.assertFalse(self.list.listitem_set.exists())
def test_remove_book_unauthorized(self):
""" take an item off a list """
"""take an item off a list"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
item = models.ListItem.objects.create(
book_list=self.list, user=self.local_user, book=self.book, order=1

View file

@ -8,10 +8,10 @@ from bookwyrm import views
class NotificationViews(TestCase):
""" notifications """
"""notifications"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -23,7 +23,7 @@ class NotificationViews(TestCase):
models.SiteSettings.objects.create()
def test_notifications_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Notifications.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -33,7 +33,7 @@ class NotificationViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_clear_notifications(self):
""" erase notifications """
"""erase notifications"""
models.Notification.objects.create(
user=self.local_user, notification_type="FAVORITE"
)

View file

@ -13,10 +13,10 @@ from bookwyrm.settings import USER_AGENT
# pylint: disable=too-many-public-methods
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
class OutboxView(TestCase):
""" sends out activities """
"""sends out activities"""
def setUp(self):
""" we'll need some data """
"""we'll need some data"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -34,19 +34,19 @@ class OutboxView(TestCase):
)
def test_outbox(self, _):
""" returns user's statuses """
"""returns user's statuses"""
request = self.factory.get("")
result = views.Outbox.as_view()(request, "mouse")
self.assertIsInstance(result, JsonResponse)
def test_outbox_bad_method(self, _):
""" can't POST to outbox """
"""can't POST to outbox"""
request = self.factory.post("")
result = views.Outbox.as_view()(request, "mouse")
self.assertEqual(result.status_code, 405)
def test_outbox_unknown_user(self, _):
""" should 404 for unknown and remote users """
"""should 404 for unknown and remote users"""
request = self.factory.post("")
result = views.Outbox.as_view()(request, "beepboop")
self.assertEqual(result.status_code, 405)
@ -54,7 +54,7 @@ class OutboxView(TestCase):
self.assertEqual(result.status_code, 405)
def test_outbox_privacy(self, _):
""" don't show dms et cetera in outbox """
"""don't show dms et cetera in outbox"""
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
models.Status.objects.create(
content="PRIVATE!!", user=self.local_user, privacy="direct"
@ -77,7 +77,7 @@ class OutboxView(TestCase):
self.assertEqual(data["totalItems"], 2)
def test_outbox_filter(self, _):
""" if we only care about reviews, only get reviews """
"""if we only care about reviews, only get reviews"""
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
models.Review.objects.create(
content="look at this",
@ -103,7 +103,7 @@ class OutboxView(TestCase):
self.assertEqual(data["totalItems"], 1)
def test_outbox_bookwyrm_request_true(self, _):
""" should differentiate between bookwyrm and outside requests """
"""should differentiate between bookwyrm and outside requests"""
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
models.Review.objects.create(
name="hi",
@ -121,7 +121,7 @@ class OutboxView(TestCase):
self.assertEqual(data["orderedItems"][0]["type"], "Review")
def test_outbox_bookwyrm_request_false(self, _):
""" should differentiate between bookwyrm and outside requests """
"""should differentiate between bookwyrm and outside requests"""
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
models.Review.objects.create(
name="hi",

View file

@ -10,10 +10,10 @@ from bookwyrm import models, views
class PasswordViews(TestCase):
""" view user and edit profile """
"""view user and edit profile"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -27,7 +27,7 @@ class PasswordViews(TestCase):
models.SiteSettings.objects.create(id=1)
def test_password_reset_request(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.PasswordResetRequest.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -38,7 +38,7 @@ class PasswordViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_password_reset_request_post(self):
""" send 'em an email """
"""send 'em an email"""
request = self.factory.post("", {"email": "aa@bb.ccc"})
view = views.PasswordResetRequest.as_view()
resp = view(request)
@ -53,7 +53,7 @@ class PasswordViews(TestCase):
self.assertEqual(models.PasswordReset.objects.get().user, self.local_user)
def test_password_reset(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.PasswordReset.as_view()
code = models.PasswordReset.objects.create(user=self.local_user)
request = self.factory.get("")
@ -64,7 +64,7 @@ class PasswordViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_password_reset_post(self):
""" reset from code """
"""reset from code"""
view = views.PasswordReset.as_view()
code = models.PasswordReset.objects.create(user=self.local_user)
request = self.factory.post("", {"password": "hi", "confirm-password": "hi"})
@ -74,7 +74,7 @@ class PasswordViews(TestCase):
self.assertFalse(models.PasswordReset.objects.exists())
def test_password_reset_wrong_code(self):
""" reset from code """
"""reset from code"""
view = views.PasswordReset.as_view()
models.PasswordReset.objects.create(user=self.local_user)
request = self.factory.post("", {"password": "hi", "confirm-password": "hi"})
@ -83,7 +83,7 @@ class PasswordViews(TestCase):
self.assertTrue(models.PasswordReset.objects.exists())
def test_password_reset_mismatch(self):
""" reset from code """
"""reset from code"""
view = views.PasswordReset.as_view()
code = models.PasswordReset.objects.create(user=self.local_user)
request = self.factory.post("", {"password": "hi", "confirm-password": "hihi"})
@ -92,7 +92,7 @@ class PasswordViews(TestCase):
self.assertTrue(models.PasswordReset.objects.exists())
def test_password_change_get(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.ChangePassword.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -103,7 +103,7 @@ class PasswordViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_password_change(self):
""" change password """
"""change password"""
view = views.ChangePassword.as_view()
password_hash = self.local_user.password
request = self.factory.post("", {"password": "hi", "confirm-password": "hi"})
@ -113,7 +113,7 @@ class PasswordViews(TestCase):
self.assertNotEqual(self.local_user.password, password_hash)
def test_password_change_mismatch(self):
""" change password """
"""change password"""
view = views.ChangePassword.as_view()
password_hash = self.local_user.password
request = self.factory.post("", {"password": "hi", "confirm-password": "hihi"})

View file

@ -10,10 +10,10 @@ from bookwyrm import models, views
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
class ReadingViews(TestCase):
""" viewing and creating statuses """
"""viewing and creating statuses"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -41,7 +41,7 @@ class ReadingViews(TestCase):
)
def test_start_reading(self, _):
""" begin a book """
"""begin a book"""
shelf = self.local_user.shelf_set.get(identifier=models.Shelf.READING)
self.assertFalse(shelf.books.exists())
self.assertFalse(models.Status.objects.exists())
@ -72,7 +72,7 @@ class ReadingViews(TestCase):
self.assertEqual(readthrough.book, self.book)
def test_start_reading_reshelf(self, _):
""" begin a book """
"""begin a book"""
to_read_shelf = self.local_user.shelf_set.get(identifier=models.Shelf.TO_READ)
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.ShelfBook.objects.create(
@ -92,7 +92,7 @@ class ReadingViews(TestCase):
self.assertEqual(shelf.books.get(), self.book)
def test_finish_reading(self, _):
""" begin a book """
"""begin a book"""
shelf = self.local_user.shelf_set.get(identifier=models.Shelf.READ_FINISHED)
self.assertFalse(shelf.books.exists())
self.assertFalse(models.Status.objects.exists())
@ -128,7 +128,7 @@ class ReadingViews(TestCase):
self.assertEqual(readthrough.book, self.book)
def test_edit_readthrough(self, _):
""" adding dates to an ongoing readthrough """
"""adding dates to an ongoing readthrough"""
start = timezone.make_aware(dateutil.parser.parse("2021-01-03"))
readthrough = models.ReadThrough.objects.create(
book=self.book, user=self.local_user, start_date=start
@ -155,7 +155,7 @@ class ReadingViews(TestCase):
self.assertEqual(readthrough.book, self.book)
def test_delete_readthrough(self, _):
""" remove a readthrough """
"""remove a readthrough"""
readthrough = models.ReadThrough.objects.create(
book=self.book, user=self.local_user
)
@ -172,7 +172,7 @@ class ReadingViews(TestCase):
self.assertFalse(models.ReadThrough.objects.filter(id=readthrough.id).exists())
def test_create_readthrough(self, _):
""" adding new read dates """
"""adding new read dates"""
request = self.factory.post(
"",
{

View file

@ -9,10 +9,10 @@ from bookwyrm import models
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
class ReadThrough(TestCase):
""" readthrough tests """
"""readthrough tests"""
def setUp(self):
""" basic user and book data """
"""basic user and book data"""
self.client = Client()
self.work = models.Work.objects.create(title="Example Work")
@ -52,7 +52,7 @@ class ReadThrough(TestCase):
self.assertEqual(delay_mock.call_count, 1)
def test_create_progress_readthrough(self, delay_mock):
""" a readthrough with progress """
"""a readthrough with progress"""
self.assertEqual(self.edition.readthrough_set.count(), 0)
self.client.post(

View file

@ -7,10 +7,10 @@ from bookwyrm import forms, models, views
class ReportViews(TestCase):
""" every response to a get request, html or json """
"""every response to a get request, html or json"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -29,7 +29,7 @@ class ReportViews(TestCase):
models.SiteSettings.objects.create()
def test_reports_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Reports.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -41,7 +41,7 @@ class ReportViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_reports_page_with_data(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.Reports.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -54,7 +54,7 @@ class ReportViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_report_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Report.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -68,7 +68,7 @@ class ReportViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_report_comment(self):
""" comment on a report """
"""comment on a report"""
view = views.Report.as_view()
request = self.factory.post("", {"note": "hi"})
request.user = self.local_user
@ -83,7 +83,7 @@ class ReportViews(TestCase):
self.assertEqual(comment.report, report)
def test_make_report(self):
""" a user reports another user """
"""a user reports another user"""
form = forms.ReportForm()
form.data["reporter"] = self.local_user.id
form.data["user"] = self.rat.id
@ -97,7 +97,7 @@ class ReportViews(TestCase):
self.assertEqual(report.user, self.rat)
def test_resolve_report(self):
""" toggle report resolution status """
"""toggle report resolution status"""
report = models.Report.objects.create(reporter=self.local_user, user=self.rat)
self.assertFalse(report.resolved)
request = self.factory.post("")
@ -115,7 +115,7 @@ class ReportViews(TestCase):
self.assertFalse(report.resolved)
def test_suspend_user(self):
""" toggle whether a user is able to log in """
"""toggle whether a user is able to log in"""
self.assertTrue(self.rat.is_active)
request = self.factory.post("")
request.user = self.local_user

View file

@ -8,10 +8,10 @@ from bookwyrm.views import rss_feed
class RssFeedView(TestCase):
""" rss feed behaves as expected """
"""rss feed behaves as expected"""
def setUp(self):
""" test data """
"""test data"""
self.site = models.SiteSettings.objects.create()
self.user = models.User.objects.create_user(
@ -50,7 +50,7 @@ class RssFeedView(TestCase):
@patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream")
def test_rss_feed(self, _):
""" load an rss feed """
"""load an rss feed"""
view = rss_feed.RssFeed()
request = self.factory.get("/user/rss_user/rss")
request.user = self.user

View file

@ -13,10 +13,10 @@ from bookwyrm.settings import DOMAIN
class ShelfViews(TestCase):
""" tag views"""
"""tag views"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -38,7 +38,7 @@ class ShelfViews(TestCase):
models.SiteSettings.objects.create()
def test_search_json_response(self):
""" searches local data only and returns book data in json format """
"""searches local data only and returns book data in json format"""
view = views.Search.as_view()
# we need a connector for this, sorry
request = self.factory.get("", {"q": "Test Book"})
@ -53,11 +53,11 @@ class ShelfViews(TestCase):
self.assertEqual(data[0]["key"], "https://%s/book/%d" % (DOMAIN, self.book.id))
def test_search_html_response(self):
""" searches remote connectors """
"""searches remote connectors"""
view = views.Search.as_view()
class TestConnector(abstract_connector.AbstractMinimalConnector):
""" nothing added here """
"""nothing added here"""
def format_search_result(self, search_result):
pass
@ -106,7 +106,7 @@ class ShelfViews(TestCase):
)
def test_search_html_response_users(self):
""" searches remote connectors """
"""searches remote connectors"""
view = views.Search.as_view()
request = self.factory.get("", {"q": "mouse"})
request.user = self.local_user

View file

@ -11,10 +11,10 @@ from bookwyrm.activitypub import ActivitypubResponse
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
class ShelfViews(TestCase):
""" tag views"""
"""tag views"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -37,7 +37,7 @@ class ShelfViews(TestCase):
models.SiteSettings.objects.create()
def test_shelf_page(self, _):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Shelf.as_view()
shelf = self.local_user.shelf_set.first()
request = self.factory.get("")
@ -64,7 +64,7 @@ class ShelfViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_edit_shelf_privacy(self, _):
""" set name or privacy on shelf """
"""set name or privacy on shelf"""
view = views.Shelf.as_view()
shelf = self.local_user.shelf_set.get(identifier="to-read")
self.assertEqual(shelf.privacy, "public")
@ -84,7 +84,7 @@ class ShelfViews(TestCase):
self.assertEqual(shelf.privacy, "unlisted")
def test_edit_shelf_name(self, _):
""" change the name of an editable shelf """
"""change the name of an editable shelf"""
view = views.Shelf.as_view()
shelf = models.Shelf.objects.create(name="Test Shelf", user=self.local_user)
self.assertEqual(shelf.privacy, "public")
@ -101,7 +101,7 @@ class ShelfViews(TestCase):
self.assertEqual(shelf.identifier, "testshelf-%d" % shelf.id)
def test_edit_shelf_name_not_editable(self, _):
""" can't change the name of an non-editable shelf """
"""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")
self.assertEqual(shelf.privacy, "public")
@ -116,7 +116,7 @@ class ShelfViews(TestCase):
self.assertEqual(shelf.name, "To Read")
def test_handle_shelve(self, _):
""" shelve a book """
"""shelve a book"""
request = self.factory.post(
"", {"book": self.book.id, "shelf": self.shelf.identifier}
)
@ -134,7 +134,7 @@ class ShelfViews(TestCase):
self.assertEqual(self.shelf.books.get(), self.book)
def test_handle_shelve_to_read(self, _):
""" special behavior for the to-read shelf """
"""special behavior for the to-read shelf"""
shelf = models.Shelf.objects.get(identifier="to-read")
request = self.factory.post(
"", {"book": self.book.id, "shelf": shelf.identifier}
@ -147,7 +147,7 @@ class ShelfViews(TestCase):
self.assertEqual(shelf.books.get(), self.book)
def test_handle_shelve_reading(self, _):
""" special behavior for the reading shelf """
"""special behavior for the reading shelf"""
shelf = models.Shelf.objects.get(identifier="reading")
request = self.factory.post(
"", {"book": self.book.id, "shelf": shelf.identifier}
@ -160,7 +160,7 @@ class ShelfViews(TestCase):
self.assertEqual(shelf.books.get(), self.book)
def test_handle_shelve_read(self, _):
""" special behavior for the read shelf """
"""special behavior for the read shelf"""
shelf = models.Shelf.objects.get(identifier="read")
request = self.factory.post(
"", {"book": self.book.id, "shelf": shelf.identifier}
@ -173,7 +173,7 @@ class ShelfViews(TestCase):
self.assertEqual(shelf.books.get(), self.book)
def test_handle_unshelve(self, _):
""" remove a book from a shelf """
"""remove a book from a shelf"""
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
models.ShelfBook.objects.create(
book=self.book, user=self.local_user, shelf=self.shelf

View file

@ -10,10 +10,10 @@ from bookwyrm.settings import DOMAIN
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
class StatusViews(TestCase):
""" viewing and creating statuses """
"""viewing and creating statuses"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -43,7 +43,7 @@ class StatusViews(TestCase):
models.SiteSettings.objects.create()
def test_handle_status(self, _):
""" create a status """
"""create a status"""
view = views.CreateStatus.as_view()
form = forms.CommentForm(
{
@ -66,7 +66,7 @@ class StatusViews(TestCase):
self.assertEqual(status.book, self.book)
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()
user = models.User.objects.create_user(
"rat", "rat@rat.com", "password", local=True
@ -96,7 +96,7 @@ class StatusViews(TestCase):
self.assertEqual(models.Notification.objects.get().user, self.local_user)
def test_handle_status_mentions(self, _):
""" @mention a user in a post """
"""@mention a user in a post"""
view = views.CreateStatus.as_view()
user = models.User.objects.create_user(
"rat@%s" % DOMAIN, "rat@rat.com", "password", local=True, localname="rat"
@ -124,7 +124,7 @@ class StatusViews(TestCase):
)
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()
user = models.User.objects.create_user(
"rat", "rat@rat.com", "password", local=True, localname="rat"
@ -168,7 +168,7 @@ class StatusViews(TestCase):
self.assertTrue(self.local_user in reply.mention_users.all())
def test_delete_and_redraft(self, _):
""" delete and re-draft a status """
"""delete and re-draft a status"""
view = views.DeleteAndRedraft.as_view()
request = self.factory.post("")
request.user = self.local_user
@ -189,7 +189,7 @@ class StatusViews(TestCase):
self.assertTrue(status.deleted)
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()
request = self.factory.post("")
request.user = self.local_user
@ -209,7 +209,7 @@ class StatusViews(TestCase):
self.assertFalse(status.deleted)
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()
request = self.factory.post("")
request.user = self.local_user
@ -229,7 +229,7 @@ class StatusViews(TestCase):
self.assertFalse(status.deleted)
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(
"nutria@%s" % DOMAIN,
"nutria@nutria.com",
@ -275,7 +275,7 @@ class StatusViews(TestCase):
)
def test_format_links(self, _):
""" find and format urls into a tags """
"""find and format urls into a tags"""
url = "http://www.fish.com/"
self.assertEqual(
views.status.format_links(url), '<a href="%s">www.fish.com/</a>' % url
@ -298,7 +298,7 @@ class StatusViews(TestCase):
)
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>"
result = views.status.to_markdown(text)
self.assertEqual(
@ -307,13 +307,13 @@ class StatusViews(TestCase):
)
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>"
result = views.status.to_markdown(text)
self.assertEqual(result, '<p><a href="http://fish.com">hi</a> ' "is rad</p>")
def test_handle_delete_status(self, mock):
""" marks a status as deleted """
"""marks a status as deleted"""
view = views.DeleteStatus.as_view()
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
status = models.Status.objects.create(user=self.local_user, content="hi")
@ -333,7 +333,7 @@ class StatusViews(TestCase):
self.assertTrue(status.deleted)
def test_handle_delete_status_permission_denied(self, _):
""" marks a status as deleted """
"""marks a status as deleted"""
view = views.DeleteStatus.as_view()
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
status = models.Status.objects.create(user=self.local_user, content="hi")
@ -347,7 +347,7 @@ class StatusViews(TestCase):
self.assertFalse(status.deleted)
def test_handle_delete_status_moderator(self, mock):
""" marks a status as deleted """
"""marks a status as deleted"""
view = views.DeleteStatus.as_view()
with patch("bookwyrm.activitystreams.ActivityStream.add_status"):
status = models.Status.objects.create(user=self.local_user, content="hi")

View file

@ -10,10 +10,10 @@ from bookwyrm import models, views
class UpdateViews(TestCase):
""" lets the ui check for unread notification """
"""lets the ui check for unread notification"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -25,7 +25,7 @@ class UpdateViews(TestCase):
models.SiteSettings.objects.create()
def test_get_notification_count(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
request = self.factory.get("")
request.user = self.local_user
@ -43,7 +43,7 @@ class UpdateViews(TestCase):
self.assertEqual(data["count"], 1)
def test_get_unread_status_count(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
request = self.factory.get("")
request.user = self.local_user

View file

@ -15,10 +15,10 @@ from bookwyrm.activitypub import ActivitypubResponse
class UserViews(TestCase):
""" view user and edit profile """
"""view user and edit profile"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -43,7 +43,7 @@ class UserViews(TestCase):
self.anonymous_user.is_authenticated = False
def test_user_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.User.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -69,7 +69,7 @@ class UserViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_user_page_blocked(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.User.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -80,7 +80,7 @@ class UserViews(TestCase):
self.assertEqual(result.status_code, 404)
def test_followers_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Followers.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -98,7 +98,7 @@ class UserViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_followers_page_blocked(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.Followers.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -109,7 +109,7 @@ class UserViews(TestCase):
self.assertEqual(result.status_code, 404)
def test_following_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.Following.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -127,7 +127,7 @@ class UserViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_following_page_blocked(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.Following.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -138,7 +138,7 @@ class UserViews(TestCase):
self.assertEqual(result.status_code, 404)
def test_edit_user_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.EditUser.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -148,7 +148,7 @@ class UserViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_edit_user(self):
""" use a form to update a user """
"""use a form to update a user"""
view = views.EditUser.as_view()
form = forms.EditUserForm(instance=self.local_user)
form.data["name"] = "New Name"
@ -168,7 +168,7 @@ class UserViews(TestCase):
# idk how to mock the upload form, got tired of triyng to make it work
def test_edit_user_avatar(self):
""" use a form to update a user """
"""use a form to update a user"""
view = views.EditUser.as_view()
form = forms.EditUserForm(instance=self.local_user)
form.data["name"] = "New Name"
@ -195,7 +195,7 @@ class UserViews(TestCase):
self.assertEqual(self.local_user.avatar.height, 120)
def test_crop_avatar(self):
""" reduce that image size """
"""reduce that image size"""
image_file = pathlib.Path(__file__).parent.joinpath(
"../../static/images/no_cover.jpg"
)

View file

@ -9,10 +9,10 @@ from bookwyrm import models, views
class UserAdminViews(TestCase):
""" every response to a get request, html or json """
"""every response to a get request, html or json"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -24,7 +24,7 @@ class UserAdminViews(TestCase):
models.SiteSettings.objects.create()
def test_user_admin_list_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.UserAdminList.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -35,7 +35,7 @@ class UserAdminViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_user_admin_page(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
view = views.UserAdmin.as_view()
request = self.factory.get("")
request.user = self.local_user
@ -48,7 +48,7 @@ class UserAdminViews(TestCase):
self.assertEqual(result.status_code, 200)
def test_user_admin_page_post(self):
""" set the user's group """
"""set the user's group"""
group = Group.objects.create(name="editor")
self.assertEqual(
list(self.local_user.groups.values_list("name", flat=True)), []

View file

@ -11,10 +11,10 @@ from bookwyrm import models, views
class UserViews(TestCase):
""" view user and edit profile """
"""view user and edit profile"""
def setUp(self):
""" we need basic test data and mocks """
"""we need basic test data and mocks"""
self.factory = RequestFactory()
self.local_user = models.User.objects.create_user(
"mouse@local.com",
@ -41,7 +41,7 @@ class UserViews(TestCase):
self.anonymous_user.is_authenticated = False
def test_webfinger(self):
""" there are so many views, this just makes sure it LOADS """
"""there are so many views, this just makes sure it LOADS"""
request = self.factory.get("", {"resource": "acct:mouse@local.com"})
request.user = self.anonymous_user
@ -51,7 +51,7 @@ class UserViews(TestCase):
self.assertEqual(data["subject"], "acct:mouse@local.com")
def test_nodeinfo_pointer(self):
""" just tells you where nodeinfo is """
"""just tells you where nodeinfo is"""
request = self.factory.get("")
request.user = self.anonymous_user
@ -61,7 +61,7 @@ class UserViews(TestCase):
self.assertTrue("href" in data["links"][0])
def test_nodeinfo(self):
""" info about the instance """
"""info about the instance"""
request = self.factory.get("")
request.user = self.anonymous_user
@ -73,7 +73,7 @@ class UserViews(TestCase):
self.assertEqual(models.User.objects.count(), 3)
def test_instanceinfo(self):
""" about the instance's user activity """
"""about the instance's user activity"""
request = self.factory.get("")
request.user = self.anonymous_user