"""Fixtures.""" from unittest.mock import MagicMock from unittest.mock import patch import fakeredis import pytest from accounting.adapters.cache import CacheAdapter from accounting.adapters.db import DatabaseAdapter from accounting.adapters.warehouse import SnowflakeAdapter @pytest.fixture(scope='session') @patch('accounting.adapters.cache.CacheAdapter._get_connection') def mock_cache_adapter(mock_conn): """Replace redis with fakeredis and return a new CacheAdapter.""" mock_conn.return_value = fakeredis.FakeRedis() return CacheAdapter() @pytest.fixture(scope='session') @patch('accounting.adapters.db.DatabaseAdapter._get_connection') def mock_db_adapter(mock_conn): """Replace mysql with a mock.""" mock_conn.return_value = MagicMock() return DatabaseAdapter() @pytest.fixture(scope='session') @patch('accounting.adapters.warehouse.SnowflakeAdapter._get_connection') def mock_warehouse_adapter(mock_conn): """Replace snowflake connection with a mock.""" mock_conn.return_value = MagicMock() adapter = SnowflakeAdapter() adapter.execute('select 1') return adapter @pytest.fixture() def appended_field(): """Return a valid appended field array.""" return { 'upc': 1, 'vendor_id': 1, 'release_status': 'in_content', 'owner_id': 2, } @pytest.fixture() def transaction_filepath(): """Return the path to a test transaction file.""" return './tests/files/txn_100_aacfc' @pytest.fixture() def txn_required_fields(): """Return a complete transaction represented as a dict.""" return { 'statement_detail_id': 1, 'period_id': 1, 'customer_id': 1, 'statement_id': 1, 'vendor_id': 1, 'owner_id': 1, 'date': '01/01/01', 'upc': 1, 'qty': 1, 'total': 1, 'trans_type': 'AP', 'unit_price': 0.5, 'original_price': 0.5, 'original_currency_id': 1, 'activity_rate': 1.2, }