Verified Commit 87daa817 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

More factories

parent feab0f98
import factory
import requests
import requests_http_signature
import uuid
from django.utils import timezone
from django.conf import settings
......@@ -52,6 +53,21 @@ class SignedRequestFactory(factory.Factory):
self.headers.update(default_headers)
@registry.register(name='federation.Link')
class LinkFactory(factory.Factory):
type = 'Link'
href = factory.Faker('url')
mediaType = 'text/html'
class Meta:
model = dict
class Params:
audio = factory.Trait(
mediaType=factory.Iterator(['audio/mp3', 'audio/ogg'])
)
@registry.register
class ActorFactory(factory.DjangoModelFactory):
public_key = None
......@@ -135,3 +151,34 @@ class ActivityFactory(factory.Factory):
class Meta:
model = dict
@registry.register(name='federation.AudioMetadata')
class AudioMetadataFactory(factory.Factory):
recording = factory.LazyAttribute(
lambda o: 'https://musicbrainz.org/recording/{}'.format(uuid.uuid4())
)
artist = factory.LazyAttribute(
lambda o: 'https://musicbrainz.org/artist/{}'.format(uuid.uuid4())
)
release = factory.LazyAttribute(
lambda o: 'https://musicbrainz.org/release/{}'.format(uuid.uuid4())
)
class Meta:
model = dict
@registry.register(name='federation.Audio')
class AudioFactory(factory.Factory):
type = 'Audio'
id = factory.Faker('url')
published = factory.LazyFunction(
lambda: timezone.now().isoformat()
)
actor = factory.Faker('url')
url = factory.SubFactory(LinkFactory, audio=True)
metadata = factory.SubFactory(AudioMetadataFactory)
class Meta:
model = dict
......@@ -2,6 +2,10 @@ import factory
import os
from funkwhale_api.factories import registry, ManyToManyFromList
from funkwhale_api.federation.factories import (
AudioMetadataFactory,
ActorFactory,
)
from funkwhale_api.users.factories import UserFactory
SAMPLES_PATH = os.path.join(
......@@ -61,6 +65,13 @@ class ImportBatchFactory(factory.django.DjangoModelFactory):
class Meta:
model = 'music.ImportBatch'
class Params:
federation = factory.Trait(
submitted_by=None,
federation_actor=factory.SubFactory(ActorFactory),
source='federation',
)
@registry.register
class ImportJobFactory(factory.django.DjangoModelFactory):
......@@ -71,6 +82,13 @@ class ImportJobFactory(factory.django.DjangoModelFactory):
class Meta:
model = 'music.ImportJob'
class Params:
federation = factory.Trait(
batch=factory.SubFactory(ImportBatchFactory, federation=True),
federation_source=factory.Faker('url'),
metadata=factory.SubFactory(AudioMetadataFactory),
)
@registry.register(name='music.FileImportJob')
class FileImportJobFactory(ImportJobFactory):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment