64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
|
#!/usr/bin/env python3
|
||
|
import factory
|
||
|
import app.activitypub as ap
|
||
|
from app import models
|
||
|
|
||
|
from sqlalchemy import orm
|
||
|
|
||
|
from app import activitypub as ap
|
||
|
from app import actor
|
||
|
from app import models
|
||
|
from app.database import SessionLocal
|
||
|
|
||
|
_Session = orm.scoped_session(SessionLocal)
|
||
|
|
||
|
|
||
|
class BaseModelMeta:
|
||
|
sqlalchemy_session = _Session
|
||
|
sqlalchemy_session_persistence = "commit"
|
||
|
|
||
|
|
||
|
class RemoteActorFactory(factory.Factory): # pyright: disable
|
||
|
class Meta:
|
||
|
model = ap.BaseActor
|
||
|
exclude = (
|
||
|
"base_url",
|
||
|
"username",
|
||
|
"public_key",
|
||
|
"also_known_as",
|
||
|
)
|
||
|
|
||
|
ap_actor = factory.LazyAttribute(
|
||
|
lambda o: {
|
||
|
"@context": ap.AS_CTX,
|
||
|
"type": "Person",
|
||
|
"id": o.base_url,
|
||
|
"following": o.base_url + "/following",
|
||
|
"followers": o.base_url + "/followers",
|
||
|
"inbox": o.base_url + "/inbox",
|
||
|
"outbox": o.base_url + "/outbox",
|
||
|
"preferredUsername": o.username,
|
||
|
"name": o.username,
|
||
|
"summary": "test user",
|
||
|
"endpoints": {},
|
||
|
"url": o.base_url,
|
||
|
"manuallyApprovesFollowers": False,
|
||
|
"attachment": [],
|
||
|
"icon": {},
|
||
|
"publicKey": {
|
||
|
"id": f"{o.base_url}#main-key",
|
||
|
"owner": o.base_url,
|
||
|
"publicKeyPem": o.public_key,
|
||
|
},
|
||
|
"alsoKnownAs": [],
|
||
|
}
|
||
|
)
|
||
|
|
||
|
|
||
|
class ActorFactory(factory.alchemy.SQLAlchemyModelFactory):
|
||
|
class Meta(BaseModelMeta):
|
||
|
model = models.Actor
|
||
|
|
||
|
ap_type = "Person"
|
||
|
ap_id = "stub"
|