1
0
Fork 0

Merge branch 'bookwyrm-social:main' into url-names

This commit is contained in:
Vivianne 2022-04-08 21:45:37 -07:00 committed by GitHub
commit 5a2bf64864
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
135 changed files with 15863 additions and 3417 deletions

View file

@ -1 +1,2 @@
from . import *
""" import ALL the tests """
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -4,7 +4,10 @@ from bookwyrm import models
class Author(TestCase):
"""serialize author tests"""
def setUp(self):
"""initial data"""
self.book = models.Edition.objects.create(
title="Example Edition",
remote_id="https://example.com/book/1",
@ -16,6 +19,7 @@ class Author(TestCase):
)
def test_serialize_model(self):
"""check presense of author fields"""
activity = self.author.to_activity()
self.assertEqual(activity["id"], self.author.remote_id)
self.assertIsInstance(activity["aliases"], list)

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -90,7 +90,6 @@ class InitDB(TestCase):
self.assertEqual(Group.objects.count(), 3)
self.assertTrue(Permission.objects.exists())
self.assertEqual(models.Connector.objects.count(), 3)
self.assertEqual(models.FederatedServer.objects.count(), 2)
self.assertEqual(models.SiteSettings.objects.count(), 1)
self.assertEqual(models.LinkDomain.objects.count(), 5)
@ -102,7 +101,6 @@ class InitDB(TestCase):
# everything should have been called
self.assertEqual(Group.objects.count(), 3)
self.assertEqual(models.Connector.objects.count(), 0)
self.assertEqual(models.FederatedServer.objects.count(), 0)
self.assertEqual(models.SiteSettings.objects.count(), 0)
self.assertEqual(models.LinkDomain.objects.count(), 0)

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -38,7 +38,7 @@ class BaseModel(TestCase):
def test_remote_id(self):
"""these should be generated"""
self.test_model.id = 1
self.test_model.id = 1 # pylint: disable=invalid-name
expected = self.test_model.get_remote_id()
self.assertEqual(expected, f"https://{DOMAIN}/bookwyrmtestmodel/1")

View file

@ -162,6 +162,7 @@ class ModelFields(TestCase):
class TestActivity(ActivityObject):
"""real simple mock"""
# pylint: disable=invalid-name
to: List[str]
cc: List[str]
id: str = "http://hi.com"

View file

@ -17,7 +17,7 @@ class User(TestCase):
"bookwyrm.activitystreams.populate_stream_task.delay"
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.user = models.User.objects.create_user(
"mouse@%s" % DOMAIN,
f"mouse@{DOMAIN}",
"mouse@mouse.mouse",
"mouseword",
local=True,
@ -107,7 +107,7 @@ class User(TestCase):
def test_get_or_create_remote_server(self):
responses.add(
responses.GET,
"https://%s/.well-known/nodeinfo" % DOMAIN,
f"https://{DOMAIN}/.well-known/nodeinfo",
json={"links": [{"href": "http://www.example.com"}, {}]},
)
responses.add(
@ -124,7 +124,7 @@ class User(TestCase):
@responses.activate
def test_get_or_create_remote_server_no_wellknown(self):
responses.add(
responses.GET, "https://%s/.well-known/nodeinfo" % DOMAIN, status=404
responses.GET, f"https://{DOMAIN}/.well-known/nodeinfo", status=404
)
server = models.user.get_or_create_remote_server(DOMAIN)
@ -136,7 +136,7 @@ class User(TestCase):
def test_get_or_create_remote_server_no_links(self):
responses.add(
responses.GET,
"https://%s/.well-known/nodeinfo" % DOMAIN,
f"https://{DOMAIN}/.well-known/nodeinfo",
json={"links": [{"href": "http://www.example.com"}, {}]},
)
responses.add(responses.GET, "http://www.example.com", status=404)
@ -150,7 +150,7 @@ class User(TestCase):
def test_get_or_create_remote_server_unknown_format(self):
responses.add(
responses.GET,
"https://%s/.well-known/nodeinfo" % DOMAIN,
f"https://{DOMAIN}/.well-known/nodeinfo",
json={"links": [{"href": "http://www.example.com"}, {}]},
)
responses.add(responses.GET, "http://www.example.com", json={"fish": "salmon"})

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -64,8 +64,8 @@ class Signature(TestCase):
def send(self, signature, now, data, digest):
"""test request"""
c = Client()
return c.post(
client = Client()
return client.post(
urlsplit(self.rat.inbox).path,
data=data,
content_type="application/json",

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -60,7 +60,7 @@ class EditBookViews(TestCase):
def test_edit_book_create_page(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.EditBook.as_view()
view = views.CreateBook.as_view()
request = self.factory.get("")
request.user = self.local_user
request.user.is_superuser = True

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -61,7 +61,7 @@ class InboxActivities(TestCase):
self.assertEqual(models.Notification.objects.count(), 0)
activity = {
"type": "Announce",
"id": "%s/boost" % self.status.remote_id,
"id": f"{self.status.remote_id}/boost",
"actor": self.remote_user.remote_id,
"object": self.status.remote_id,
"to": ["https://www.w3.org/ns/activitystreams#public"],
@ -94,7 +94,7 @@ class InboxActivities(TestCase):
self.assertEqual(models.Notification.objects.count(), 0)
activity = {
"type": "Announce",
"id": "%s/boost" % self.status.remote_id,
"id": f"{self.status.remote_id}/boost",
"actor": self.remote_user.remote_id,
"object": "https://remote.com/status/1",
"to": ["https://www.w3.org/ns/activitystreams#public"],

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -360,10 +360,17 @@ class RegisterViews(TestCase):
result = view(request)
validate_html(result.render())
def test_resend_link(self, *_):
def test_resend_link_get(self, *_):
"""try again"""
request = self.factory.get("")
request.user = self.anonymous_user
result = views.ResendConfirmEmail.as_view()(request)
validate_html(result.render())
def test_resend_link_post(self, *_):
"""try again"""
request = self.factory.post("", {"email": "mouse@mouse.com"})
request.user = self.anonymous_user
with patch("bookwyrm.emailing.send_email.delay") as mock:
views.resend_link(request)
views.ResendConfirmEmail.as_view()(request)
self.assertEqual(mock.call_count, 1)

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import *
# pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -66,7 +66,7 @@ class AuthorViews(TestCase):
def test_author_page_edition_author(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.Author.as_view()
another_book = models.Edition.objects.create(
models.Edition.objects.create(
title="Example Edition",
remote_id="https://example.com/book/1",
parent_work=self.work,

View file

@ -0,0 +1,69 @@
""" test for app action functionality """
from unittest.mock import patch
from django.http import StreamingHttpResponse
from django.test import TestCase
from django.test.client import RequestFactory
from bookwyrm import models, views
from bookwyrm.tests.validate_html import validate_html
@patch("bookwyrm.activitystreams.add_book_statuses_task.delay")
@patch("bookwyrm.activitystreams.add_status_task.delay")
@patch("bookwyrm.activitystreams.populate_stream_task.delay")
@patch("bookwyrm.suggested_users.rerank_suggestions_task.delay")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
class ExportViews(TestCase):
"""viewing and creating statuses"""
def setUp(self):
"""we need basic test data and mocks"""
self.factory = RequestFactory()
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
"bookwyrm.activitystreams.populate_stream_task.delay"
):
self.local_user = models.User.objects.create_user(
"mouse@local.com",
"mouse@mouse.com",
"mouseword",
local=True,
localname="mouse",
remote_id="https://example.com/users/mouse",
)
self.work = models.Work.objects.create(title="Test Work")
self.book = models.Edition.objects.create(
title="Test Book",
remote_id="https://example.com/book/1",
parent_work=self.work,
isbn_13="9781234567890",
bnf_id="beep",
)
def tst_export_get(self, *_):
"""request export"""
request = self.factory.get("")
request.user = self.local_user
result = views.Export.as_view()(request)
validate_html(result.render())
def test_export_file(self, *_):
"""simple export"""
models.ShelfBook.objects.create(
shelf=self.local_user.shelf_set.first(),
user=self.local_user,
book=self.book,
)
request = self.factory.get("")
request.user = self.local_user
export = views.export_user_book_data(request)
self.assertIsInstance(export, StreamingHttpResponse)
self.assertEqual(export.status_code, 200)
result = list(export.streaming_content)
# pylint: disable=line-too-long
self.assertEqual(
result[0],
b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,isbn_10,isbn_13,oclc_number,rating,review_name,review_cw,review_content\r\n",
)
expected = f"Test Book,,{self.book.remote_id},,,,,beep,,,,123456789X,9781234567890,,,,,\r\n"
self.assertEqual(result[1].decode("utf-8"), expected)

View file

@ -139,7 +139,7 @@ class ViewsHelpers(TestCase):
}
responses.add(
responses.GET,
"https://example.com/.well-known/webfinger?resource=acct:%s" % username,
f"https://example.com/.well-known/webfinger?resource=acct:{username}",
json=wellknown,
status=200,
)

View file

@ -83,7 +83,7 @@ class UserViews(TestCase):
def test_user_page_domain(self):
"""when the user domain has dashes in it"""
with patch("bookwyrm.models.user.set_remote_server"):
self.remote_user = models.User.objects.create_user(
models.User.objects.create_user(
"nutria",
"",
"nutriaword",