Merge from main for up-to-date migrations
This commit is contained in:
commit
e928027e16
99 changed files with 1889 additions and 758 deletions
|
@ -119,6 +119,25 @@ class ActivitypubMixins(TestCase):
|
|||
result = models.Edition.find_existing({"openlibraryKey": "OL1234"})
|
||||
self.assertEqual(result, book)
|
||||
|
||||
def test_find_existing_with_id(self, *_):
|
||||
"""make sure that an "id" field won't produce a match"""
|
||||
book = models.Edition.objects.create(title="Test edition")
|
||||
|
||||
result = models.Edition.find_existing({"id": book.id})
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_find_existing_with_id_and_match(self, *_):
|
||||
"""make sure that an "id" field won't produce a match"""
|
||||
book = models.Edition.objects.create(title="Test edition")
|
||||
matching_book = models.Edition.objects.create(
|
||||
title="Another test edition", openlibrary_key="OL1234"
|
||||
)
|
||||
|
||||
result = models.Edition.find_existing(
|
||||
{"id": book.id, "openlibraryKey": "OL1234"}
|
||||
)
|
||||
self.assertEqual(result, matching_book)
|
||||
|
||||
def test_get_recipients_public_object(self, *_):
|
||||
"""determines the recipients for an object's broadcast"""
|
||||
MockSelf = namedtuple("Self", ("privacy"))
|
||||
|
|
|
@ -11,7 +11,7 @@ from django.test import TestCase
|
|||
from django.utils import timezone
|
||||
|
||||
from bookwyrm import models, settings
|
||||
from bookwyrm.models.book import isbn_10_to_13, isbn_13_to_10
|
||||
from bookwyrm.models.book import isbn_10_to_13, isbn_13_to_10, normalize_isbn
|
||||
from bookwyrm.settings import ENABLE_THUMBNAIL_GENERATION
|
||||
|
||||
|
||||
|
@ -72,6 +72,10 @@ class Book(TestCase):
|
|||
isbn_10 = isbn_13_to_10(isbn_13)
|
||||
self.assertEqual(isbn_10, "178816167X")
|
||||
|
||||
def test_normalize_isbn(self):
|
||||
"""Remove misc characters from ISBNs"""
|
||||
self.assertEqual(normalize_isbn("978-0-4633461-1-2"), "9780463346112")
|
||||
|
||||
def test_get_edition_info(self):
|
||||
"""text slug about an edition"""
|
||||
book = models.Edition.objects.create(title="Test Edition")
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
""" testing models """
|
||||
import json
|
||||
|
||||
from unittest.mock import patch
|
||||
from django.contrib.auth.models import Group
|
||||
from django.db import IntegrityError
|
||||
from django.test import TestCase
|
||||
import responses
|
||||
|
||||
|
@ -9,9 +11,11 @@ from bookwyrm import models
|
|||
from bookwyrm.management.commands import initdb
|
||||
from bookwyrm.settings import USE_HTTPS, DOMAIN
|
||||
|
||||
|
||||
# pylint: disable=missing-class-docstring
|
||||
# pylint: disable=missing-function-docstring
|
||||
class User(TestCase):
|
||||
|
||||
protocol = "https://" if USE_HTTPS else "http://"
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
|
@ -26,6 +30,7 @@ class User(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
name="hi",
|
||||
summary="a summary",
|
||||
bookwyrm_user=False,
|
||||
)
|
||||
self.another_user = models.User.objects.create_user(
|
||||
|
@ -88,9 +93,11 @@ class User(TestCase):
|
|||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"schema": "http://schema.org#",
|
||||
"PropertyValue": "schema:PropertyValue",
|
||||
"alsoKnownAs": {"@id": "as:alsoKnownAs", "@type": "@id"},
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"movedTo": {"@id": "as:movedTo", "@type": "@id"},
|
||||
"schema": "http://schema.org#",
|
||||
"value": "schema:value",
|
||||
},
|
||||
],
|
||||
|
@ -216,19 +223,71 @@ class User(TestCase):
|
|||
|
||||
@patch("bookwyrm.suggested_users.remove_user_task.delay")
|
||||
def test_delete_user(self, _):
|
||||
"""deactivate a user"""
|
||||
"""permanently delete a user"""
|
||||
self.assertTrue(self.user.is_active)
|
||||
self.assertEqual(self.user.name, "hi")
|
||||
self.assertEqual(self.user.summary, "a summary")
|
||||
self.assertEqual(self.user.email, "mouse@mouse.mouse")
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"
|
||||
) as broadcast_mock:
|
||||
) as broadcast_mock, patch(
|
||||
"bookwyrm.models.user.User.erase_user_statuses"
|
||||
) as erase_statuses_mock:
|
||||
self.user.delete()
|
||||
|
||||
self.assertEqual(erase_statuses_mock.call_count, 1)
|
||||
|
||||
# make sure the deletion is broadcast
|
||||
self.assertEqual(broadcast_mock.call_count, 1)
|
||||
activity = json.loads(broadcast_mock.call_args[1]["args"][1])
|
||||
self.assertEqual(activity["type"], "Delete")
|
||||
self.assertEqual(activity["object"], self.user.remote_id)
|
||||
|
||||
self.user.refresh_from_db()
|
||||
|
||||
# the user's account data should be deleted
|
||||
self.assertIsNone(self.user.name)
|
||||
self.assertIsNone(self.user.summary)
|
||||
self.assertNotEqual(self.user.email, "mouse@mouse.mouse")
|
||||
self.assertFalse(self.user.is_active)
|
||||
|
||||
@patch("bookwyrm.suggested_users.remove_user_task.delay")
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
||||
@patch("bookwyrm.activitystreams.remove_status_task.delay")
|
||||
def test_delete_user_erase_statuses(self, *_):
|
||||
"""erase user statuses when user is deleted"""
|
||||
status = models.Status.objects.create(user=self.user, content="hello")
|
||||
self.assertFalse(status.deleted)
|
||||
self.assertIsNotNone(status.content)
|
||||
self.assertIsNone(status.deleted_date)
|
||||
|
||||
self.user.delete()
|
||||
status.refresh_from_db()
|
||||
|
||||
self.assertTrue(status.deleted)
|
||||
self.assertIsNone(status.content)
|
||||
self.assertIsNotNone(status.deleted_date)
|
||||
|
||||
@patch("bookwyrm.suggested_users.remove_user_task.delay")
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
@patch("bookwyrm.activitystreams.add_status_task.delay")
|
||||
def test_delete_user_erase_statuses_invalid(self, *_):
|
||||
"""erase user statuses when user is deleted"""
|
||||
status = models.Status.objects.create(user=self.user, content="hello")
|
||||
self.assertFalse(status.deleted)
|
||||
self.assertIsNotNone(status.content)
|
||||
self.assertIsNone(status.deleted_date)
|
||||
|
||||
self.user.deactivate()
|
||||
with self.assertRaises(IntegrityError):
|
||||
self.user.erase_user_statuses()
|
||||
|
||||
status.refresh_from_db()
|
||||
self.assertFalse(status.deleted)
|
||||
self.assertIsNotNone(status.content)
|
||||
self.assertIsNone(status.deleted_date)
|
||||
|
||||
def test_admins_no_admins(self):
|
||||
"""list of admins"""
|
||||
result = models.User.admins()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue