"""Common fixtures.""" import uuid import pytest import application from deliveryhistory import api from deliveryhistory.constants import header from tests.testutils import db @pytest.fixture def header_fixture(): """Return header dict fixture. Returns: dict: header dict """ correlation_id = str(uuid.uuid1()) fixture_header = { header.CORRELATION_ID: correlation_id, header.CONTENT_TYPE: header.APPLICATION_JSON } return fixture_header @pytest.fixture def context(): """Return flask app context, including a mock logger. Returns: AppContext: flask app context, including a mock logger. """ class MockLog: def error(self): pass def info(self): pass def warning(self): pass context = application.app.app_context() context.g.log = MockLog return context @pytest.fixture def fixture_client(): """Create an api test client fixture.""" return api.app.test_client() @pytest.fixture def body_fixture(): """Create a valid delivery history record response.""" return { 'items': [{ 'isrc': 'ISRC12345678', 'upc': '100075857722', 'tuid': 123123, 'partner_id': 412, 'delivery_date': '2016-08-10 19:52:22.696936' }] } @pytest.fixture def stores_fixture(): """Create a valid stores count response.""" return [ {'product_id': 12345, 'display_upc': '5555', 'stores_count': 40} ] @pytest.fixture def delivery_history_fixture(): """Create a valid delivery history response.""" return [ {'date_delivered': '2019-09-13', 'store_id': 3} ] @pytest.fixture def db_fixture(): """Create and insert a standard common db fixture.""" db.clear_ows_tables() @pytest.fixture def ar_db_fixture(): """Create and insert a standard common db fixture.""" db.seed_delivery_tables() @pytest.fixture def app_context(): """Create an api test app fixture.""" with api.app.app_context(): yield