class FAQFactory(DjangoModelFactory): conference = factory.SubFactory(ConferenceFactory) question = LanguageFactory("sentence") answer = LanguageFactory("sentence") class Meta: model = FAQ
class MenuLinkFactory(DjangoModelFactory): menu = factory.SubFactory(MenuFactory) title = LanguageFactory("sentence") href = LanguageFactory("slug") class Meta: model = MenuLink
class KeynoteFactory(DjangoModelFactory): conference = factory.SubFactory(ConferenceFactory) slug = LanguageFactory("slug") title = LanguageFactory("word") description = LanguageFactory("word") class Meta: model = Keynote
class EventFactory(DjangoModelFactory): conference = factory.SubFactory(ConferenceFactory) title = LanguageFactory("sentence") slug = LanguageFactory("slug") content = LanguageFactory("text") image = factory.django.ImageField() class Meta: model = Event
class JobListingFactory(DjangoModelFactory): title = LanguageFactory("sentence") slug = LanguageFactory("slug") description = LanguageFactory("sentence") company = LanguageFactory("sentence") company_logo = factory.django.ImageField() class Meta: model = JobListing
class KeynoteSpeakerFactory(DjangoModelFactory): keynote = factory.SubFactory(KeynoteFactory) name = factory.Faker("name") bio = LanguageFactory("word") pronouns = LanguageFactory("word") photo = factory.django.ImageField() class Meta: model = KeynoteSpeaker
class PostFactory(DjangoModelFactory): author_id = factory.Faker("pyint", min_value=1) title = LanguageFactory("sentence") slug = LanguageFactory("slug") excerpt = LanguageFactory("sentence") content = LanguageFactory("sentence") published = timezone.now() image = factory.django.ImageField() class Meta: model = Post
class PageFactory(DjangoModelFactory): conference = factory.SubFactory(ConferenceFactory) factory.Faker title = LanguageFactory("sentence") slug = LanguageFactory("slug") content = LanguageFactory("sentence") published = True image = factory.django.ImageField() class Meta: model = Page
class PostFactory(DjangoModelFactory): author = factory.SubFactory(UserFactory) title = LanguageFactory("sentence") slug = LanguageFactory("slug") excerpt = LanguageFactory("sentence") content = LanguageFactory("sentence") published = timezone.now() image = factory.django.ImageField() class Meta: model = Post
class DeadlineFactory(DjangoModelFactory): conference = factory.SubFactory(ConferenceFactory) type = factory.fuzzy.FuzzyChoice([deadline[0] for deadline in Deadline.TYPES]) name = LanguageFactory("sentence") description = LanguageFactory("sentence") start = factory.Faker("past_datetime", tzinfo=pytz.UTC) end = factory.Faker("future_datetime", tzinfo=pytz.UTC) class Meta: model = Deadline
class HotelRoomFactory(DjangoModelFactory): conference = factory.SubFactory(ConferenceFactory) name = LanguageFactory("name") description = LanguageFactory("text") total_capacity = factory.Faker("pyint", min_value=10) price = factory.Faker("pydecimal", min_value=1, left_digits=4, right_digits=2) class Meta: model = HotelRoom
class MenuFactory(DjangoModelFactory): title = LanguageFactory("sentence") conference = factory.SubFactory(ConferenceFactory) identifier = factory.Faker("slug") class Meta: model = Menu
class GenericCopyFactory(DjangoModelFactory): conference = factory.SubFactory(ConferenceFactory) key = factory.Faker("slug") content = LanguageFactory("sentence") class Meta: model = GenericCopy
class ConferenceFactory(DjangoModelFactory): name = LanguageFactory("name") code = factory.Faker("text", max_nb_chars=10) introduction = LanguageFactory("sentence") start = factory.Faker("past_datetime", tzinfo=pytz.UTC) end = factory.Faker("future_datetime", tzinfo=pytz.UTC) timezone = pytz.timezone("Europe/Rome") @classmethod def _create(cls, model_class, *args, **kwargs): specified_deadlines = {} for deadline in Deadline.TYPES: _type = deadline[0] value = kwargs.pop(f"active_{_type}", None) specified_deadlines[_type] = value instance = super()._create(model_class, *args, **kwargs) for _type, value in specified_deadlines.items(): if value is True: instance.deadlines.add( DeadlineFactory(conference=instance, type=_type)) elif value is False: instance.deadlines.add( DeadlineFactory( conference=instance, type=_type, start=timezone.now() - timezone.timedelta(days=10), end=timezone.now() - timezone.timedelta(days=5), )) return instance @factory.post_generation def topics(self, create, extracted, **kwargs): """Accepts a list of topic names and adds each topic to the Conference allowed submission topics. If a topic with that name doesn't exists, a new one is created. This fixture makes easier to add allowed topics to a Conference in the tests """ if not create: return if extracted: for topic in extracted: self.topics.add(Topic.objects.get_or_create(name=topic)[0]) @factory.post_generation def languages(self, create, extracted, **kwargs): """Accepts a list of language codes and adds each language to the Conference allowed languages. This fixture makes easier to add allowed languages to a Conference in the tests """ if not create: return if extracted: for language_code in extracted: self.languages.add(Language.objects.get(code=language_code)) @factory.post_generation def submission_types(self, create, extracted, **kwargs): """Accepts a list of submission type names and adds each submission type to the Conference allowed submission types. If a submission type with that name doesn't exists, a new one is created. This fixture makes easier to add allowed submission types to a Conference in the tests """ if not create: return if extracted: for submission_type in extracted: self.submission_types.add( SubmissionType.objects.get_or_create( name=submission_type)[0]) @factory.post_generation def durations(self, create, extracted, **kwargs): """Accepts a list of durations (in minutes) and creates a duration object to the Conference allowed durations. This fixture makes easier to add durations to a Conference in the tests """ if not create: return if extracted: for duration in extracted: duration, created = Duration.objects.get_or_create( duration=duration, conference=self, defaults={"name": f"{duration}m"}, ) if created: duration.allowed_submission_types.set( SubmissionType.objects.all()) self.durations.add(duration) @factory.post_generation def audience_levels(self, create, extracted, **kwargs): if not create: return if extracted: for audience_level in extracted: self.audience_levels.add( AudienceLevel.objects.get_or_create( name=audience_level)[0]) class Meta: model = Conference django_get_or_create = ("code", )