class QuestionFactory(DjangoModelFactory): slug = Faker("slug") label = Faker("multilang", faker_provider="name") type = Faker("word", ext_word_list=AUTO_QUESTION_TYPES) is_required = "true" is_hidden = "false" configuration = {} meta = {} is_archived = False format_validators = [] row_form = Maybe("is_table", yes_declaration=SubFactory(FormFactory), no_declaration=None) sub_form = Maybe("is_form", yes_declaration=SubFactory(FormFactory), no_declaration=None) static_content = Maybe( "is_static", yes_declaration=Faker("multilang", faker_provider="text"), no_declaration=None, ) data_source = Maybe("is_dynamic", yes_declaration="MyDataSource", no_declaration=None) calc_expression = Maybe("is_calc_float", yes_declaration="-1.0", no_declaration=None) calc_dependents = [] class Meta: model = models.Question class Params: is_table = LazyAttribute( lambda q: q.type == models.Question.TYPE_TABLE) is_form = LazyAttribute(lambda q: q.type == models.Question.TYPE_FORM) is_dynamic = LazyAttribute(lambda q: q.type in [ models.Question.TYPE_DYNAMIC_CHOICE, models.Question.TYPE_DYNAMIC_MULTIPLE_CHOICE, ]) is_static = LazyAttribute( lambda q: q.type == models.Question.TYPE_STATIC) is_calc_float = LazyAttribute( lambda q: q.type == models.Question.TYPE_CALCULATED_FLOAT)
class IdentityFactory(DjangoModelFactory): idp_id = Faker("uuid4") email = Faker("email") is_organisation = False organisation_name = Maybe("is_organisation", Faker("company"), None) first_name = Faker("first_name") last_name = Faker("last_name") class Meta: model = models.Identity
class AnswerFactory(DjangoModelFactory): question = SubFactory(QuestionFactory) document = SubFactory(DocumentFactory) meta = {} @lazy_attribute def value(self): if (self.question.type == models.Question.TYPE_MULTIPLE_CHOICE or self.question.type == models.Question.TYPE_DYNAMIC_MULTIPLE_CHOICE): return [Faker("name").generate({}), Faker("name").generate({})] elif self.question.type == models.Question.TYPE_FLOAT: return Faker("pyfloat").generate({}) elif self.question.type == models.Question.TYPE_INTEGER: return Faker("pyint").generate({}) elif self.question.type not in [ models.Question.TYPE_FORM, models.Question.TYPE_TABLE, models.Question.TYPE_FILE, models.Question.TYPE_DATE, ]: return Faker("name").generate({}) return None value_document = Maybe("is_form", yes_declaration=SubFactory(DocumentFactory), no_declaration=None) file = Maybe("is_file", yes_declaration=SubFactory(FileFactory), no_declaration=None) date = Maybe("is_date", yes_declaration=Faker("date"), no_declaration=None) class Meta: model = models.Answer class Params: is_form = LazyAttribute( lambda a: a.question.type == models.Question.TYPE_FORM) is_file = LazyAttribute( lambda a: a.question.type == models.Question.TYPE_FILE) is_date = LazyAttribute( lambda a: a.question.type == models.Question.TYPE_DATE)