Refactor tests.db.fake_data.factories into a package

This commit is contained in:
Alexander Hess 2021-09-15 11:54:45 +02:00
commit f891fac3dc
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
10 changed files with 236 additions and 172 deletions

View 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)