velofy/tests/db/fake_data/factories/addresses.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1.3 KiB
Python
Raw Permalink Normal View History

"""Factory to create `Address` instances."""
import random
import string
import factory
from factory import alchemy
from tests.db.fake_data.factories import utils
from velofy import db
class AddressFactory(alchemy.SQLAlchemyModelFactory):
"""Create instances of the `db.Address` model."""
class Meta:
model = db.Address
sqlalchemy_get_or_create = ("id",)
2026-11-28 02:01:12 +01:00
id = factory.Sequence(lambda num: num)
created_at = factory.LazyFunction(utils.early_in_the_morning)
# Non-primary addresses behave no differently in the tests
# => Treat all addresses as primary ones
primary_id = factory.LazyAttribute(lambda obj: obj.id)
# Mimic a Google Maps Place ID with just random characters
place_id = factory.LazyFunction(
lambda: "".join(random.choice(string.ascii_lowercase) for _ in range(20)),
)
# Place the addresses somewhere in downtown Paris
latitude = factory.Faker("pyfloat", min_value=48.845, max_value=48.865)
longitude = factory.Faker("pyfloat", min_value=2.31, max_value=2.37)
# city -> set by the `make_address` fixture as there is only one `city`
city_name = "Paris"
zip_code = factory.LazyFunction(lambda: random.randint(75001, 75020))
street = factory.Faker("street_address", locale="fr_FR")