mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-27 18:40:31 +00:00
pylint fixes
This commit is contained in:
parent
4108238716
commit
f8c9df4aff
3 changed files with 9 additions and 7 deletions
|
@ -1,8 +1,8 @@
|
|||
""" basics for an activitypub serializer """
|
||||
from dataclasses import dataclass, fields, MISSING
|
||||
from json import JSONEncoder
|
||||
import requests
|
||||
import logging
|
||||
import requests
|
||||
|
||||
from django.apps import apps
|
||||
from django.db import IntegrityError, transaction
|
||||
|
@ -251,10 +251,10 @@ def set_related_field(
|
|||
|
||||
def get_model_from_type(activity_type):
|
||||
"""given the activity, what type of model"""
|
||||
models = apps.get_models()
|
||||
activity_models = apps.get_models()
|
||||
model = [
|
||||
m
|
||||
for m in models
|
||||
for m in activity_models
|
||||
if hasattr(m, "activity_serializer")
|
||||
and hasattr(m.activity_serializer, "type")
|
||||
and m.activity_serializer.type == activity_type
|
||||
|
@ -280,9 +280,9 @@ def resolve_remote_id(
|
|||
# load the data and create the object
|
||||
try:
|
||||
data = get_data(remote_id)
|
||||
except requests.HTTPError as e:
|
||||
except ConnectorException as e:
|
||||
if (e.response is not None) and e.response.status_code == 401:
|
||||
"""This most likely means it's a mastodon with secure fetch enabled."""
|
||||
# This most likely means it's a mastodon with secure fetch enabled.
|
||||
data = get_activitypub_data(remote_id)
|
||||
else:
|
||||
logger.info("Could not connect to host for remote_id: %s", remote_id)
|
||||
|
@ -306,7 +306,8 @@ def resolve_remote_id(
|
|||
|
||||
|
||||
def get_representative():
|
||||
username = "%s@%s" % (INSTANCE_ACTOR_USERNAME, DOMAIN)
|
||||
"""Get or create an actor representing the entire instance to sign requests to 'secure mastodon' servers"""
|
||||
username = f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}"
|
||||
try:
|
||||
user = models.User.objects.get(username=username)
|
||||
except models.User.DoesNotExist:
|
||||
|
|
|
@ -32,7 +32,7 @@ def make_signature(method, sender, destination, date, digest=None):
|
|||
]
|
||||
headers = "(request-target) host date"
|
||||
if digest is not None:
|
||||
signature_headers.append("digest: %s" % digest)
|
||||
signature_headers.append(f"digest: {digest}")
|
||||
headers = "(request-target) host date digest"
|
||||
|
||||
message_to_sign = "\n".join(signature_headers)
|
||||
|
|
|
@ -54,6 +54,7 @@ class BaseActivity(TestCase):
|
|||
self.image_data = output.getvalue()
|
||||
|
||||
def test_get_representative_not_existing(self, *_):
|
||||
"""test that an instance representative actor is created if it does not exist"""
|
||||
representative = get_representative()
|
||||
self.assertIsInstance(representative, models.User)
|
||||
|
||||
|
|
Loading…
Reference in a new issue