Merge branch 'main' into bookwyrm-groups
There are database migrations in main ahead of this branch so they need to be merged in to the branch before we can merge back into main.
This commit is contained in:
@ -58,6 +58,17 @@ class EditBookViews(TestCase):
|
||||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_edit_book_create_page(self):
|
||||
"""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
|
||||
request.user.is_superuser = True
|
||||
result = view(request)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_edit_book(self):
|
||||
"""lets a user edit a book"""
|
||||
view = views.EditBook.as_view()
|
||||
|
@ -37,9 +37,9 @@ class InboxUpdate(TestCase):
|
||||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
self.create_json = {
|
||||
self.update_json = {
|
||||
"id": "hi",
|
||||
"type": "Create",
|
||||
"type": "Update",
|
||||
"actor": "hi",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#public"],
|
||||
"cc": ["https://example.com/user/mouse/followers"],
|
||||
@ -54,26 +54,20 @@ class InboxUpdate(TestCase):
|
||||
book_list = models.List.objects.create(
|
||||
name="hi", remote_id="https://example.com/list/22", user=self.local_user
|
||||
)
|
||||
activity = {
|
||||
"type": "Update",
|
||||
"to": [],
|
||||
"cc": [],
|
||||
"actor": "hi",
|
||||
"id": "sdkjf",
|
||||
"object": {
|
||||
"id": "https://example.com/list/22",
|
||||
"type": "BookList",
|
||||
"totalItems": 1,
|
||||
"first": "https://example.com/list/22?page=1",
|
||||
"last": "https://example.com/list/22?page=1",
|
||||
"name": "Test List",
|
||||
"owner": "https://example.com/user/mouse",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc": ["https://example.com/user/mouse/followers"],
|
||||
"summary": "summary text",
|
||||
"curation": "curated",
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
},
|
||||
activity = self.update_json
|
||||
activity["object"] = {
|
||||
"id": "https://example.com/list/22",
|
||||
"type": "BookList",
|
||||
"totalItems": 1,
|
||||
"first": "https://example.com/list/22?page=1",
|
||||
"last": "https://example.com/list/22?page=1",
|
||||
"name": "Test List",
|
||||
"owner": "https://example.com/user/mouse",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc": ["https://example.com/user/mouse/followers"],
|
||||
"summary": "summary text",
|
||||
"curation": "curated",
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
}
|
||||
views.inbox.activity_task(activity)
|
||||
book_list.refresh_from_db()
|
||||
@ -176,3 +170,26 @@ class InboxUpdate(TestCase):
|
||||
)
|
||||
book = models.Work.objects.get(id=book.id)
|
||||
self.assertEqual(book.title, "Piranesi")
|
||||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
||||
def test_update_status(self, *_):
|
||||
"""edit a status"""
|
||||
status = models.Status.objects.create(user=self.remote_user, content="hi")
|
||||
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../../data/ap_note.json")
|
||||
status_data = json.loads(datafile.read_bytes())
|
||||
status_data["id"] = status.remote_id
|
||||
status_data["updated"] = "2021-12-13T05:09:29Z"
|
||||
|
||||
activity = self.update_json
|
||||
activity["object"] = status_data
|
||||
|
||||
with patch("bookwyrm.activitypub.base_activity.set_related_field.delay"):
|
||||
views.inbox.activity_task(activity)
|
||||
|
||||
status.refresh_from_db()
|
||||
self.assertEqual(status.content, "test content in note")
|
||||
self.assertEqual(status.edited_date.year, 2021)
|
||||
self.assertEqual(status.edited_date.month, 12)
|
||||
self.assertEqual(status.edited_date.day, 13)
|
||||
|
@ -9,6 +9,7 @@ from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import forms, models, views
|
||||
from bookwyrm.activitypub import ActivitypubResponse
|
||||
from bookwyrm.tests.validate_html import validate_html
|
||||
|
||||
|
||||
class AuthorViews(TestCase):
|
||||
@ -54,7 +55,7 @@ class AuthorViews(TestCase):
|
||||
is_api.return_value = False
|
||||
result = view(request, author.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
@ -75,7 +76,7 @@ class AuthorViews(TestCase):
|
||||
|
||||
result = view(request, author.id)
|
||||
self.assertIsInstance(result, TemplateResponse)
|
||||
result.render()
|
||||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
@ -7,6 +7,7 @@ from django.test.client import RequestFactory
|
||||
|
||||
from bookwyrm import forms, models, views
|
||||
from bookwyrm.settings import DOMAIN
|
||||
from bookwyrm.tests.validate_html import validate_html
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
@ -50,7 +51,7 @@ class StatusViews(TestCase):
|
||||
)
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_handle_status(self, *_):
|
||||
def test_create_status_comment(self, *_):
|
||||
"""create a status"""
|
||||
view = views.CreateStatus.as_view()
|
||||
form = forms.CommentForm(
|
||||
@ -67,11 +68,13 @@ class StatusViews(TestCase):
|
||||
view(request, "comment")
|
||||
|
||||
status = models.Comment.objects.get()
|
||||
self.assertEqual(status.raw_content, "hi")
|
||||
self.assertEqual(status.content, "<p>hi</p>")
|
||||
self.assertEqual(status.user, self.local_user)
|
||||
self.assertEqual(status.book, self.book)
|
||||
self.assertIsNone(status.edited_date)
|
||||
|
||||
def test_handle_status_reply(self, *_):
|
||||
def test_create_status_reply(self, *_):
|
||||
"""create a status in reply to an existing status"""
|
||||
view = views.CreateStatus.as_view()
|
||||
user = models.User.objects.create_user(
|
||||
@ -98,7 +101,7 @@ class StatusViews(TestCase):
|
||||
self.assertEqual(status.user, user)
|
||||
self.assertEqual(models.Notification.objects.get().user, self.local_user)
|
||||
|
||||
def test_handle_status_mentions(self, *_):
|
||||
def test_create_status_mentions(self, *_):
|
||||
"""@mention a user in a post"""
|
||||
view = views.CreateStatus.as_view()
|
||||
user = models.User.objects.create_user(
|
||||
@ -128,7 +131,7 @@ class StatusViews(TestCase):
|
||||
status.content, f'<p>hi <a href="{user.remote_id}">@rat</a></p>'
|
||||
)
|
||||
|
||||
def test_handle_status_reply_with_mentions(self, *_):
|
||||
def test_create_status_reply_with_mentions(self, *_):
|
||||
"""reply to a post with an @mention'ed user"""
|
||||
view = views.CreateStatus.as_view()
|
||||
user = models.User.objects.create_user(
|
||||
@ -168,60 +171,6 @@ class StatusViews(TestCase):
|
||||
self.assertFalse(self.remote_user in reply.mention_users.all())
|
||||
self.assertTrue(self.local_user in reply.mention_users.all())
|
||||
|
||||
def test_delete_and_redraft(self, *_):
|
||||
"""delete and re-draft a status"""
|
||||
view = views.DeleteAndRedraft.as_view()
|
||||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
status = models.Comment.objects.create(
|
||||
content="hi", book=self.book, user=self.local_user
|
||||
)
|
||||
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as mock:
|
||||
result = view(request, status.id)
|
||||
self.assertTrue(mock.called)
|
||||
result.render()
|
||||
|
||||
# make sure it was deleted
|
||||
status.refresh_from_db()
|
||||
self.assertTrue(status.deleted)
|
||||
|
||||
def test_delete_and_redraft_invalid_status_type_rating(self, *_):
|
||||
"""you can't redraft generated statuses"""
|
||||
view = views.DeleteAndRedraft.as_view()
|
||||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
status = models.ReviewRating.objects.create(
|
||||
book=self.book, rating=2.0, user=self.local_user
|
||||
)
|
||||
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as mock:
|
||||
with self.assertRaises(PermissionDenied):
|
||||
view(request, status.id)
|
||||
self.assertFalse(mock.called)
|
||||
|
||||
status.refresh_from_db()
|
||||
self.assertFalse(status.deleted)
|
||||
|
||||
def test_delete_and_redraft_invalid_status_type_generated_note(self, *_):
|
||||
"""you can't redraft generated statuses"""
|
||||
view = views.DeleteAndRedraft.as_view()
|
||||
request = self.factory.post("")
|
||||
request.user = self.local_user
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
status = models.GeneratedNote.objects.create(
|
||||
content="hi", user=self.local_user
|
||||
)
|
||||
|
||||
with patch("bookwyrm.activitystreams.remove_status_task.delay") as mock:
|
||||
with self.assertRaises(PermissionDenied):
|
||||
view(request, status.id)
|
||||
self.assertFalse(mock.called)
|
||||
|
||||
status.refresh_from_db()
|
||||
self.assertFalse(status.deleted)
|
||||
|
||||
def test_find_mentions(self, *_):
|
||||
"""detect and look up @ mentions of users"""
|
||||
user = models.User.objects.create_user(
|
||||
@ -349,7 +298,7 @@ http://www.fish.com/"""
|
||||
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, *_):
|
||||
def test_delete_status(self, mock, *_):
|
||||
"""marks a status as deleted"""
|
||||
view = views.DeleteStatus.as_view()
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
@ -367,7 +316,7 @@ http://www.fish.com/"""
|
||||
status.refresh_from_db()
|
||||
self.assertTrue(status.deleted)
|
||||
|
||||
def test_handle_delete_status_permission_denied(self, *_):
|
||||
def test_delete_status_permission_denied(self, *_):
|
||||
"""marks a status as deleted"""
|
||||
view = views.DeleteStatus.as_view()
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
@ -382,7 +331,7 @@ http://www.fish.com/"""
|
||||
status.refresh_from_db()
|
||||
self.assertFalse(status.deleted)
|
||||
|
||||
def test_handle_delete_status_moderator(self, mock, *_):
|
||||
def test_delete_status_moderator(self, mock, *_):
|
||||
"""marks a status as deleted"""
|
||||
view = views.DeleteStatus.as_view()
|
||||
with patch("bookwyrm.activitystreams.add_status_task.delay"):
|
||||
@ -400,3 +349,75 @@ http://www.fish.com/"""
|
||||
self.assertEqual(activity["object"]["type"], "Tombstone")
|
||||
status.refresh_from_db()
|
||||
self.assertTrue(status.deleted)
|
||||
|
||||
def test_edit_status_get(self, *_):
|
||||
"""load the edit status view"""
|
||||
view = views.EditStatus.as_view()
|
||||
status = models.Comment.objects.create(
|
||||
content="status", user=self.local_user, book=self.book
|
||||
)
|
||||
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
result = view(request, status.id)
|
||||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_edit_status_get_reply(self, *_):
|
||||
"""load the edit status view"""
|
||||
view = views.EditStatus.as_view()
|
||||
parent = models.Comment.objects.create(
|
||||
content="parent status", user=self.local_user, book=self.book
|
||||
)
|
||||
status = models.Status.objects.create(
|
||||
content="reply", user=self.local_user, reply_parent=parent
|
||||
)
|
||||
|
||||
request = self.factory.get("")
|
||||
request.user = self.local_user
|
||||
result = view(request, status.id)
|
||||
validate_html(result.render())
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
def test_edit_status_success(self, mock, *_):
|
||||
"""update an existing status"""
|
||||
status = models.Status.objects.create(content="status", user=self.local_user)
|
||||
self.assertIsNone(status.edited_date)
|
||||
view = views.CreateStatus.as_view()
|
||||
form = forms.CommentForm(
|
||||
{
|
||||
"content": "hi",
|
||||
"user": self.local_user.id,
|
||||
"book": self.book.id,
|
||||
"privacy": "public",
|
||||
}
|
||||
)
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.local_user
|
||||
|
||||
view(request, "comment", existing_status_id=status.id)
|
||||
activity = json.loads(mock.call_args_list[1][0][1])
|
||||
self.assertEqual(activity["type"], "Update")
|
||||
self.assertEqual(activity["object"]["id"], status.remote_id)
|
||||
|
||||
status.refresh_from_db()
|
||||
self.assertEqual(status.content, "<p>hi</p>")
|
||||
self.assertIsNotNone(status.edited_date)
|
||||
|
||||
def test_edit_status_permission_denied(self, *_):
|
||||
"""update an existing status"""
|
||||
status = models.Status.objects.create(content="status", user=self.local_user)
|
||||
view = views.CreateStatus.as_view()
|
||||
form = forms.CommentForm(
|
||||
{
|
||||
"content": "hi",
|
||||
"user": self.local_user.id,
|
||||
"book": self.book.id,
|
||||
"privacy": "public",
|
||||
}
|
||||
)
|
||||
request = self.factory.post("", form.data)
|
||||
request.user = self.remote_user
|
||||
|
||||
with self.assertRaises(PermissionDenied):
|
||||
view(request, "comment", existing_status_id=status.id)
|
||||
|
Reference in New Issue
Block a user