feat [server]: film factory
This commit is contained in:
parent
3669ddacb3
commit
0edfb4b336
2 changed files with 34 additions and 0 deletions
33
server/myapi/factories.py
Normal file
33
server/myapi/factories.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
import factory
|
||||
import random
|
||||
|
||||
from myapi.models import Film
|
||||
|
||||
|
||||
class ModelFieldLazyChoice(factory.LazyFunction):
|
||||
def __init__(self, model_class, field, *args, **kwargs):
|
||||
choices = [choice[0] for choice in model_class._meta.get_field(field).choices]
|
||||
super(ModelFieldLazyChoice, self).__init__(
|
||||
function=lambda: random.choice(choices),
|
||||
*args, **kwargs
|
||||
)
|
||||
|
||||
class FilmFactory(factory.django.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Film
|
||||
|
||||
projection_date = factory.Faker("date_time_this_year")
|
||||
title = factory.Faker("text", max_nb_chars=30)
|
||||
actors = factory.List([factory.Faker("name") for i in range(5)])
|
||||
director = factory.Faker("name")
|
||||
synopsis = factory.Faker("paragraph")
|
||||
origin_country = factory.Faker("country")
|
||||
release_year = factory.Faker("year")
|
||||
trailer_link = "https://www.youtube-nocookie.com/embed/lRLBR98-FZ8"
|
||||
is_in_color = factory.Faker("boolean")
|
||||
movie_format = ModelFieldLazyChoice(Film, "movie_format")
|
||||
language_subtitles = ModelFieldLazyChoice(Film, "language_subtitles")
|
||||
poster_link = "https://fr.web.img6.acsta.net/pictures/22/01/18/10/13/5983633.jpg"
|
||||
banner_link = "https://fr.web.img6.acsta.net/pictures/22/01/18/10/13/5983633.jpg"
|
||||
is_confirmed = factory.Faker("boolean")
|
||||
facebook_event_link = "https://www.facebook.com/events/1074495033473403"
|
|
@ -4,3 +4,4 @@ django-cors-headers==3.11.0
|
|||
djangorestframework-camel-case==1.3.0
|
||||
getconf~=1.11.1
|
||||
tmdbv3api~=1.7.6
|
||||
factory-boy==3.2.1
|
||||
|
|
Loading…
Reference in a new issue