diff --git a/tests/config.py b/tests/config.py index 2af0d60..b99c8a9 100644 --- a/tests/config.py +++ b/tests/config.py @@ -7,6 +7,8 @@ from urban_meal_delivery import config # The day on which most test cases take place. YEAR, MONTH, DAY = 2016, 7, 1 +# Same day as a `tuple`. +DATE = (YEAR, MONTH, DAY) # The hour when most test cases take place. NOON = 12 diff --git a/tests/db/fake_data/factories/orders/ad_hoc.py b/tests/db/fake_data/factories/orders/ad_hoc.py index 9fde451..b6090f1 100644 --- a/tests/db/fake_data/factories/orders/ad_hoc.py +++ b/tests/db/fake_data/factories/orders/ad_hoc.py @@ -70,9 +70,7 @@ class AdHocOrderFactory(alchemy.SQLAlchemyModelFactory): # Attributes regarding the specialization of an `Order`: ad-hoc or scheduled. # Ad-hoc `Order`s are placed between 11.45 and 14.15. placed_at = factory.LazyFunction( - lambda: dt.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 11, 45, - ) + lambda: dt.datetime(*test_config.DATE, 11, 45) + utils.random_timespan(max_hours=2, max_minutes=30), ) ad_hoc = True diff --git a/tests/db/fake_data/factories/orders/scheduled.py b/tests/db/fake_data/factories/orders/scheduled.py index 4e71bdb..27c1798 100644 --- a/tests/db/fake_data/factories/orders/scheduled.py +++ b/tests/db/fake_data/factories/orders/scheduled.py @@ -27,27 +27,13 @@ class ScheduledOrderFactory(ad_hoc.AdHocOrderFactory): scheduled_delivery_at = factory.LazyFunction( lambda: random.choice( [ - dt.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 12, 0, - ), - dt.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 12, 15, - ), - dt.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 12, 30, - ), - dt.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 12, 45, - ), - dt.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 13, 0, - ), - dt.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 13, 15, - ), - dt.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 13, 30, - ), + dt.datetime(*test_config.DATE, 12, 0), + dt.datetime(*test_config.DATE, 12, 15), + dt.datetime(*test_config.DATE, 12, 30), + dt.datetime(*test_config.DATE, 12, 45), + dt.datetime(*test_config.DATE, 13, 0), + dt.datetime(*test_config.DATE, 13, 15), + dt.datetime(*test_config.DATE, 13, 30), ], ), ) diff --git a/tests/db/fake_data/factories/utils.py b/tests/db/fake_data/factories/utils.py index 953cddf..28142a9 100644 --- a/tests/db/fake_data/factories/utils.py +++ b/tests/db/fake_data/factories/utils.py @@ -23,5 +23,5 @@ def random_timespan( # noqa:WPS211 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) + early = dt.datetime(*test_config.DATE, 3, 0) return early + random_timespan(max_hours=2) diff --git a/tests/forecasts/conftest.py b/tests/forecasts/conftest.py index f258a3c..522eb0f 100644 --- a/tests/forecasts/conftest.py +++ b/tests/forecasts/conftest.py @@ -17,9 +17,7 @@ def horizontal_datetime_index(): The times resemble a horizontal time series with a `frequency` of `7`. All observations take place at `NOON`. """ - first_start_at = dt.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, test_config.NOON, 0, - ) + first_start_at = dt.datetime(*test_config.DATE, test_config.NOON, 0) gen = ( start_at diff --git a/tests/forecasts/timify/test_aggregate_orders.py b/tests/forecasts/timify/test_aggregate_orders.py index 325db74..b515e45 100644 --- a/tests/forecasts/timify/test_aggregate_orders.py +++ b/tests/forecasts/timify/test_aggregate_orders.py @@ -73,9 +73,7 @@ class TestAggregateOrders: order = make_order( scheduled=False, restaurant=restaurant, - placed_at=datetime.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, hour, 11, - ), + placed_at=datetime.datetime(*test_config.DATE, hour, 11), ) db_session.add(order) @@ -104,9 +102,7 @@ class TestAggregateOrders: order = make_order( scheduled=False, restaurant=restaurant, - placed_at=datetime.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, hour, 11, - ), + placed_at=datetime.datetime(*test_config.DATE, hour, 11), ) db_session.add(order) @@ -137,9 +133,7 @@ class TestAggregateOrders: order = make_order( scheduled=False, restaurant=restaurant, - placed_at=datetime.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, hour, 11, - ), + placed_at=datetime.datetime(*test_config.DATE, hour, 11), ) db_session.add(order) @@ -169,21 +163,15 @@ class TestAggregateOrders: ad_hoc_order = make_order( scheduled=False, restaurant=restaurant, - placed_at=datetime.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 11, 11, - ), + placed_at=datetime.datetime(*test_config.DATE, 11, 11), ) db_session.add(ad_hoc_order) pre_order = make_order( scheduled=True, restaurant=restaurant, - placed_at=datetime.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 9, 0, - ), - scheduled_delivery_at=datetime.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, 12, 0, - ), + placed_at=datetime.datetime(*test_config.DATE, 9, 0), + scheduled_delivery_at=datetime.datetime(*test_config.DATE, 12, 0), ) db_session.add(pre_order) @@ -215,9 +203,7 @@ class TestAggregateOrders: order = make_order( scheduled=False, restaurant=restaurant, - placed_at=datetime.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, hour, 11, - ), + placed_at=datetime.datetime(*test_config.DATE, hour, 11), ) db_session.add(order) @@ -252,9 +238,7 @@ class TestAggregateOrders: order = make_order( scheduled=False, restaurant=restaurant, - placed_at=datetime.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, hour, 11, - ), + placed_at=datetime.datetime(*test_config.DATE, hour, 11), ) db_session.add(order) @@ -333,9 +317,7 @@ class TestAggregateOrders: order = make_order( scheduled=False, restaurant=restaurant1, - placed_at=datetime.datetime( - test_config.YEAR, test_config.MONTH, test_config.DAY, hour, 11, - ), + placed_at=datetime.datetime(*test_config.DATE, hour, 11), ) db_session.add(order)