from unittest.mock import MagicMock from unittest.mock import patch from ows_accounting import features from ows_accounting.models import transaction_types from ows_accounting.models.sql import transactiontype @patch('ows_accounting.models.transaction_types.snowflake') def test_get_transaction_types_with_sales_label_snowflake( mock_snowflake, monkeypatch): """Test get_transaction_types_with_sales for label.""" monkeypatch.setattr( features, 'is_transaction_types_with_sales_snowflake_migration_enabled', MagicMock(return_value=True)) mock_session = MagicMock() mock_context = MagicMock() mock_result = MagicMock() mock_session.execute.return_value = mock_result mock_snowflake.db_session.return_value = mock_context mock_context.__enter__.return_value = mock_session transaction_types.get_transaction_types_with_sales( 18805, 'vendor', 205, 205) sql = transactiontype.SQL_GET_TRANSACTIONTYPE transactiontype.SNOWFLAKE_TRANSACTIONTYPE_PARAMS.update( account_id_column='labelid') sql = sql.format(**transactiontype.SNOWFLAKE_TRANSACTIONTYPE_PARAMS) mock_session.execute.assert_any_call( sql, dict(account_id=18805, min_period=205, max_period=205)) @patch('ows_accounting.models.transaction_types.snowflake') def test_get_transaction_types_with_sales_subaccount_snowflake( mock_snowflake, monkeypatch): """Test get_transaction_types_with_sales for subaccount.""" monkeypatch.setattr( features, 'is_transaction_types_with_sales_snowflake_migration_enabled', MagicMock(return_value=True)) mock_session = MagicMock() mock_context = MagicMock() mock_result = MagicMock() mock_session.execute.return_value = mock_result mock_snowflake.db_session.return_value = mock_context mock_context.__enter__.return_value = mock_session transaction_types.get_transaction_types_with_sales( 13562, 'subaccount', 196, 198) sql = transactiontype.SQL_GET_TRANSACTIONTYPE transactiontype.SNOWFLAKE_TRANSACTIONTYPE_PARAMS.update( account_id_column='subaccountid') sql = sql.format(**transactiontype.SNOWFLAKE_TRANSACTIONTYPE_PARAMS) mock_session.execute.assert_any_call( sql, dict(account_id=13562, min_period=196, max_period=198))