New version of black, new whitespace
This commit is contained in:
parent
ef83eb33b0
commit
3ade2d3bb1
152 changed files with 1289 additions and 1289 deletions
|
@ -15,10 +15,10 @@ from bookwyrm.models.activitypub_mixin import ActivityMixin, ObjectMixin
|
|||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
class ActivitypubMixins(TestCase):
|
||||
""" functionality shared across models """
|
||||
"""functionality shared across models"""
|
||||
|
||||
def setUp(self):
|
||||
""" shared data """
|
||||
"""shared data"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
|
@ -46,16 +46,16 @@ class ActivitypubMixins(TestCase):
|
|||
|
||||
# ActivitypubMixin
|
||||
def test_to_activity(self, _):
|
||||
""" model to ActivityPub json """
|
||||
"""model to ActivityPub json"""
|
||||
|
||||
@dataclass(init=False)
|
||||
class TestActivity(ActivityObject):
|
||||
""" real simple mock """
|
||||
"""real simple mock"""
|
||||
|
||||
type: str = "Test"
|
||||
|
||||
class TestModel(ActivitypubMixin, base_model.BookWyrmModel):
|
||||
""" real simple mock model because BookWyrmModel is abstract """
|
||||
"""real simple mock model because BookWyrmModel is abstract"""
|
||||
|
||||
instance = TestModel()
|
||||
instance.remote_id = "https://www.example.com/test"
|
||||
|
@ -67,7 +67,7 @@ class ActivitypubMixins(TestCase):
|
|||
self.assertEqual(activity["type"], "Test")
|
||||
|
||||
def test_find_existing_by_remote_id(self, _):
|
||||
""" attempt to match a remote id to an object in the db """
|
||||
"""attempt to match a remote id to an object in the db"""
|
||||
# uses a different remote id scheme
|
||||
# this isn't really part of this test directly but it's helpful to state
|
||||
book = models.Edition.objects.create(
|
||||
|
@ -100,7 +100,7 @@ class ActivitypubMixins(TestCase):
|
|||
result = models.Status.find_existing_by_remote_id("https://comment.net")
|
||||
|
||||
def test_find_existing(self, _):
|
||||
""" match a blob of data to a model """
|
||||
"""match a blob of data to a model"""
|
||||
book = models.Edition.objects.create(
|
||||
title="Test edition",
|
||||
openlibrary_key="OL1234",
|
||||
|
@ -110,7 +110,7 @@ class ActivitypubMixins(TestCase):
|
|||
self.assertEqual(result, book)
|
||||
|
||||
def test_get_recipients_public_object(self, _):
|
||||
""" determines the recipients for an object's broadcast """
|
||||
"""determines the recipients for an object's broadcast"""
|
||||
MockSelf = namedtuple("Self", ("privacy"))
|
||||
mock_self = MockSelf("public")
|
||||
recipients = ActivitypubMixin.get_recipients(mock_self)
|
||||
|
@ -118,7 +118,7 @@ class ActivitypubMixins(TestCase):
|
|||
self.assertEqual(recipients[0], self.remote_user.inbox)
|
||||
|
||||
def test_get_recipients_public_user_object_no_followers(self, _):
|
||||
""" determines the recipients for a user's object broadcast """
|
||||
"""determines the recipients for a user's object broadcast"""
|
||||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
||||
mock_self = MockSelf("public", self.local_user)
|
||||
|
||||
|
@ -126,7 +126,7 @@ class ActivitypubMixins(TestCase):
|
|||
self.assertEqual(len(recipients), 0)
|
||||
|
||||
def test_get_recipients_public_user_object(self, _):
|
||||
""" determines the recipients for a user's object broadcast """
|
||||
"""determines the recipients for a user's object broadcast"""
|
||||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
||||
mock_self = MockSelf("public", self.local_user)
|
||||
self.local_user.followers.add(self.remote_user)
|
||||
|
@ -136,7 +136,7 @@ class ActivitypubMixins(TestCase):
|
|||
self.assertEqual(recipients[0], self.remote_user.inbox)
|
||||
|
||||
def test_get_recipients_public_user_object_with_mention(self, _):
|
||||
""" determines the recipients for a user's object broadcast """
|
||||
"""determines the recipients for a user's object broadcast"""
|
||||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
||||
mock_self = MockSelf("public", self.local_user)
|
||||
self.local_user.followers.add(self.remote_user)
|
||||
|
@ -159,7 +159,7 @@ class ActivitypubMixins(TestCase):
|
|||
self.assertTrue(self.remote_user.inbox in recipients)
|
||||
|
||||
def test_get_recipients_direct(self, _):
|
||||
""" determines the recipients for a user's object broadcast """
|
||||
"""determines the recipients for a user's object broadcast"""
|
||||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
||||
mock_self = MockSelf("public", self.local_user)
|
||||
self.local_user.followers.add(self.remote_user)
|
||||
|
@ -181,7 +181,7 @@ class ActivitypubMixins(TestCase):
|
|||
self.assertEqual(recipients[0], another_remote_user.inbox)
|
||||
|
||||
def test_get_recipients_combine_inboxes(self, _):
|
||||
""" should combine users with the same shared_inbox """
|
||||
"""should combine users with the same shared_inbox"""
|
||||
self.remote_user.shared_inbox = "http://example.com/inbox"
|
||||
self.remote_user.save(broadcast=False)
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
|
@ -205,7 +205,7 @@ class ActivitypubMixins(TestCase):
|
|||
self.assertEqual(recipients[0], "http://example.com/inbox")
|
||||
|
||||
def test_get_recipients_software(self, _):
|
||||
""" should differentiate between bookwyrm and other remote users """
|
||||
"""should differentiate between bookwyrm and other remote users"""
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
another_remote_user = models.User.objects.create_user(
|
||||
"nutria",
|
||||
|
@ -235,13 +235,13 @@ class ActivitypubMixins(TestCase):
|
|||
|
||||
# ObjectMixin
|
||||
def test_object_save_create(self, _):
|
||||
""" should save uneventufully when broadcast is disabled """
|
||||
"""should save uneventufully when broadcast is disabled"""
|
||||
|
||||
class Success(Exception):
|
||||
""" this means we got to the right method """
|
||||
"""this means we got to the right method"""
|
||||
|
||||
class ObjectModel(ObjectMixin, base_model.BookWyrmModel):
|
||||
""" real simple mock model because BookWyrmModel is abstract """
|
||||
"""real simple mock model because BookWyrmModel is abstract"""
|
||||
|
||||
user = models.fields.ForeignKey("User", on_delete=db.models.CASCADE)
|
||||
|
||||
|
@ -252,7 +252,7 @@ class ActivitypubMixins(TestCase):
|
|||
def broadcast(
|
||||
self, activity, sender, **kwargs
|
||||
): # pylint: disable=arguments-differ
|
||||
""" do something """
|
||||
"""do something"""
|
||||
raise Success()
|
||||
|
||||
def to_create_activity(self, user): # pylint: disable=arguments-differ
|
||||
|
@ -266,13 +266,13 @@ class ActivitypubMixins(TestCase):
|
|||
ObjectModel(user=None).save()
|
||||
|
||||
def test_object_save_update(self, _):
|
||||
""" should save uneventufully when broadcast is disabled """
|
||||
"""should save uneventufully when broadcast is disabled"""
|
||||
|
||||
class Success(Exception):
|
||||
""" this means we got to the right method """
|
||||
"""this means we got to the right method"""
|
||||
|
||||
class UpdateObjectModel(ObjectMixin, base_model.BookWyrmModel):
|
||||
""" real simple mock model because BookWyrmModel is abstract """
|
||||
"""real simple mock model because BookWyrmModel is abstract"""
|
||||
|
||||
user = models.fields.ForeignKey("User", on_delete=db.models.CASCADE)
|
||||
last_edited_by = models.fields.ForeignKey(
|
||||
|
@ -292,13 +292,13 @@ class ActivitypubMixins(TestCase):
|
|||
UpdateObjectModel(id=1, last_edited_by=self.local_user).save()
|
||||
|
||||
def test_object_save_delete(self, _):
|
||||
""" should create delete activities when objects are deleted by flag """
|
||||
"""should create delete activities when objects are deleted by flag"""
|
||||
|
||||
class ActivitySuccess(Exception):
|
||||
""" this means we got to the right method """
|
||||
"""this means we got to the right method"""
|
||||
|
||||
class DeletableObjectModel(ObjectMixin, base_model.BookWyrmModel):
|
||||
""" real simple mock model because BookWyrmModel is abstract """
|
||||
"""real simple mock model because BookWyrmModel is abstract"""
|
||||
|
||||
user = models.fields.ForeignKey("User", on_delete=db.models.CASCADE)
|
||||
deleted = models.fields.BooleanField()
|
||||
|
@ -314,7 +314,7 @@ class ActivitypubMixins(TestCase):
|
|||
DeletableObjectModel(id=1, user=self.local_user, deleted=True).save()
|
||||
|
||||
def test_to_delete_activity(self, _):
|
||||
""" wrapper for Delete activity """
|
||||
"""wrapper for Delete activity"""
|
||||
MockSelf = namedtuple("Self", ("remote_id", "to_activity"))
|
||||
mock_self = MockSelf(
|
||||
"https://example.com/status/1", lambda *args: self.object_mock
|
||||
|
@ -329,7 +329,7 @@ class ActivitypubMixins(TestCase):
|
|||
)
|
||||
|
||||
def test_to_update_activity(self, _):
|
||||
""" ditto above but for Update """
|
||||
"""ditto above but for Update"""
|
||||
MockSelf = namedtuple("Self", ("remote_id", "to_activity"))
|
||||
mock_self = MockSelf(
|
||||
"https://example.com/status/1", lambda *args: self.object_mock
|
||||
|
@ -347,7 +347,7 @@ class ActivitypubMixins(TestCase):
|
|||
|
||||
# Activity mixin
|
||||
def test_to_undo_activity(self, _):
|
||||
""" and again, for Undo """
|
||||
"""and again, for Undo"""
|
||||
MockSelf = namedtuple("Self", ("remote_id", "to_activity", "user"))
|
||||
mock_self = MockSelf(
|
||||
"https://example.com/status/1",
|
||||
|
|
|
@ -8,10 +8,10 @@ from bookwyrm.settings import DOMAIN
|
|||
|
||||
|
||||
class BaseModel(TestCase):
|
||||
""" functionality shared across models """
|
||||
"""functionality shared across models"""
|
||||
|
||||
def setUp(self):
|
||||
""" shared data """
|
||||
"""shared data"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.com", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
|
@ -27,14 +27,14 @@ class BaseModel(TestCase):
|
|||
)
|
||||
|
||||
def test_remote_id(self):
|
||||
""" these should be generated """
|
||||
"""these should be generated"""
|
||||
instance = base_model.BookWyrmModel()
|
||||
instance.id = 1
|
||||
expected = instance.get_remote_id()
|
||||
self.assertEqual(expected, "https://%s/bookwyrmmodel/1" % DOMAIN)
|
||||
|
||||
def test_remote_id_with_user(self):
|
||||
""" format of remote id when there's a user object """
|
||||
"""format of remote id when there's a user object"""
|
||||
instance = base_model.BookWyrmModel()
|
||||
instance.user = self.local_user
|
||||
instance.id = 1
|
||||
|
@ -42,7 +42,7 @@ class BaseModel(TestCase):
|
|||
self.assertEqual(expected, "https://%s/user/mouse/bookwyrmmodel/1" % DOMAIN)
|
||||
|
||||
def test_set_remote_id(self):
|
||||
""" this function sets remote ids after creation """
|
||||
"""this function sets remote ids after creation"""
|
||||
# using Work because it BookWrymModel is abstract and this requires save
|
||||
# Work is a relatively not-fancy model.
|
||||
instance = models.Work.objects.create(title="work title")
|
||||
|
@ -59,7 +59,7 @@ class BaseModel(TestCase):
|
|||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_object_visible_to_user(self, _):
|
||||
""" does a user have permission to view an object """
|
||||
"""does a user have permission to view an object"""
|
||||
obj = models.Status.objects.create(
|
||||
content="hi", user=self.remote_user, privacy="public"
|
||||
)
|
||||
|
@ -88,7 +88,7 @@ class BaseModel(TestCase):
|
|||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_object_visible_to_user_follower(self, _):
|
||||
""" what you can see if you follow a user """
|
||||
"""what you can see if you follow a user"""
|
||||
self.remote_user.followers.add(self.local_user)
|
||||
obj = models.Status.objects.create(
|
||||
content="hi", user=self.remote_user, privacy="followers"
|
||||
|
@ -108,7 +108,7 @@ class BaseModel(TestCase):
|
|||
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_object_visible_to_user_blocked(self, _):
|
||||
""" you can't see it if they block you """
|
||||
"""you can't see it if they block you"""
|
||||
self.remote_user.blocks.add(self.local_user)
|
||||
obj = models.Status.objects.create(
|
||||
content="hi", user=self.remote_user, privacy="public"
|
||||
|
|
|
@ -8,10 +8,10 @@ from bookwyrm.models.book import isbn_10_to_13, isbn_13_to_10
|
|||
|
||||
|
||||
class Book(TestCase):
|
||||
""" not too much going on in the books model but here we are """
|
||||
"""not too much going on in the books model but here we are"""
|
||||
|
||||
def setUp(self):
|
||||
""" we'll need some books """
|
||||
"""we'll need some books"""
|
||||
self.work = models.Work.objects.create(
|
||||
title="Example Work", remote_id="https://example.com/book/1"
|
||||
)
|
||||
|
@ -25,17 +25,17 @@ class Book(TestCase):
|
|||
)
|
||||
|
||||
def test_remote_id(self):
|
||||
""" fanciness with remote/origin ids """
|
||||
"""fanciness with remote/origin ids"""
|
||||
remote_id = "https://%s/book/%d" % (settings.DOMAIN, self.work.id)
|
||||
self.assertEqual(self.work.get_remote_id(), remote_id)
|
||||
self.assertEqual(self.work.remote_id, remote_id)
|
||||
|
||||
def test_create_book(self):
|
||||
""" you shouldn't be able to create Books (only editions and works) """
|
||||
"""you shouldn't be able to create Books (only editions and works)"""
|
||||
self.assertRaises(ValueError, models.Book.objects.create, title="Invalid Book")
|
||||
|
||||
def test_isbn_10_to_13(self):
|
||||
""" checksums and so on """
|
||||
"""checksums and so on"""
|
||||
isbn_10 = "178816167X"
|
||||
isbn_13 = isbn_10_to_13(isbn_10)
|
||||
self.assertEqual(isbn_13, "9781788161671")
|
||||
|
@ -45,7 +45,7 @@ class Book(TestCase):
|
|||
self.assertEqual(isbn_13, "9781788161671")
|
||||
|
||||
def test_isbn_13_to_10(self):
|
||||
""" checksums and so on """
|
||||
"""checksums and so on"""
|
||||
isbn_13 = "9781788161671"
|
||||
isbn_10 = isbn_13_to_10(isbn_13)
|
||||
self.assertEqual(isbn_10, "178816167X")
|
||||
|
@ -55,7 +55,7 @@ class Book(TestCase):
|
|||
self.assertEqual(isbn_10, "178816167X")
|
||||
|
||||
def test_get_edition_info(self):
|
||||
""" text slug about an edition """
|
||||
"""text slug about an edition"""
|
||||
book = models.Edition.objects.create(title="Test Edition")
|
||||
self.assertEqual(book.edition_info, "")
|
||||
|
||||
|
@ -77,7 +77,7 @@ class Book(TestCase):
|
|||
self.assertEqual(book.alt_text, "Test Edition (worm, Glorbish language, 2020)")
|
||||
|
||||
def test_get_rank(self):
|
||||
""" sets the data quality index for the book """
|
||||
"""sets the data quality index for the book"""
|
||||
# basic rank
|
||||
self.assertEqual(self.first_edition.edition_rank, 0)
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ from bookwyrm import models
|
|||
|
||||
|
||||
class FederatedServer(TestCase):
|
||||
""" federate server management """
|
||||
"""federate server management"""
|
||||
|
||||
def setUp(self):
|
||||
""" we'll need a user """
|
||||
"""we'll need a user"""
|
||||
self.server = models.FederatedServer.objects.create(server_name="test.server")
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
|
@ -36,7 +36,7 @@ class FederatedServer(TestCase):
|
|||
)
|
||||
|
||||
def test_block_unblock(self):
|
||||
""" block a server and all users on it """
|
||||
"""block a server and all users on it"""
|
||||
self.assertEqual(self.server.status, "federated")
|
||||
self.assertTrue(self.remote_user.is_active)
|
||||
self.assertFalse(self.inactive_remote_user.is_active)
|
||||
|
|
|
@ -25,10 +25,10 @@ from bookwyrm.models.activitypub_mixin import ActivitypubMixin
|
|||
|
||||
# pylint: disable=too-many-public-methods
|
||||
class ActivitypubFields(TestCase):
|
||||
""" overwrites standard model feilds to work with activitypub """
|
||||
"""overwrites standard model feilds to work with activitypub"""
|
||||
|
||||
def test_validate_remote_id(self):
|
||||
""" should look like a url """
|
||||
"""should look like a url"""
|
||||
self.assertIsNone(fields.validate_remote_id("http://www.example.com"))
|
||||
self.assertIsNone(fields.validate_remote_id("https://www.example.com"))
|
||||
self.assertIsNone(fields.validate_remote_id("http://exle.com/dlg-23/x"))
|
||||
|
@ -45,7 +45,7 @@ class ActivitypubFields(TestCase):
|
|||
)
|
||||
|
||||
def test_activitypub_field_mixin(self):
|
||||
""" generic mixin with super basic to and from functionality """
|
||||
"""generic mixin with super basic to and from functionality"""
|
||||
instance = fields.ActivitypubFieldMixin()
|
||||
self.assertEqual(instance.field_to_activity("fish"), "fish")
|
||||
self.assertEqual(instance.field_from_activity("fish"), "fish")
|
||||
|
@ -63,11 +63,11 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(instance.get_activitypub_field(), "snakeCaseName")
|
||||
|
||||
def test_set_field_from_activity(self):
|
||||
""" setter from entire json blob """
|
||||
"""setter from entire json blob"""
|
||||
|
||||
@dataclass
|
||||
class TestModel:
|
||||
""" real simple mock """
|
||||
"""real simple mock"""
|
||||
|
||||
field_name: str
|
||||
|
||||
|
@ -82,11 +82,11 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(mock_model.field_name, "hi")
|
||||
|
||||
def test_set_activity_from_field(self):
|
||||
""" set json field given entire model """
|
||||
"""set json field given entire model"""
|
||||
|
||||
@dataclass
|
||||
class TestModel:
|
||||
""" real simple mock """
|
||||
"""real simple mock"""
|
||||
|
||||
field_name: str
|
||||
unrelated: str
|
||||
|
@ -100,7 +100,7 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(data["fieldName"], "bip")
|
||||
|
||||
def test_remote_id_field(self):
|
||||
""" just sets some defaults on charfield """
|
||||
"""just sets some defaults on charfield"""
|
||||
instance = fields.RemoteIdField()
|
||||
self.assertEqual(instance.max_length, 255)
|
||||
self.assertTrue(instance.deduplication_field)
|
||||
|
@ -109,7 +109,7 @@ class ActivitypubFields(TestCase):
|
|||
instance.run_validators("http://www.example.com/dlfjg 23/x")
|
||||
|
||||
def test_username_field(self):
|
||||
""" again, just setting defaults on username field """
|
||||
"""again, just setting defaults on username field"""
|
||||
instance = fields.UsernameField()
|
||||
self.assertEqual(instance.activitypub_field, "preferredUsername")
|
||||
self.assertEqual(instance.max_length, 150)
|
||||
|
@ -130,7 +130,7 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(instance.field_to_activity("test@example.com"), "test")
|
||||
|
||||
def test_privacy_field_defaults(self):
|
||||
""" post privacy field's many default values """
|
||||
"""post privacy field's many default values"""
|
||||
instance = fields.PrivacyField()
|
||||
self.assertEqual(instance.max_length, 255)
|
||||
self.assertEqual(
|
||||
|
@ -143,11 +143,11 @@ class ActivitypubFields(TestCase):
|
|||
)
|
||||
|
||||
def test_privacy_field_set_field_from_activity(self):
|
||||
""" translate between to/cc fields and privacy """
|
||||
"""translate between to/cc fields and privacy"""
|
||||
|
||||
@dataclass(init=False)
|
||||
class TestActivity(ActivityObject):
|
||||
""" real simple mock """
|
||||
"""real simple mock"""
|
||||
|
||||
to: List[str]
|
||||
cc: List[str]
|
||||
|
@ -155,7 +155,7 @@ class ActivitypubFields(TestCase):
|
|||
type: str = "Test"
|
||||
|
||||
class TestPrivacyModel(ActivitypubMixin, BookWyrmModel):
|
||||
""" real simple mock model because BookWyrmModel is abstract """
|
||||
"""real simple mock model because BookWyrmModel is abstract"""
|
||||
|
||||
privacy_field = fields.PrivacyField()
|
||||
mention_users = fields.TagField(User)
|
||||
|
@ -187,7 +187,7 @@ class ActivitypubFields(TestCase):
|
|||
@patch("bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
def test_privacy_field_set_activity_from_field(self, *_):
|
||||
""" translate between to/cc fields and privacy """
|
||||
"""translate between to/cc fields and privacy"""
|
||||
user = User.objects.create_user(
|
||||
"rat", "rat@rat.rat", "ratword", local=True, localname="rat"
|
||||
)
|
||||
|
@ -231,7 +231,7 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(activity["cc"], [])
|
||||
|
||||
def test_foreign_key(self):
|
||||
""" should be able to format a related model """
|
||||
"""should be able to format a related model"""
|
||||
instance = fields.ForeignKey("User", on_delete=models.CASCADE)
|
||||
Serializable = namedtuple("Serializable", ("to_activity", "remote_id"))
|
||||
item = Serializable(lambda: {"a": "b"}, "https://e.b/c")
|
||||
|
@ -240,7 +240,7 @@ class ActivitypubFields(TestCase):
|
|||
|
||||
@responses.activate
|
||||
def test_foreign_key_from_activity_str(self):
|
||||
""" create a new object from a foreign key """
|
||||
"""create a new object from a foreign key"""
|
||||
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||
userdata = json.loads(datafile.read_bytes())
|
||||
|
@ -264,7 +264,7 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(value.name, "MOUSE?? MOUSE!!")
|
||||
|
||||
def test_foreign_key_from_activity_dict(self):
|
||||
""" test recieving activity json """
|
||||
"""test recieving activity json"""
|
||||
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||
userdata = json.loads(datafile.read_bytes())
|
||||
|
@ -284,7 +284,7 @@ class ActivitypubFields(TestCase):
|
|||
# et cetera but we're not testing serializing user json
|
||||
|
||||
def test_foreign_key_from_activity_dict_existing(self):
|
||||
""" test receiving a dict of an existing object in the db """
|
||||
"""test receiving a dict of an existing object in the db"""
|
||||
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||
userdata = json.loads(datafile.read_bytes())
|
||||
|
@ -302,7 +302,7 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(value, user)
|
||||
|
||||
def test_foreign_key_from_activity_str_existing(self):
|
||||
""" test receiving a remote id of an existing object in the db """
|
||||
"""test receiving a remote id of an existing object in the db"""
|
||||
instance = fields.ForeignKey(User, on_delete=models.CASCADE)
|
||||
user = User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
|
@ -315,14 +315,14 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(value, user)
|
||||
|
||||
def test_one_to_one_field(self):
|
||||
""" a gussied up foreign key """
|
||||
"""a gussied up foreign key"""
|
||||
instance = fields.OneToOneField("User", on_delete=models.CASCADE)
|
||||
Serializable = namedtuple("Serializable", ("to_activity", "remote_id"))
|
||||
item = Serializable(lambda: {"a": "b"}, "https://e.b/c")
|
||||
self.assertEqual(instance.field_to_activity(item), {"a": "b"})
|
||||
|
||||
def test_many_to_many_field(self):
|
||||
""" lists! """
|
||||
"""lists!"""
|
||||
instance = fields.ManyToManyField("User")
|
||||
|
||||
Serializable = namedtuple("Serializable", ("to_activity", "remote_id"))
|
||||
|
@ -340,7 +340,7 @@ class ActivitypubFields(TestCase):
|
|||
|
||||
@responses.activate
|
||||
def test_many_to_many_field_from_activity(self):
|
||||
""" resolve related fields for a list, takes a list of remote ids """
|
||||
"""resolve related fields for a list, takes a list of remote ids"""
|
||||
instance = fields.ManyToManyField(User)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
|
||||
userdata = json.loads(datafile.read_bytes())
|
||||
|
@ -360,7 +360,7 @@ class ActivitypubFields(TestCase):
|
|||
self.assertIsInstance(value[0], User)
|
||||
|
||||
def test_tag_field(self):
|
||||
""" a special type of many to many field """
|
||||
"""a special type of many to many field"""
|
||||
instance = fields.TagField("User")
|
||||
|
||||
Serializable = namedtuple(
|
||||
|
@ -379,13 +379,13 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(result[0].type, "Serializable")
|
||||
|
||||
def test_tag_field_from_activity(self):
|
||||
""" loadin' a list of items from Links """
|
||||
"""loadin' a list of items from Links"""
|
||||
# TODO
|
||||
|
||||
@responses.activate
|
||||
@patch("bookwyrm.models.activitypub_mixin.ObjectMixin.broadcast")
|
||||
def test_image_field(self, _):
|
||||
""" storing images """
|
||||
"""storing images"""
|
||||
user = User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
|
@ -423,7 +423,7 @@ class ActivitypubFields(TestCase):
|
|||
self.assertIsInstance(loaded_image[1], ContentFile)
|
||||
|
||||
def test_datetime_field(self):
|
||||
""" this one is pretty simple, it just has to use isoformat """
|
||||
"""this one is pretty simple, it just has to use isoformat"""
|
||||
instance = fields.DateTimeField()
|
||||
now = timezone.now()
|
||||
self.assertEqual(instance.field_to_activity(now), now.isoformat())
|
||||
|
@ -431,12 +431,12 @@ class ActivitypubFields(TestCase):
|
|||
self.assertEqual(instance.field_from_activity("bip"), None)
|
||||
|
||||
def test_array_field(self):
|
||||
""" idk why it makes them strings but probably for a good reason """
|
||||
"""idk why it makes them strings but probably for a good reason"""
|
||||
instance = fields.ArrayField(fields.IntegerField)
|
||||
self.assertEqual(instance.field_to_activity([0, 1]), ["0", "1"])
|
||||
|
||||
def test_html_field(self):
|
||||
""" sanitizes html, the sanitizer has its own tests """
|
||||
"""sanitizes html, the sanitizer has its own tests"""
|
||||
instance = fields.HtmlField()
|
||||
self.assertEqual(
|
||||
instance.field_from_activity("<marquee><p>hi</p></marquee>"), "<p>hi</p>"
|
||||
|
|
|
@ -14,10 +14,10 @@ from bookwyrm.connectors.abstract_connector import SearchResult
|
|||
|
||||
|
||||
class ImportJob(TestCase):
|
||||
""" this is a fancy one!!! """
|
||||
"""this is a fancy one!!!"""
|
||||
|
||||
def setUp(self):
|
||||
""" data is from a goodreads export of The Raven Tower """
|
||||
"""data is from a goodreads export of The Raven Tower"""
|
||||
read_data = {
|
||||
"Book Id": 39395857,
|
||||
"Title": "The Raven Tower",
|
||||
|
@ -72,30 +72,30 @@ class ImportJob(TestCase):
|
|||
)
|
||||
|
||||
def test_isbn(self):
|
||||
""" it unquotes the isbn13 field from data """
|
||||
"""it unquotes the isbn13 field from data"""
|
||||
expected = "9780356506999"
|
||||
item = models.ImportItem.objects.get(index=1)
|
||||
self.assertEqual(item.isbn, expected)
|
||||
|
||||
def test_shelf(self):
|
||||
""" converts to the local shelf typology """
|
||||
"""converts to the local shelf typology"""
|
||||
expected = "reading"
|
||||
self.assertEqual(self.item_1.shelf, expected)
|
||||
|
||||
def test_date_added(self):
|
||||
""" converts to the local shelf typology """
|
||||
"""converts to the local shelf typology"""
|
||||
expected = datetime.datetime(2019, 4, 9, 0, 0, tzinfo=timezone.utc)
|
||||
item = models.ImportItem.objects.get(index=1)
|
||||
self.assertEqual(item.date_added, expected)
|
||||
|
||||
def test_date_read(self):
|
||||
""" converts to the local shelf typology """
|
||||
"""converts to the local shelf typology"""
|
||||
expected = datetime.datetime(2019, 4, 12, 0, 0, tzinfo=timezone.utc)
|
||||
item = models.ImportItem.objects.get(index=2)
|
||||
self.assertEqual(item.date_read, expected)
|
||||
|
||||
def test_currently_reading_reads(self):
|
||||
""" infer currently reading dates where available """
|
||||
"""infer currently reading dates where available"""
|
||||
expected = [
|
||||
models.ReadThrough(
|
||||
start_date=datetime.datetime(2019, 4, 9, 0, 0, tzinfo=timezone.utc)
|
||||
|
@ -106,7 +106,7 @@ class ImportJob(TestCase):
|
|||
self.assertEqual(actual.reads[0].finish_date, expected[0].finish_date)
|
||||
|
||||
def test_read_reads(self):
|
||||
""" infer read dates where available """
|
||||
"""infer read dates where available"""
|
||||
actual = self.item_2
|
||||
self.assertEqual(
|
||||
actual.reads[0].start_date,
|
||||
|
@ -118,14 +118,14 @@ class ImportJob(TestCase):
|
|||
)
|
||||
|
||||
def test_unread_reads(self):
|
||||
""" handle books with no read dates """
|
||||
"""handle books with no read dates"""
|
||||
expected = []
|
||||
actual = models.ImportItem.objects.get(index=3)
|
||||
self.assertEqual(actual.reads, expected)
|
||||
|
||||
@responses.activate
|
||||
def test_get_book_from_isbn(self):
|
||||
""" search and load books by isbn (9780356506999) """
|
||||
"""search and load books by isbn (9780356506999)"""
|
||||
connector_info = models.Connector.objects.create(
|
||||
identifier="openlibrary.org",
|
||||
name="OpenLibrary",
|
||||
|
|
|
@ -7,10 +7,10 @@ from bookwyrm import models, settings
|
|||
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
|
||||
class List(TestCase):
|
||||
""" some activitypub oddness ahead """
|
||||
"""some activitypub oddness ahead"""
|
||||
|
||||
def setUp(self):
|
||||
""" look, a list """
|
||||
"""look, a list"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ class List(TestCase):
|
|||
self.book = models.Edition.objects.create(title="hi", parent_work=work)
|
||||
|
||||
def test_remote_id(self, _):
|
||||
""" shelves use custom remote ids """
|
||||
"""shelves use custom remote ids"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
book_list = models.List.objects.create(
|
||||
name="Test List", user=self.local_user
|
||||
|
@ -27,7 +27,7 @@ class List(TestCase):
|
|||
self.assertEqual(book_list.get_remote_id(), expected_id)
|
||||
|
||||
def test_to_activity(self, _):
|
||||
""" jsonify it """
|
||||
"""jsonify it"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
book_list = models.List.objects.create(
|
||||
name="Test List", user=self.local_user
|
||||
|
@ -41,7 +41,7 @@ class List(TestCase):
|
|||
self.assertEqual(activity_json["owner"], self.local_user.remote_id)
|
||||
|
||||
def test_list_item(self, _):
|
||||
""" a list entry """
|
||||
"""a list entry"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
book_list = models.List.objects.create(
|
||||
name="Test List", user=self.local_user, privacy="unlisted"
|
||||
|
@ -59,7 +59,7 @@ class List(TestCase):
|
|||
self.assertEqual(item.recipients, [])
|
||||
|
||||
def test_list_item_pending(self, _):
|
||||
""" a list entry """
|
||||
"""a list entry"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
book_list = models.List.objects.create(
|
||||
name="Test List", user=self.local_user
|
||||
|
|
|
@ -6,10 +6,10 @@ from bookwyrm import models, settings
|
|||
|
||||
|
||||
class ReadThrough(TestCase):
|
||||
""" some activitypub oddness ahead """
|
||||
"""some activitypub oddness ahead"""
|
||||
|
||||
def setUp(self):
|
||||
""" look, a shelf """
|
||||
"""look, a shelf"""
|
||||
self.user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
|
@ -27,7 +27,7 @@ class ReadThrough(TestCase):
|
|||
)
|
||||
|
||||
def test_progress_update(self):
|
||||
""" Test progress updates """
|
||||
"""Test progress updates"""
|
||||
self.readthrough.create_update() # No-op, no progress yet
|
||||
self.readthrough.progress = 10
|
||||
self.readthrough.create_update()
|
||||
|
|
|
@ -6,10 +6,10 @@ from bookwyrm import models
|
|||
|
||||
|
||||
class Relationship(TestCase):
|
||||
""" following, blocking, stuff like that """
|
||||
"""following, blocking, stuff like that"""
|
||||
|
||||
def setUp(self):
|
||||
""" we need some users for this """
|
||||
"""we need some users for this"""
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
"rat",
|
||||
|
@ -27,11 +27,11 @@ class Relationship(TestCase):
|
|||
self.local_user.save(broadcast=False)
|
||||
|
||||
def test_user_follows_from_request(self):
|
||||
""" convert a follow request into a follow """
|
||||
"""convert a follow request into a follow"""
|
||||
real_broadcast = models.UserFollowRequest.broadcast
|
||||
|
||||
def mock_broadcast(_, activity, user):
|
||||
""" introspect what's being sent out """
|
||||
"""introspect what's being sent out"""
|
||||
self.assertEqual(user.remote_id, self.local_user.remote_id)
|
||||
self.assertEqual(activity["type"], "Follow")
|
||||
|
||||
|
@ -54,7 +54,7 @@ class Relationship(TestCase):
|
|||
models.UserFollowRequest.broadcast = real_broadcast
|
||||
|
||||
def test_user_follows_from_request_custom_remote_id(self):
|
||||
""" store a specific remote id for a relationship provided by remote """
|
||||
"""store a specific remote id for a relationship provided by remote"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
request = models.UserFollowRequest.objects.create(
|
||||
user_subject=self.local_user,
|
||||
|
@ -71,7 +71,7 @@ class Relationship(TestCase):
|
|||
self.assertEqual(rel.user_object, self.remote_user)
|
||||
|
||||
def test_follow_request_activity(self):
|
||||
""" accept a request and make it a relationship """
|
||||
"""accept a request and make it a relationship"""
|
||||
real_broadcast = models.UserFollowRequest.broadcast
|
||||
|
||||
def mock_broadcast(_, activity, user):
|
||||
|
@ -88,7 +88,7 @@ class Relationship(TestCase):
|
|||
models.UserFollowRequest.broadcast = real_broadcast
|
||||
|
||||
def test_follow_request_accept(self):
|
||||
""" accept a request and make it a relationship """
|
||||
"""accept a request and make it a relationship"""
|
||||
real_broadcast = models.UserFollowRequest.broadcast
|
||||
|
||||
def mock_broadcast(_, activity, user):
|
||||
|
@ -115,7 +115,7 @@ class Relationship(TestCase):
|
|||
models.UserFollowRequest.broadcast = real_broadcast
|
||||
|
||||
def test_follow_request_reject(self):
|
||||
""" accept a request and make it a relationship """
|
||||
"""accept a request and make it a relationship"""
|
||||
real_broadcast = models.UserFollowRequest.broadcast
|
||||
|
||||
def mock_reject(_, activity, user):
|
||||
|
|
|
@ -8,10 +8,10 @@ from bookwyrm import models, settings
|
|||
|
||||
# pylint: disable=unused-argument
|
||||
class Shelf(TestCase):
|
||||
""" some activitypub oddness ahead """
|
||||
"""some activitypub oddness ahead"""
|
||||
|
||||
def setUp(self):
|
||||
""" look, a shelf """
|
||||
"""look, a shelf"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
|
@ -19,7 +19,7 @@ class Shelf(TestCase):
|
|||
self.book = models.Edition.objects.create(title="test book", parent_work=work)
|
||||
|
||||
def test_remote_id(self):
|
||||
""" shelves use custom remote ids """
|
||||
"""shelves use custom remote ids"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
shelf = models.Shelf.objects.create(
|
||||
name="Test Shelf", identifier="test-shelf", user=self.local_user
|
||||
|
@ -28,7 +28,7 @@ class Shelf(TestCase):
|
|||
self.assertEqual(shelf.get_remote_id(), expected_id)
|
||||
|
||||
def test_to_activity(self):
|
||||
""" jsonify it """
|
||||
"""jsonify it"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
shelf = models.Shelf.objects.create(
|
||||
name="Test Shelf", identifier="test-shelf", user=self.local_user
|
||||
|
@ -42,7 +42,7 @@ class Shelf(TestCase):
|
|||
self.assertEqual(activity_json["owner"], self.local_user.remote_id)
|
||||
|
||||
def test_create_update_shelf(self):
|
||||
""" create and broadcast shelf creation """
|
||||
"""create and broadcast shelf creation"""
|
||||
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock:
|
||||
shelf = models.Shelf.objects.create(
|
||||
|
@ -63,7 +63,7 @@ class Shelf(TestCase):
|
|||
self.assertEqual(shelf.name, "arthur russel")
|
||||
|
||||
def test_shelve(self):
|
||||
""" create and broadcast shelf creation """
|
||||
"""create and broadcast shelf creation"""
|
||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||
shelf = models.Shelf.objects.create(
|
||||
name="Test Shelf", identifier="test-shelf", user=self.local_user
|
||||
|
|
|
@ -17,10 +17,10 @@ from bookwyrm import activitypub, models, settings
|
|||
@patch("bookwyrm.models.Status.broadcast")
|
||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||
class Status(TestCase):
|
||||
""" lotta types of statuses """
|
||||
"""lotta types of statuses"""
|
||||
|
||||
def setUp(self):
|
||||
""" useful things for creating a status """
|
||||
"""useful things for creating a status"""
|
||||
self.local_user = models.User.objects.create_user(
|
||||
"mouse", "mouse@mouse.mouse", "mouseword", local=True, localname="mouse"
|
||||
)
|
||||
|
@ -46,14 +46,14 @@ class Status(TestCase):
|
|||
self.book.cover.save("test.jpg", ContentFile(output.getvalue()))
|
||||
|
||||
def test_status_generated_fields(self, *_):
|
||||
""" setting remote id """
|
||||
"""setting remote id"""
|
||||
status = models.Status.objects.create(content="bleh", user=self.local_user)
|
||||
expected_id = "https://%s/user/mouse/status/%d" % (settings.DOMAIN, status.id)
|
||||
self.assertEqual(status.remote_id, expected_id)
|
||||
self.assertEqual(status.privacy, "public")
|
||||
|
||||
def test_replies(self, *_):
|
||||
""" get a list of replies """
|
||||
"""get a list of replies"""
|
||||
parent = models.Status.objects.create(content="hi", user=self.local_user)
|
||||
child = models.Status.objects.create(
|
||||
content="hello", reply_parent=parent, user=self.local_user
|
||||
|
@ -72,7 +72,7 @@ class Status(TestCase):
|
|||
self.assertIsInstance(replies.last(), models.Review)
|
||||
|
||||
def test_status_type(self, *_):
|
||||
""" class name """
|
||||
"""class name"""
|
||||
self.assertEqual(models.Status().status_type, "Note")
|
||||
self.assertEqual(models.Review().status_type, "Review")
|
||||
self.assertEqual(models.Quotation().status_type, "Quotation")
|
||||
|
@ -80,14 +80,14 @@ class Status(TestCase):
|
|||
self.assertEqual(models.Boost().status_type, "Announce")
|
||||
|
||||
def test_boostable(self, *_):
|
||||
""" can a status be boosted, based on privacy """
|
||||
"""can a status be boosted, based on privacy"""
|
||||
self.assertTrue(models.Status(privacy="public").boostable)
|
||||
self.assertTrue(models.Status(privacy="unlisted").boostable)
|
||||
self.assertFalse(models.Status(privacy="followers").boostable)
|
||||
self.assertFalse(models.Status(privacy="direct").boostable)
|
||||
|
||||
def test_to_replies(self, *_):
|
||||
""" activitypub replies collection """
|
||||
"""activitypub replies collection"""
|
||||
parent = models.Status.objects.create(content="hi", user=self.local_user)
|
||||
child = models.Status.objects.create(
|
||||
content="hello", reply_parent=parent, user=self.local_user
|
||||
|
@ -104,7 +104,7 @@ class Status(TestCase):
|
|||
self.assertEqual(replies["totalItems"], 2)
|
||||
|
||||
def test_status_to_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.Status.objects.create(
|
||||
content="test content", user=self.local_user
|
||||
)
|
||||
|
@ -115,7 +115,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["sensitive"], False)
|
||||
|
||||
def test_status_to_activity_tombstone(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
):
|
||||
|
@ -131,7 +131,7 @@ class Status(TestCase):
|
|||
self.assertFalse(hasattr(activity, "content"))
|
||||
|
||||
def test_status_to_pure_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.Status.objects.create(
|
||||
content="test content", user=self.local_user
|
||||
)
|
||||
|
@ -143,7 +143,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["attachment"], [])
|
||||
|
||||
def test_generated_note_to_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.GeneratedNote.objects.create(
|
||||
content="test content", user=self.local_user
|
||||
)
|
||||
|
@ -157,7 +157,7 @@ class Status(TestCase):
|
|||
self.assertEqual(len(activity["tag"]), 2)
|
||||
|
||||
def test_generated_note_to_pure_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.GeneratedNote.objects.create(
|
||||
content="test content", user=self.local_user
|
||||
)
|
||||
|
@ -181,7 +181,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["attachment"][0].name, "Test Edition")
|
||||
|
||||
def test_comment_to_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.Comment.objects.create(
|
||||
content="test content", user=self.local_user, book=self.book
|
||||
)
|
||||
|
@ -192,7 +192,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["inReplyToBook"], self.book.remote_id)
|
||||
|
||||
def test_comment_to_pure_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.Comment.objects.create(
|
||||
content="test content", user=self.local_user, book=self.book
|
||||
)
|
||||
|
@ -212,7 +212,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["attachment"][0].name, "Test Edition")
|
||||
|
||||
def test_quotation_to_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.Quotation.objects.create(
|
||||
quote="a sickening sense",
|
||||
content="test content",
|
||||
|
@ -227,7 +227,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["inReplyToBook"], self.book.remote_id)
|
||||
|
||||
def test_quotation_to_pure_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.Quotation.objects.create(
|
||||
quote="a sickening sense",
|
||||
content="test content",
|
||||
|
@ -250,7 +250,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["attachment"][0].name, "Test Edition")
|
||||
|
||||
def test_review_to_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.Review.objects.create(
|
||||
name="Review name",
|
||||
content="test content",
|
||||
|
@ -267,7 +267,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["inReplyToBook"], self.book.remote_id)
|
||||
|
||||
def test_review_to_pure_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.Review.objects.create(
|
||||
name="Review's name",
|
||||
content="test content",
|
||||
|
@ -291,7 +291,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["attachment"][0].name, "Test Edition")
|
||||
|
||||
def test_review_to_pure_activity_no_rating(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.Review.objects.create(
|
||||
name="Review name",
|
||||
content="test content",
|
||||
|
@ -313,7 +313,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["attachment"][0].name, "Test Edition")
|
||||
|
||||
def test_reviewrating_to_pure_activity(self, *_):
|
||||
""" subclass of the base model version with a "pure" serializer """
|
||||
"""subclass of the base model version with a "pure" serializer"""
|
||||
status = models.ReviewRating.objects.create(
|
||||
rating=3.0,
|
||||
user=self.local_user,
|
||||
|
@ -335,11 +335,11 @@ class Status(TestCase):
|
|||
self.assertEqual(activity["attachment"][0].name, "Test Edition")
|
||||
|
||||
def test_favorite(self, *_):
|
||||
""" fav a status """
|
||||
"""fav a status"""
|
||||
real_broadcast = models.Favorite.broadcast
|
||||
|
||||
def fav_broadcast_mock(_, activity, user):
|
||||
""" ok """
|
||||
"""ok"""
|
||||
self.assertEqual(user.remote_id, self.local_user.remote_id)
|
||||
self.assertEqual(activity["type"], "Like")
|
||||
|
||||
|
@ -361,7 +361,7 @@ class Status(TestCase):
|
|||
models.Favorite.broadcast = real_broadcast
|
||||
|
||||
def test_boost(self, *_):
|
||||
""" boosting, this one's a bit fussy """
|
||||
"""boosting, this one's a bit fussy"""
|
||||
status = models.Status.objects.create(
|
||||
content="test content", user=self.local_user
|
||||
)
|
||||
|
@ -373,7 +373,7 @@ class Status(TestCase):
|
|||
self.assertEqual(activity, boost.to_activity(pure=True))
|
||||
|
||||
def test_notification(self, *_):
|
||||
""" a simple model """
|
||||
"""a simple model"""
|
||||
notification = models.Notification.objects.create(
|
||||
user=self.local_user, notification_type="FAVORITE"
|
||||
)
|
||||
|
@ -385,7 +385,7 @@ class Status(TestCase):
|
|||
)
|
||||
|
||||
def test_create_broadcast(self, _, broadcast_mock):
|
||||
""" should send out two verions of a status on create """
|
||||
"""should send out two verions of a status on create"""
|
||||
models.Comment.objects.create(
|
||||
content="hi", user=self.local_user, book=self.book
|
||||
)
|
||||
|
@ -405,7 +405,7 @@ class Status(TestCase):
|
|||
self.assertEqual(args["object"]["type"], "Comment")
|
||||
|
||||
def test_recipients_with_mentions(self, *_):
|
||||
""" get recipients to broadcast a status """
|
||||
"""get recipients to broadcast a status"""
|
||||
status = models.GeneratedNote.objects.create(
|
||||
content="test content", user=self.local_user
|
||||
)
|
||||
|
@ -414,7 +414,7 @@ class Status(TestCase):
|
|||
self.assertEqual(status.recipients, [self.remote_user])
|
||||
|
||||
def test_recipients_with_reply_parent(self, *_):
|
||||
""" get recipients to broadcast a status """
|
||||
"""get recipients to broadcast a status"""
|
||||
parent_status = models.GeneratedNote.objects.create(
|
||||
content="test content", user=self.remote_user
|
||||
)
|
||||
|
@ -425,7 +425,7 @@ class Status(TestCase):
|
|||
self.assertEqual(status.recipients, [self.remote_user])
|
||||
|
||||
def test_recipients_with_reply_parent_and_mentions(self, *_):
|
||||
""" get recipients to broadcast a status """
|
||||
"""get recipients to broadcast a status"""
|
||||
parent_status = models.GeneratedNote.objects.create(
|
||||
content="test content", user=self.remote_user
|
||||
)
|
||||
|
@ -438,7 +438,7 @@ class Status(TestCase):
|
|||
|
||||
@responses.activate
|
||||
def test_ignore_activity_boost(self, *_):
|
||||
""" don't bother with most remote statuses """
|
||||
"""don't bother with most remote statuses"""
|
||||
activity = activitypub.Announce(
|
||||
id="http://www.faraway.com/boost/12",
|
||||
actor=self.remote_user.remote_id,
|
||||
|
|
|
@ -22,7 +22,7 @@ class User(TestCase):
|
|||
)
|
||||
|
||||
def test_computed_fields(self):
|
||||
""" username instead of id here """
|
||||
"""username instead of id here"""
|
||||
expected_id = "https://%s/user/mouse" % DOMAIN
|
||||
self.assertEqual(self.user.remote_id, expected_id)
|
||||
self.assertEqual(self.user.username, "mouse@%s" % DOMAIN)
|
||||
|
@ -155,7 +155,7 @@ class User(TestCase):
|
|||
self.assertIsNone(server.application_version)
|
||||
|
||||
def test_delete_user(self):
|
||||
""" deactivate a user """
|
||||
"""deactivate a user"""
|
||||
self.assertTrue(self.user.is_active)
|
||||
with patch(
|
||||
"bookwyrm.models.activitypub_mixin.broadcast_task.delay"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue