Faster tests by not creating covers unless mandatory

This commit is contained in:
Eliot Berriot 2020-03-23 14:29:01 +01:00
parent 48681c39db
commit c9259c906b
No known key found for this signature in database
GPG key ID: 6B501DFD73514E14
22 changed files with 110 additions and 68 deletions

View file

@ -86,6 +86,17 @@ class DomainFactory(NoUpdateOnCreate, factory.django.DjangoModelFactory):
return self.service_actor
_CACHE = {}
def get_cached_key_pair():
try:
return _CACHE["keys"]
except KeyError:
_CACHE["keys"] = keys.get_key_pair()
return _CACHE["keys"]
@registry.register
class ActorFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
public_key = None
@ -111,11 +122,14 @@ class ActorFactory(NoUpdateOnCreate, factory.DjangoModelFactory):
o.domain.name, o.preferred_username
)
)
keys = factory.LazyFunction(keys.get_key_pair)
keys = factory.LazyFunction(get_cached_key_pair)
class Meta:
model = models.Actor
class Params:
with_real_keys = factory.Trait(keys=factory.LazyFunction(keys.get_key_pair),)
@factory.post_generation
def local(self, create, extracted, **kwargs):
if not extracted and not kwargs:

View file

@ -64,7 +64,6 @@ class ArtistFactory(
mbid = factory.Faker("uuid4")
fid = factory.Faker("federation_url")
playable = playable_factory("track__album__artist")
attachment_cover = factory.SubFactory(common_factories.AttachmentFactory)
class Meta:
model = "music.Artist"
@ -74,6 +73,9 @@ class ArtistFactory(
attributed_to=factory.SubFactory(federation_factories.ActorFactory)
)
local = factory.Trait(fid=factory.Faker("federation_url", local=True))
with_cover = factory.Trait(
attachment_cover=factory.SubFactory(common_factories.AttachmentFactory)
)
@registry.register
@ -83,7 +85,6 @@ class AlbumFactory(
title = factory.Faker("sentence", nb_words=3)
mbid = factory.Faker("uuid4")
release_date = factory.Faker("date_object")
attachment_cover = factory.SubFactory(common_factories.AttachmentFactory)
artist = factory.SubFactory(ArtistFactory)
release_group_id = factory.Faker("uuid4")
fid = factory.Faker("federation_url")
@ -100,6 +101,9 @@ class AlbumFactory(
local = factory.Trait(
fid=factory.Faker("federation_url", local=True), artist__local=True
)
with_cover = factory.Trait(
attachment_cover=factory.SubFactory(common_factories.AttachmentFactory)
)
@registry.register
@ -112,7 +116,6 @@ class TrackFactory(
album = factory.SubFactory(AlbumFactory)
position = 1
playable = playable_factory("track")
attachment_cover = factory.SubFactory(common_factories.AttachmentFactory)
class Meta:
model = "music.Track"
@ -125,6 +128,9 @@ class TrackFactory(
local = factory.Trait(
fid=factory.Faker("federation_url", local=True), album__local=True
)
with_cover = factory.Trait(
attachment_cover=factory.SubFactory(common_factories.AttachmentFactory)
)
@factory.post_generation
def artist(self, created, extracted, **kwargs):