Skip to content

Add the seq feature for better testing and uniqueness #25

@huogerac

Description

@huogerac

The model bakery has interesting features that we should use here too:
Does make sense add this in this library?

customers = baker.make('Customer', name=baker.seq('Test'), _quantity=3)
for customer in customers:
     print(customer.name)
#  'Test1'
#  'Test2'
#  'Test3'

Also this can be used for dates:

start_date = datetime(2025, 3, 13, 9, 0, 0)

# Create 3 customers with created_at increasing by 1 day
customers = baker.make(
    'Customer',
    name=baker.seq('Chad'),
    created_at=baker.seq(start_date, timedelta(days=1)),
    _quantity=3
)

for customer in customers:
    print(customer.name, customer.created_at)

Chad1 2025-03-13 09:00:00
Chad2 2025-03-14 09:00:00
Chad3 2025-03-15 09:00:00

Others options:

base_datetime = datetime(2024, 3, 13, 9, 0, 0)  # Start at 9:00 AM

messages = baker.make(
    "app.Message",
    created_at=baker.seq(base_datetime, timedelta(minutes=5)),  # Increments by 5 minutes
    _quantity=100
)


# Other model bakery feature is using a list, for example, to have many messages aleatory in the same day:
import random

messages = baker.make(
    "app.Message",
    created_at=[base_datetime + timedelta(minutes=random.randint(0, 1440)) for _ in range(100)],
    _quantity=100
)


baker.make(
    'Customer',
    age=seq(15, increment_by=3)
    height_ft=seq(5.5, increment_by=.25)
    appointment=seq(date(2014, 7, 21), timedelta(days=1)),
    name=seq('Custom num: ', increment_by=2, start=5),
)

# output
customer.age    # 18
customer.height_ft    # 5.75
customer.appointment    # datetime.date(2014, 7, 22)
customer.name    # 'Custom num: 5'

new_customer.age    # 21
new_customer.height_ft    # 6.0
new_customer.appointment    # datetime.date(2014, 7, 23)
customer.name    # 'Custom num: 7'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions