-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(utils): add picture factory and global fixture
- Loading branch information
1 parent
9c75121
commit 0cadd70
Showing
4 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Factories for Utils App.""" | ||
|
||
import factory | ||
from uuid import uuid4 | ||
from django.contrib.contenttypes.models import ContentType | ||
|
||
from apps.animes.models import Anime | ||
from apps.mangas.models import Manga | ||
from apps.characters.models import Character | ||
from apps.persons.models import Person | ||
from ..models import Picture | ||
from ..functions import generate_test_image, generate_random_code | ||
|
||
|
||
class PictureFactory(factory.django.DjangoModelFactory): | ||
"""Factory for Picture model.""" | ||
|
||
class Meta: | ||
model = Picture | ||
skip_postgeneration_save = True | ||
|
||
content_type = factory.LazyAttribute( | ||
lambda o: ContentType.objects.get_for_model(o.content_object.__class__) | ||
) | ||
object_id = factory.LazyAttribute(lambda o: uuid4()) | ||
name = factory.LazyFunction(lambda: generate_random_code()) | ||
image = factory.LazyAttribute(lambda _: generate_test_image(size=(600, 600))) | ||
|
||
@factory.lazy_attribute | ||
def content_object(self): | ||
model_mapping = { | ||
"anime": Anime.objects.first(), | ||
"manga": Manga.objects.first(), | ||
"character": Character.objects.first(), | ||
"person": Person.objects.first(), | ||
} | ||
content_type_model = model_mapping.get(self.content_type.model) | ||
return content_type_model |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters