in modules/util.py [0:0]
def fake_autofill_data(self, country_code) -> AutofillAddressBase:
"""
Generates fake autofill data for a given country code.
"""
# valid attributes to get region for locale
region_attributes = ["state", "administrative_unit", "region"]
fake, valid_code = self.create_localized_faker(country_code)
name = fake.name()
given_name, family_name = name.split()
organization = fake.company().replace(",", "")
street_address = fake.street_address()
# find correct attribute for selected locale
valid_attribute = next(
filter(lambda attr: hasattr(fake, attr), region_attributes), None
)
# set correct region if valid attribute is found else none
address_level_1 = (
getattr(fake, valid_attribute)() if valid_attribute else valid_attribute
)
address_level_2 = fake.city()
postal_code = fake.postcode()
country = fake.current_country()
email = fake.email()
telephone = self.generate_localized_phone(country_code, fake)
fake_data = AutofillAddressBase(
name=name,
family_name=family_name,
given_name=given_name,
organization=organization,
street_address=street_address,
address_level_2=address_level_2,
address_level_1=address_level_1,
postal_code=postal_code,
country=country,
country_code=country_code,
email=email,
telephone=telephone,
)
return fake_data