class ResourceCommentFactory(factory.django.DjangoModelFactory): resource = factory.SubFactory(ResourceFactory) comment = factory.Faker('paragraph', nb_sentences=5) class Meta: model = ResourceComment
class EmailBlockFactory(FormFieldBlockFactory): default_value = factory.Faker('email') class Meta: model = blocks.EmailBlock
class FaceFactory(factory.Factory): class Meta: model = Face smiley = factory.Faker('smiley') french_smiley = factory.Faker('smiley', locale='fr_FR')
class TagFactory(factory.DjangoModelFactory): class Meta: model = Tag name = factory.Faker("user_name")
class MonsterFactory(factory.Factory): """Definition of monster factory.""" class Meta: """Bind model to factory.""" model = Monster name = factory.Faker('word', ext_word_list=random_wordlist(prefix='Name_', max_length=40)) size = factory.Faker('word', ext_word_list=random_wordlist(prefix='Size_', max_length=40)) type_ = factory.Faker('word', ext_word_list=random_wordlist(prefix='Type_', max_length=40)) alignment = factory.Faker('word', ext_word_list=random_wordlist( prefix='Alignment_', max_length=40)) hit_points = factory.Faker('word', ext_word_list=random_wordlist( prefix='HitPoints_', max_length=40)) speed = factory.Faker('word', ext_word_list=random_wordlist(prefix='Speed_', max_length=40)) strength = factory.Faker('random_int', min=0, max=100) dexterity = factory.Faker('random_int', min=0, max=100) constitution = factory.Faker('random_int', min=0, max=100) intelligence = factory.Faker('random_int', min=0, max=100) wisdom = factory.Faker('random_int', min=0, max=100) charisma = factory.Faker('random_int', min=0, max=100) saving_throws = factory.Faker('word', ext_word_list=random_wordlist( prefix='SavingThrows_', max_length=40)) skills = factory.Faker('word', ext_word_list=random_wordlist(prefix='Skills_', max_length=40)) damage_immunities = factory.Faker('word', ext_word_list=random_wordlist( prefix='DamageImmunities_', max_length=40)) damage_vulnerabilities = factory.Faker('word', ext_word_list=random_wordlist( prefix='DamageVulnerabilities_', max_length=40)) damage_resistances = factory.Faker('word', ext_word_list=random_wordlist( prefix='DamageResistances_', max_length=40)) condition_immunities = factory.Faker('word', ext_word_list=random_wordlist( prefix='ConditionImmunities_', max_length=40)) senses = factory.Faker('word', ext_word_list=random_wordlist(prefix='Senses_', max_length=40)) languages = factory.Faker('word', ext_word_list=random_wordlist( prefix='Languages_', max_length=40)) challenge = factory.Faker('word', ext_word_list=random_wordlist( prefix='Challenge_', max_length=40)) experience = factory.Faker('word', ext_word_list=random_wordlist( prefix='Experience_', max_length=40)) description = factory.Faker('text', max_nb_chars=150)
class ModelFactory(factory_trytond.TrytonFactory): class Meta: model = 'test.model' name = factory.Faker('word')
class OrganisationFactory(factory.django.DjangoModelFactory): class Meta: model = Organisation name = factory.Faker('company')
class LayoutFactory(factory.django.DjangoModelFactory): class Meta: model = models.Layout name = factory.Faker("catch_phrase")
class ParserFactory(factory.django.DjangoModelFactory): class Meta: model = models.ParserMapping layout = factory.SubFactory(LayoutFactory) mime_type = factory.Faker("mime_type")
class GuideFactory(factory.django.DjangoModelFactory): title = factory.Faker('text', max_nb_chars=300, locale='pl_PL') created_by = factory.SubFactory(AdminFactory) class Meta: model = models.Guide
def dtfactory(start, end): return factory.Faker('date_time_between', start_date=start, end_date=end)
class OrganizationFactory(factory.DjangoModelFactory): """Factory for Organization.""" def _organization_name(): # pylint: disable=E0211 """Creates a fake organization name. Fake name consist of predicate1 + subject + predicate2 + propername np. "Wojewódzka Alternatywa Organizacyjna "Naprzód"". """ predicate1_dict = { "masculine": [ "Krajowy", "Wojewódzki", "Powiatowy", "Regionalny", "Wielkopolski", "Osiedlowy", "Stołeczny" ], "feminine": [ "Krajowa", "Wojewódzka", "Powiatowa", "Regionalna", "Wielkopolska", "Osiedlowa", "Stołeczna" ], "neutrum": [ "Krajowe", "Wojewódzkie", "Powiatowe", "Regionalne", "Wielkopolskie", "Osiedlowe", "Stołeczne" ] } noun_list = { "Fundacja": "feminine", "Rada": "feminine", "Urząd": "masculine", "Zarząd": "masculine", "Delegatura": "feminine", "Poradnia": "feminine", "Szpital": "masculine", "Ogród": "masculine", "Koło": "neutrum", "Obwód": "masculine" } predicate2_dict = { "masculine": [ "Organizacyjny", "Rejestrowy", "Egzekutywny", "Wspierający", "Transakcyjny", "Związkowy", "Zbiorczy" ], "feminine": [ "Organizacyjna", "Rejestrowa", "Egzekutywna", "Wspierająca", "Transakcyjna", "Związkowa", "Zbiorcza" ], "neutrum": [ "Organizacyjne", "Rejestrowe", "Egzekutywne", "Wspierające", "Transakcyjne", "Związkowe", "Zbiorcze" ] } propername_list = [ "Wspiera się", "Totuus", "Zawsze Razem", "W Kupie Siła", "Al Capone", "UKF", "Smak Miesiąca" ] subject = (FuzzyChoice(noun_list.keys())).fuzz() predicate1 = (FuzzyChoice(predicate1_dict[noun_list[subject]])).fuzz() predicate2 = (FuzzyChoice(predicate2_dict[noun_list[subject]])).fuzz() propername = (FuzzyChoice(propername_list)).fuzz() return "{0} {1} {2} {3}".format(predicate1, subject, predicate2, propername) class Meta: # pylint: disable=C0111 model = Organization name = factory.fuzzy.FuzzyAttribute(_organization_name) address = factory.Faker("address", locale="pl_PL") description = factory.Faker("paragraph")
class ImageFactory(factory.DjangoModelFactory): title = factory.Faker('word') file = get_test_image_file() class Meta: model = get_image_model()
class ServiceFactory(DjangoModelFactory): class Meta: model = Service name = factory.Faker("company")
class SourceSystemTypeFactory(factory.django.DjangoModelFactory): class Meta: model = models.SourceSystemType django_get_or_create = ("name",) name = factory.Faker("word")
class CompanyFactory(factory.django.DjangoModelFactory): """Company factory.""" created_by = factory.SubFactory(AdviserFactory) modified_by = factory.SelfAttribute('created_by') name = factory.Faker('company') trading_names = factory.List([ factory.Faker('company'), factory.Faker('company'), ]) address_1 = factory.Sequence(lambda x: f'{x} Fake Lane') address_town = 'Woodside' address_postcode = factory.Faker('postcode') address_country_id = constants.Country.united_kingdom.value.id registered_address_1 = factory.Sequence(lambda n: f'{n} Foo st.') registered_address_town = 'London' registered_address_postcode = factory.Faker('postcode') registered_address_country_id = constants.Country.united_kingdom.value.id business_type_id = BusinessTypeConstant.private_limited_company.value.id sector_id = constants.Sector.aerospace_assembly_aircraft.value.id archived = False uk_region_id = constants.UKRegion.england.value.id export_experience_category = factory.LazyFunction( ExportExperienceCategory.objects.order_by('?').first, ) turnover_range = factory.LazyFunction( lambda: random_obj_for_model(TurnoverRange)) employee_range = factory.LazyFunction( lambda: random_obj_for_model(EmployeeRange)) turnover = 100 is_turnover_estimated = True number_of_employees = 95 is_number_of_employees_estimated = True archived_documents_url_path = factory.Faker('uri_path') created_on = now() @to_many_field def export_to_countries(self): # noqa: D102 """ Add support for setting `export_to_countries`. """ return [] @to_many_field def future_interest_countries(self): # noqa: D102 """ Add support for setting `future_interest_countries`. """ return [] @to_many_field def export_countries(self): # noqa: D102 """ Add support for setting `export_countries`. """ return [] class Params: hq = factory.Trait(headquarter_type=factory.LazyFunction( lambda: random_obj_for_model(HeadquarterType)), ) class Meta: model = 'company.Company'
class UserFactory(factory.django.djangoModelFactory): class Meta: model = Usr username = factory.Faker('name')
class UserFactory(factory.django.DjangoModelFactory): class Meta: model = get_user_model() email = factory.Faker('ascii_free_email') password = make_password('123456')
class Params: name_base = factory.Faker("company")
class SponsorLevelFactory(DjangoModelFactory): conference = factory.SubFactory(ConferenceFactory) name = factory.Faker("word") class Meta: model = SponsorLevel
class OEmbedCacheFactory(factory.DjangoModelFactory): class Meta: model = OEmbedCache url = factory.Faker("url") oembed = factory.Faker("text")
class SpellFactory(factory.Factory): """Definition of spell factory.""" class Meta: """Bind model to factory.""" model = Spell name = factory.Faker('word', ext_word_list=random_wordlist(max_length=40, prefix='Spell_')) type_ = factory.Faker('random_element', elements=Fixtures['spell']['spellTypeOptions']) damage = factory.Faker('word', ext_word_list=random_wordlist(max_length=40, prefix='Damage_')) damage_type = factory.Faker('word', ext_word_list=random_wordlist( max_length=40, prefix='DamageType_')) school = factory.Faker('random_element', elements=Fixtures['spell']['spellSchoolOptions']) level = factory.Faker('random_int', min=0, max=10) material_components = factory.Faker('word', ext_word_list=random_wordlist( max_length=40, prefix='MaterialComponents_')) is_ritual = factory.Faker('boolean', chance_of_getting_true=50) prepared = factory.Faker('boolean', chance_of_getting_true=50) always_prepared = factory.Faker('boolean', chance_of_getting_true=50) casting_time = factory.Faker( 'random_element', elements=Fixtures['spell']['spellCastingTimeOptions']) components = factory.Faker( 'random_element', elements=Fixtures['spell']['spellComponentsOptions']) duration = factory.Faker( 'random_element', elements=Fixtures['spell']['spellDurationOptions']) range_ = factory.Faker('random_element', elements=Fixtures['spell']['spellRangeOptions']) description = factory.Faker('text', max_nb_chars=150)
class BaseProfileFactory(factory.Factory): class Meta: model = base.Profile handle = factory.Faker("safe_email") raw_content = factory.Faker("paragraphs", nb=3) email = factory.Faker("safe_email") gender = factory.Faker("job") location = "internet" nsfw = factory.Faker("pybool") public_key = factory.Faker("sha1") public = factory.Faker("pybool") guid = factory.Faker("uuid4") image_urls = { "small": factory.Faker("image_url", width=30, height=30).generate({}), "medium": factory.Faker("image_url", width=100, height=100).generate({}), "large": factory.Faker("image_url", width=300, height=300).generate({}), } tag_list = factory.Faker("words", nb=4)
class SafeMasterCopyFactory(MonitoredAddressFactory): version = factory.Sequence(lambda n: f'1.0.{n}') deployer = factory.Faker('company') class Meta: model = SafeMasterCopy
class TitleBlockFactory(FormFieldBlockFactory): default_value = factory.Faker('sentence') class Meta: model = blocks.TitleBlock
class MovieFactory(BaseFactory): class Meta: model = Movie title = factory.Faker("sentence") release_date = factory.Faker("date")
class FullNameBlockFactory(FormFieldBlockFactory): default_value = factory.Faker('name') class Meta: model = blocks.FullNameBlock
class PartitionFactory(factory.django.DjangoModelFactory): class Meta: model = Partition name = factory.Faker('sentence', nb_words=2, locale='ru_RU')
def test_simple_biased(self): self._setup_mock_faker(name="John Doe") faker_field = factory.Faker('name') self.assertEqual("John Doe", faker_field.generate({}))
class DatasetCommentFactory(factory.django.DjangoModelFactory): dataset = factory.SubFactory(DatasetFactory) comment = factory.Faker('paragraph', nb_sentences=5) class Meta: model = DatasetComment