Refactor tests.db.fake_data.factories into a package
This commit is contained in:
parent
7e23033d84
commit
f891fac3dc
10 changed files with 236 additions and 172 deletions
27
tests/db/fake_data/factories/utils.py
Normal file
27
tests/db/fake_data/factories/utils.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
"""Utilities used in all `*Factory` classes."""
|
||||
|
||||
import datetime as dt
|
||||
import random
|
||||
|
||||
from tests import config as test_config
|
||||
|
||||
|
||||
def random_timespan( # noqa:WPS211
|
||||
*,
|
||||
min_hours=0,
|
||||
min_minutes=0,
|
||||
min_seconds=0,
|
||||
max_hours=0,
|
||||
max_minutes=0,
|
||||
max_seconds=0,
|
||||
):
|
||||
"""A randomized `timedelta` object between the specified arguments."""
|
||||
total_min_seconds = min_hours * 3600 + min_minutes * 60 + min_seconds
|
||||
total_max_seconds = max_hours * 3600 + max_minutes * 60 + max_seconds
|
||||
return dt.timedelta(seconds=random.randint(total_min_seconds, total_max_seconds))
|
||||
|
||||
|
||||
def early_in_the_morning():
|
||||
"""A randomized `datetime` object early in the morning."""
|
||||
early = dt.datetime(test_config.YEAR, test_config.MONTH, test_config.DAY, 3, 0)
|
||||
return early + random_timespan(max_hours=2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue