This commit is contained in:
Renato "Lond" Cerqueira 2022-01-05 15:42:54 +01:00
parent 097d86454a
commit e2ee3d27a7
2 changed files with 15 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import requests
from django.utils.http import http_date
from bookwyrm import models
from bookwyrm.signatures import make_signature
from bookwyrm.settings import DOMAIN
class ActivitySerializerError(ValueError):
"""routine problems serializing activitypub json"""
@ -315,12 +316,19 @@ def resolve_remote_id(
# if we're refreshing, "result" will be set and we'll update it
return item.to_model(model=model, instance=result, save=save)
def get_representative():
try:
models.User.objects.get(id=-99)
except models.User.DoesNotExist:
username = "%s@%s" % (DOMAIN, DOMAIN)
email = "representative@%s" % (DOMAIN)
models.User.objects.create_user(id=-99, username=username, email=email, local=True, localname=DOMAIN)
def get_activitypub_data(url):
''' wrapper for request.get '''
now = http_date()
# XXX TEMP!!
sender = models.User.objects.get(id=1)
sender = get_representative()
if not sender.key_pair.private_key:
# this shouldn't happen. it would be bad if it happened.
raise ValueError('No private key found for sender')

View file

@ -14,6 +14,7 @@ from bookwyrm.activitypub.base_activity import (
ActivityObject,
resolve_remote_id,
set_related_field,
get_representative
)
from bookwyrm.activitypub import ActivitySerializerError
from bookwyrm import models
@ -51,6 +52,10 @@ class BaseActivity(TestCase):
image.save(output, format=image.format)
self.image_data = output.getvalue()
def test_get_representative_not_existing(self, _):
representative = get_representative()
self.assertIsInstance(representative, models.User)
def test_init(self, *_):
"""simple successfuly init"""
instance = ActivityObject(id="a", type="b")