2020-03-13 11:16:51 +00:00
|
|
|
import uuid
|
|
|
|
|
2019-11-25 08:49:49 +00:00
|
|
|
import factory
|
|
|
|
|
|
|
|
from funkwhale_api.factories import registry, NoUpdateOnCreate
|
2020-03-13 11:16:51 +00:00
|
|
|
from funkwhale_api.federation import actors
|
2019-11-25 08:49:49 +00:00
|
|
|
from funkwhale_api.federation import factories as federation_factories
|
|
|
|
from funkwhale_api.music import factories as music_factories
|
|
|
|
|
|
|
|
from . import models
|
|
|
|
|
|
|
|
|
|
|
|
def set_actor(o):
|
|
|
|
return models.generate_actor(str(o.uuid))
|
|
|
|
|
|
|
|
|
2020-03-13 11:16:51 +00:00
|
|
|
def get_rss_channel_name():
|
|
|
|
return "rssfeed-{}".format(uuid.uuid4())
|
|
|
|
|
|
|
|
|
2019-11-25 08:49:49 +00:00
|
|
|
@registry.register
|
|
|
|
class ChannelFactory(NoUpdateOnCreate, factory.django.DjangoModelFactory):
|
|
|
|
uuid = factory.Faker("uuid4")
|
|
|
|
attributed_to = factory.SubFactory(federation_factories.ActorFactory)
|
|
|
|
library = factory.SubFactory(
|
|
|
|
federation_factories.MusicLibraryFactory,
|
|
|
|
actor=factory.SelfAttribute("..attributed_to"),
|
2019-12-09 12:59:54 +00:00
|
|
|
privacy_level="everyone",
|
2019-11-25 08:49:49 +00:00
|
|
|
)
|
|
|
|
actor = factory.LazyAttribute(set_actor)
|
2020-01-30 14:00:55 +00:00
|
|
|
artist = factory.SubFactory(
|
|
|
|
music_factories.ArtistFactory,
|
|
|
|
attributed_to=factory.SelfAttribute("..attributed_to"),
|
|
|
|
)
|
2020-02-07 09:48:17 +00:00
|
|
|
rss_url = factory.Faker("url")
|
2020-01-30 16:28:52 +00:00
|
|
|
metadata = factory.LazyAttribute(lambda o: {})
|
2019-11-25 08:49:49 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = "audio.Channel"
|
|
|
|
|
|
|
|
class Params:
|
2020-03-13 11:16:51 +00:00
|
|
|
external = factory.Trait(
|
|
|
|
attributed_to=factory.LazyFunction(actors.get_service_actor),
|
|
|
|
library__privacy_level="me",
|
|
|
|
actor=factory.SubFactory(
|
|
|
|
federation_factories.ActorFactory,
|
|
|
|
local=True,
|
|
|
|
preferred_username=factory.LazyFunction(get_rss_channel_name),
|
|
|
|
),
|
|
|
|
)
|
2019-11-25 08:49:49 +00:00
|
|
|
local = factory.Trait(
|
2019-12-09 12:59:54 +00:00
|
|
|
attributed_to=factory.SubFactory(
|
|
|
|
federation_factories.ActorFactory, local=True
|
|
|
|
),
|
2020-03-13 11:16:51 +00:00
|
|
|
library__privacy_level="everyone",
|
2019-11-25 08:49:49 +00:00
|
|
|
artist__local=True,
|
|
|
|
)
|
2020-01-15 13:24:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
@registry.register(name="audio.Subscription")
|
|
|
|
class SubscriptionFactory(NoUpdateOnCreate, factory.django.DjangoModelFactory):
|
|
|
|
uuid = factory.Faker("uuid4")
|
|
|
|
approved = True
|
|
|
|
target = factory.LazyAttribute(lambda o: ChannelFactory().actor)
|
|
|
|
actor = factory.SubFactory(federation_factories.ActorFactory)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = "federation.Follow"
|