class PropertyFactory(Factory): class Meta: model = Property sale_price = fuzzy.FuzzyAttribute(lambda: randint(*SALE_BOUNDARIES)) rental_price = fuzzy.FuzzyAttribute(lambda: randint(*RENTAL_BOUNDARIES)) owner = SubFactory(PlayerFactory)
class ProgramFactory(DjangoModelFactory): """Factory for Programs""" title = fuzzy.FuzzyText(prefix="Program ") live = fuzzy.FuzzyAttribute(FAKE.boolean) description = fuzzy.FuzzyText() class Meta: # pylint: disable=missing-docstring model = Program
def test_simple_call(self): d = fuzzy.FuzzyAttribute(lambda: 10) res = d.evaluate(2, None, False) self.assertEqual(10, res) res = d.evaluate(2, None, False) self.assertEqual(10, res)
def test_simple_call(self): d = fuzzy.FuzzyAttribute(lambda: 10) res = utils.evaluate_declaration(d) self.assertEqual(10, res) res = utils.evaluate_declaration(d) self.assertEqual(10, res)
class ScoringSettingsFactory(factory.django.DjangoModelFactory): class Meta: model = ScoringSettings league = factory.SubFactory(FantasyLeagueFactory) scoring_type = fuzzy.FuzzyChoice([CATEGORY, POINTS]) scoring_fields_vals = fuzzy.FuzzyAttribute( fuzzer=create_random_scoring_fields)
class DailyAssetInfoFactory(DailyPricingObjectFactory): FACTORY_FOR = models.DailyAssetInfo asset_info = SubFactory(AssetInfoFactory) depreciation_rate = fuzzy.FuzzyDecimal(0, 50) is_depreciated = fuzzy.FuzzyAttribute(lambda: random.random() < 0.5) price = fuzzy.FuzzyDecimal(0, 1000) date = fuzzy.FuzzyDate(MIN_FACTORY_DATE, MAX_FACTORY_DATE)
class JobSiteFactory(factory.django.DjangoModelFactory): class Meta: model = JobSite name = fuzzy.FuzzyText(length=15) address = fuzzy.FuzzyText(length=15) city = fuzzy.FuzzyText(length=15) postal_code = fuzzy.FuzzyAttribute(lambda: str(random.randint(1024, 9999)))
class SignalFactory(factory.DjangoModelFactory): class Meta: model = Signal signal_id = fuzzy.FuzzyAttribute(uuid.uuid4) text = fuzzy.FuzzyText(length=100) text_extra = fuzzy.FuzzyText(length=100) # Creating (reverse FK) related objects after this `Signal` is created. location = factory.RelatedFactory( 'tests.apps.signals.factories.LocationFactory', '_signal') status = factory.RelatedFactory( 'tests.apps.signals.factories.StatusFactory', '_signal') category_assignment = factory.RelatedFactory( 'tests.apps.signals.factories.CategoryAssignmentFactory', '_signal') reporter = factory.RelatedFactory( 'tests.apps.signals.factories.ReporterFactory', '_signal') priority = factory.RelatedFactory( 'tests.apps.signals.factories.PriorityFactory', '_signal') incident_date_start = fuzzy.FuzzyDateTime( datetime(2017, 11, 1, tzinfo=pytz.UTC), datetime(2018, 2, 1, tzinfo=pytz.UTC), ) incident_date_end = fuzzy.FuzzyDateTime( datetime(2018, 2, 2, tzinfo=pytz.UTC), datetime(2019, 2, 2, tzinfo=pytz.UTC)) extra_properties = {} # SIG-884 parent = None @factory.post_generation def set_one_to_one_relations(self, create, extracted, **kwargs): """Set o2o relations on given `Signal` object.""" self.location = self.locations.last() self.status = self.statuses.last() self.category_assignment = self.category_assignments.last() self.reporter = self.reporters.last() self.priority = self.priorities.last() @factory.post_generation def set_default_type(self, create, extracted, **kwargs): """ This will add the default Type to the signal for a factory created signal """ if create: TypeFactory( _signal=self) # By default the type is set to "SIG (SIGNAL)"
class SitueringFactory(factory.DjangoModelFactory): class Meta(object): model = models.Situering betreft_nummeraanduiding = fuzzy.FuzzyInteger(low=0) # situering_nummeraanduiding = models.CharField(length=128, null=True) eerste_situering = fuzzy.FuzzyAttribute(gen_janee) huisnummer = fuzzy.FuzzyInteger(low=1) if random.randint(0, 50) % 3 == 0: huisletter = fuzzy.FuzzyText(length=1) if random.randint(0, 50) % 3 == 0: huisnummertoevoeging = fuzzy.FuzzyText(length=4) postcode = fuzzy.FuzzyText(length=6) straat = fuzzy.FuzzyText(length=80)
class RecipeFactory(DjangoModelFactory): ctime = fuzzy.FuzzyDateTime( start_dt=make_aware(datetime(2010, 1, 1)), end_dt=make_aware(datetime(2016, 1, 1)), ) name = fuzzy.FuzzyAttribute(generate_recipe_name) content = Faker('text') creator = fuzzy.FuzzyAttribute(pick_creator) class Meta: model = Recipe @post_generation def clean(self, create, extracted, **kwargs): self.clean() @post_generation def ratings(self, create, extracted, **kwargs): for rater in User.objects.order_by('?')[:random.randint(0, 5)]: RecipeRating.objects.create( recipe=self, rater=rater, rating=random.randint(1, 6), )
class ApartmentMinimalFactory(factory.Factory): class Meta: model = ApartmentTest _language = fuzzy.FuzzyChoice(["en", "fi"]) project_id = fuzzy.FuzzyInteger(0, 9999999999) # mandatory fields for vendors: project_uuid = str(uuid.uuid4()) uuid = fuzzy.FuzzyAttribute(get_uuid) project_housing_company = fuzzy.FuzzyText() project_holding_type = "RIGHT_OF_RESIDENCE_APARTMENT" project_street_address = fuzzy.FuzzyText() project_postal_code = fuzzy.FuzzyText(length=6, chars=string.digits) project_city = "Helsinki" project_building_type = "BLOCK_OF_FLATS" project_estate_agent = fuzzy.FuzzyText() project_estate_agent_email = Faker("email") apartment_number = fuzzy.FuzzyInteger(0, 99) # optional fields for vendors project_district = fuzzy.FuzzyText() project_realty_id = fuzzy.FuzzyText() project_new_development_status = fuzzy.FuzzyChoice( NEW_DEVELOPMENT_STATUS_MAPPING.keys()) project_new_housing = True project_apartment_count = fuzzy.FuzzyInteger(0, 9999999999) project_estimated_completion = fuzzy.FuzzyText() room_count = fuzzy.FuzzyInteger(0, 9999999999) sales_price = fuzzy.FuzzyInteger(0, 9999999999) debt_free_sales_price = fuzzy.FuzzyInteger(0, 9999999999) project_state_of_sale = fuzzy.FuzzyChoice( ["PRE_MARKETING", "FOR_SALE", "SOLD"]) apartment_state_of_sale = fuzzy.FuzzyChoice(["RESERVED", "FOR_SALE"]) project_description = fuzzy.FuzzyText(length=200) url = fuzzy.FuzzyText(length=20) @classmethod def build_for_sale_batch(cls, size: int) -> List[ApartmentTest]: return [ cls.build( publish_on_etuovi=True, publish_on_oikotie=True, apartment_state_of_sale="FOR_SALE", _language="fi", ) for _ in range(size) ]
class ApartmentFactory(factory.Factory): class Meta: model = ApartmentTest _language = fuzzy.FuzzyChoice(["en", "fi", "sv"]) project_id = fuzzy.FuzzyInteger(0, 9999999999) project_uuid = str(uuid.uuid4()) project_housing_company = fuzzy.FuzzyText() project_holding_type = "RIGHT_OF_RESIDENCE_APARTMENT" project_street_address = fuzzy.FuzzyText() project_postal_code = fuzzy.FuzzyText(length=6, chars=string.digits) project_city = "Helsinki" project_district = fuzzy.FuzzyText() project_realty_id = fuzzy.FuzzyText() project_construction_year = fuzzy.FuzzyInteger(2000, 3000) project_new_development_status = fuzzy.FuzzyChoice( NEW_DEVELOPMENT_STATUS_MAPPING.keys()) project_new_housing = True project_apartment_count = fuzzy.FuzzyInteger(0, 9999999999) project_parkingplace_count = fuzzy.FuzzyInteger(0, 9999999999) project_has_elevator = True project_has_sauna = True project_construction_materials = factory.List( [fuzzy.FuzzyText() for _ in range(2)]) project_roof_material = fuzzy.FuzzyText() project_heating_options = factory.List( [fuzzy.FuzzyText() for _ in range(2)]) project_energy_class = fuzzy.FuzzyText() project_site_area = fuzzy.FuzzyFloat(0, 9999999999) project_site_owner = fuzzy.FuzzyChoice(["Oma", "Vuokra"]) project_site_renter = fuzzy.FuzzyText() project_sanitation = fuzzy.FuzzyText() project_zoning_info = fuzzy.FuzzyText() project_zoning_status = fuzzy.FuzzyText() project_building_type = "BLOCK_OF_FLATS" project_description = fuzzy.FuzzyText(length=200) url = fuzzy.FuzzyText(length=20) project_accessibility = fuzzy.FuzzyText() project_smoke_free = fuzzy.FuzzyText() project_publication_start_time = (fuzzy.FuzzyDateTime( timezone.now()).fuzz().strftime("%Y-%m-%dT%H:%M:%S%z")) project_publication_end_time = (fuzzy.FuzzyDateTime( timezone.now()).fuzz().strftime("%Y-%m-%dT%H:%M:%S%z")) project_premarketing_start_time = fuzzy.FuzzyDateTime(timezone.now()) project_premarketing_end_time = fuzzy.FuzzyDateTime(timezone.now()) project_application_start_time = fuzzy.FuzzyDateTime(timezone.now()) project_application_end_time = fuzzy.FuzzyDateTime(timezone.now()) project_material_choice_dl = fuzzy.FuzzyDate(date.today()) project_shareholder_meeting_date = fuzzy.FuzzyDate(date.today()) project_estimated_completion = fuzzy.FuzzyText() project_estimated_completion_date = fuzzy.FuzzyDate(date.today()) project_completion_date = fuzzy.FuzzyDate(date.today()) project_posession_transfer_date = fuzzy.FuzzyDate(date.today()) project_attachment_urls = factory.List( [fuzzy.FuzzyText() for _ in range(2)]) project_main_image_url = fuzzy.FuzzyText() project_image_urls = factory.List([fuzzy.FuzzyText() for _ in range(2)]) project_virtual_presentation_url = fuzzy.FuzzyText() project_acc_salesperson = fuzzy.FuzzyText() project_acc_financeofficer = fuzzy.FuzzyText() project_project_manager = fuzzy.FuzzyText() project_constructor = fuzzy.FuzzyText() project_housing_manager = fuzzy.FuzzyText() project_estate_agent = fuzzy.FuzzyText() project_estate_agent_email = Faker("email") project_estate_agent_phone = fuzzy.FuzzyText() project_coordinate_lat = fuzzy.FuzzyFloat(-90, 90) project_coordinate_lon = fuzzy.FuzzyFloat(-180, 180) project_state_of_sale = fuzzy.FuzzyChoice(ProjectStateOfSale) apartment_state_of_sale = fuzzy.FuzzyChoice(ApartmentStateOfSale) uuid = fuzzy.FuzzyAttribute(get_uuid) apartment_address = fuzzy.FuzzyText() apartment_number = fuzzy.FuzzyInteger(0, 99) housing_shares = fuzzy.FuzzyText() living_area = fuzzy.FuzzyFloat(0, 9999999999) floor = fuzzy.FuzzyInteger(0, 9999999999) floor_max = fuzzy.FuzzyInteger(0, 9999999999) showing_times = factory.List([ fuzzy.FuzzyDateTime( timezone.now()).fuzz().strftime("%Y-%m-%dT%H:%M:%S%z") for _ in range(2) ]) apartment_structure = fuzzy.FuzzyText() room_count = fuzzy.FuzzyInteger(0, 9999999999) condition = "Uusi" kitchen_appliances = fuzzy.FuzzyText() has_yard = True has_terrace = True has_balcony = True balcony_description = fuzzy.FuzzyText() bathroom_appliances = fuzzy.FuzzyText() storage_description = fuzzy.FuzzyText() has_apartment_sauna = True apartment_holding_type = "RIGHT_OF_RESIDENCE_APARTMENT" view_description = fuzzy.FuzzyText() sales_price = fuzzy.FuzzyInteger(0, 9999999999) debt_free_sales_price = fuzzy.FuzzyInteger(0, 9999999999) loan_share = fuzzy.FuzzyInteger(0, 9999999999) price_m2 = fuzzy.FuzzyInteger(0, 9999999999) housing_company_fee = fuzzy.FuzzyInteger(0, 9999999999) financing_fee = fuzzy.FuzzyInteger(0, 9999999999) financing_fee_m2 = fuzzy.FuzzyInteger(0, 9999999999) maintenance_fee = fuzzy.FuzzyInteger(0, 9999999999) maintenance_fee_m2 = fuzzy.FuzzyInteger(0, 9999999999) water_fee = fuzzy.FuzzyInteger(0, 9999999999) water_fee_explanation = fuzzy.FuzzyText() parking_fee = fuzzy.FuzzyInteger(0, 9999999999) parking_fee_explanation = fuzzy.FuzzyText() other_fees = fuzzy.FuzzyText() services_description = fuzzy.FuzzyText() additional_information = fuzzy.FuzzyText() application_url = fuzzy.FuzzyText() image_urls = factory.List([fuzzy.FuzzyText() for _ in range(2)])