We now persist system accounts to database
This commit is contained in:
parent
fba9a5c97e
commit
48df30dbd8
|
@ -49,15 +49,17 @@ class SystemActor(object):
|
||||||
additional_attributes = {}
|
additional_attributes = {}
|
||||||
|
|
||||||
def get_actor_instance(self):
|
def get_actor_instance(self):
|
||||||
a = models.Actor(
|
args = self.get_instance_argument(
|
||||||
**self.get_instance_argument(
|
self.id,
|
||||||
self.id,
|
name=self.name,
|
||||||
name=self.name,
|
summary=self.summary,
|
||||||
summary=self.summary,
|
**self.additional_attributes
|
||||||
**self.additional_attributes
|
)
|
||||||
)
|
url = args.pop('url')
|
||||||
|
a, created = models.Actor.objects.get_or_create(
|
||||||
|
url=url,
|
||||||
|
defaults=args,
|
||||||
)
|
)
|
||||||
a.pk = self.id
|
|
||||||
return a
|
return a
|
||||||
|
|
||||||
def get_instance_argument(self, id, name, summary, **kwargs):
|
def get_instance_argument(self, id, name, summary, **kwargs):
|
||||||
|
|
|
@ -6,6 +6,7 @@ from django.utils import timezone
|
||||||
from rest_framework import exceptions
|
from rest_framework import exceptions
|
||||||
|
|
||||||
from funkwhale_api.federation import actors
|
from funkwhale_api.federation import actors
|
||||||
|
from funkwhale_api.federation import models
|
||||||
from funkwhale_api.federation import serializers
|
from funkwhale_api.federation import serializers
|
||||||
from funkwhale_api.federation import utils
|
from funkwhale_api.federation import utils
|
||||||
|
|
||||||
|
@ -188,3 +189,11 @@ def test_test_post_outbox_handles_create_note(
|
||||||
to=[actor.url],
|
to=[actor.url],
|
||||||
on_behalf_of=actors.SYSTEM_ACTORS['test'].get_actor_instance()
|
on_behalf_of=actors.SYSTEM_ACTORS['test'].get_actor_instance()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_getting_actor_instance_persists_in_db(db):
|
||||||
|
test = actors.SYSTEM_ACTORS['test'].get_actor_instance()
|
||||||
|
from_db = models.Actor.objects.get(url=test.url)
|
||||||
|
|
||||||
|
for f in test._meta.fields:
|
||||||
|
assert getattr(from_db, f.name) == getattr(test, f.name)
|
||||||
|
|
Loading…
Reference in New Issue