"""API unit test fixtures.""" from datetime import date, datetime from unittest.mock import MagicMock import pytest from timed_release import api from timed_release.connectors import sql from timed_release.constants import header @pytest.fixture def app_context(): """Create an api test app fixture.""" with api.app.app_context(): yield @pytest.fixture def test_account_type(): """Return a subaccount_id for testing.""" return 'vendor' @pytest.fixture def valid_headers(test_account_type): """Return valid account headers.""" return { header.GRASS_ACCOUNT_TYPE: test_account_type, header.GRASS_ACCOUNT_ID: 1} @pytest.fixture def db_session_fixture(monkeypatch): """Return mocked db session fixture.""" session_object = MagicMock() session_object.add.return_value = True session_object.commit.return_value = True session_object.rollback.return_value = True monkeypatch.setattr(sql, 'db_session', MagicMock( return_value=session_object )) return session_object @pytest.fixture def stores_fixture(monkeypatch): """Return product schedule fixture after event is processed.""" return { 'total': 2, 'items': [ { 'id': 12, 'name': 'First DSP', 'supports_timed_release': False, 'status': 'active' }, { 'id': 13, 'name': 'Second DSP', 'supports_timed_release': True, 'status': 'active' }, { 'id': 14, 'name': 'Third DSP', 'supports_timed_release': False, 'status': 'active' }, { 'id': 15, 'name': 'Fourth DSP', 'supports_timed_release': True, 'status': 'active' } ] } @pytest.fixture def workstation_timed_release_fixture(): """Return valid workstation timed release fixture.""" return { 'product_id': 1, 'sales_start_datetime': '2025-04-03T10:00:00Z', 'event_process_on': '2025-04-03T09:30:00Z', 'event_created_on': None } @pytest.fixture def second_workstation_timed_release_fixture(): """Return valid workstation timed release fixture.""" return { 'product_id': 2, 'sales_start_datetime': '2035-06-09T10:00:00Z', 'event_process_on': '2035-06-09T09:30:00Z', 'event_created_on': None } @pytest.fixture def unsupported_store_schedule_before_event_processed_fixture(monkeypatch): """Return unsupported store schedule fixture before event is processed.""" return { 'product_id': 2, 'sales_start_datetime': '2035-06-09T10:00:00Z', 'schedule': { 'dms_id': 12, 'dms_name': 'First DSP', 'supports_timed_release': False, 'sales_start_date': '2035-06-11', 'sales_start_datetime': '2035-06-11T10:00:00Z' } } @pytest.fixture def supported_store_schedule_after_before_processed_fixture(monkeypatch): """Return supported store schedule fixture before event is processed.""" return { 'product_id': 2, 'sales_start_datetime': '2035-06-09T10:00:00Z', 'schedule': { 'dms_id': 13, 'dms_name': 'Second DSP', 'supports_timed_release': True, 'sales_start_date': '2035-06-09', 'sales_start_datetime': '2035-06-09T10:00:00Z' } } @pytest.fixture def unsupported_store_schedule_after_event_processed_fixture(monkeypatch): """Return unsupported store schedule fixture after event is processed.""" return { 'product_id': 1, 'sales_start_datetime': '2025-04-03T10:00:00Z', 'schedule': { 'dms_id': 14, 'dms_name': 'Third DSP', 'supports_timed_release': False, 'sales_start_date': '2025-04-03', 'sales_start_datetime': '2025-04-03T10:00:00Z' } } @pytest.fixture def supported_store_schedule_after_event_processed_fixture(monkeypatch): """Return supported store schedule fixture after event is processed.""" return { 'product_id': 1, 'sales_start_datetime': '2025-04-03T10:00:00Z', 'schedule': { 'dms_id': 15, 'dms_name': 'Fourth DSP', 'supports_timed_release': True, 'sales_start_date': '2025-04-03', 'sales_start_datetime': '2025-04-03T10:00:00Z' } } @pytest.fixture def supported_stores_timed_release_ws_fixture(monkeypatch): """Return supported_stores_timed_release_ws data.""" return { 'timed_releases': [ { 'sales_date_time': '2026-05-20T11:11:11Z', 'source': 'workstation', 'store_id': 187, 'timing': 'timed', 'user_timezone': 'america/new_york' }, { 'sales_date_time': '2026-05-20T11:11:11Z', 'source': 'workstation', 'store_id': 286, 'timing': 'timed', 'user_timezone': 'america/new_york' } ] } @pytest.fixture def supported_stores_tr_data_fixture(): """Existing + new Supported stores timed release data fixture.""" return [ { 'product_id': 13, 'store_id': 187, 'sales_date_time': datetime(2027, 5, 3, 10, 10, 10), 'timing': 'timed', 'source': 'workstation' }, { 'product_id': 13, 'store_id': 286, 'sales_date_time': datetime(2027, 5, 3, 10, 10, 10), 'timing': 'timed', 'source': 'workstation' }, { 'product_id': 13, 'store_id': 152, 'sales_date_time': datetime(2027, 5, 3, 10, 10, 10), 'timing': 'timed', 'source': 'workstation' } ] @pytest.fixture def new_supported_stores_tr_data_fixture(): """Return new supported stores timed release data fixture.""" return [ { 'product_id': 14, 'store_id': 40, 'sales_date_time': datetime(2026, 4, 15, 15, 15, 15), 'timing': 'timed', 'source': 'workstation' }, { 'product_id': 14, 'store_id': 41, 'sales_date_time': datetime(2026, 4, 15, 15, 15, 15), 'timing': 'timed', 'source': 'workstation' } ] @pytest.fixture def unsupported_stores_schedule_data_fixture(): """Return unsupported stores schedule data fixture.""" return { 'delivery_store_ids': [1, 2, 5, 6, 9], 'schedule_datetime': datetime(2028, 8, 8, 10, 0, 0), 'process_at_datetime': datetime(2028, 8, 8, 9, 30, 0), 'process_at_offset': '00:30', 'update': { 'sale_start_date': date(2028, 8, 8) } } @pytest.fixture def timed_release_data_fixture(): """Return timed release data fixture.""" return { 'timed': { 'sales_date_time': '2026-05-20T11:11:11Z' }, 'staggered': None } @pytest.fixture def timed_release_ws_fixture(): """Return timed release ws fixture.""" return { 'product_id': 12, 'sales_date_time': '2026-05-20T11:11:11Z' }