"""Unit tests for snowflake_match_contract_terms task.""" from unittest.mock import patch from lib import config from tasks.accounting_run_calculate.snowflake_match_contract_terms \ import match_contract_terms_to_sales_task import_path = 'tasks.accounting_run_calculate.snowflake_match_contract_terms' @patch(f'{import_path}.RoyaltySnowflakeHook') @patch(f'{import_path}.helpers') @patch(f'{import_path}.insert_contract_transaction_staging_distro_template') def test_match_contract_terms_to_sales_task( mock_template, mock_helpers, mock_hook, mock_accounting_run_calculate_dag_run ): """Test task uses snowflake to match contract terms to sales.""" accounting_run_id = 123 accounting_period = { 'accounting_period_id': 1, 'accounting_period_name': 'Test Period' } mock_helpers.get_event_from_params.return_value.target_id = accounting_run_id mock_helpers.get_event_records.return_value = (accounting_period, {}) mock_helpers.get_sales_file_ids.return_value = [1, 2, 3] mock_template.return_value.render.return_value = \ 'MATCH CONTRACT TERMS TO TXNS AND INSERT INTO CONTRACT_TRANSACTION_STAGING' mock_hook.return_value.run.return_value = True match_contract_terms_to_sales_task(mock_accounting_run_calculate_dag_run) mock_helpers.get_event_from_params.assert_called_once_with( mock_accounting_run_calculate_dag_run ) mock_helpers.get_event_records.assert_called_once_with(accounting_run_id) mock_helpers.get_sales_file_ids.assert_called_once_with( accounting_period.get('accounting_period_id') ) mock_hook.assert_called_once_with(snowflake_conn_id=config.SNOWFLAKE_CONN_NAME) mock_template.return_value.render.assert_called_once_with( accounting_run_id=accounting_run_id, sales_file_ids=[1, 2, 3], schema=config.OWS_ENV ) mock_hook.return_value.run.assert_called_once()