"""Unit tests for snowflake_snapshot_flat_contract_term_schedules_nr task.""" from unittest.mock import patch from lib import config from tasks.accounting_run_calculate_nr.snowflake_snapshot_contract_term_schedules \ import snapshot_contract_term_schedules_nr_task import_path = \ 'tasks.accounting_run_calculate_nr.snowflake_snapshot_contract_term_schedules' @patch(f'{import_path}.RoyaltySnowflakeHook') @patch(f'{import_path}.helpers') @patch(f'{import_path}.snapshot_contract_term_schedule_nr_template') def test_snowflake_snapshot_flat_contract_terms_nr_task( mock_template, mock_helpers, mock_hook, mock_accounting_run_calculate_nr_dag_run ): """Test that task renders snowflake sql to snapshot contract_terms and schedules.""" accounting_run_id = 123 mock_helpers.get_event_from_params.return_value.target_id = accounting_run_id mock_template.return_value.render.return_value = \ 'INSERT INTO CONTRACT_SNAPSHOT_TERM_SCHEDULES_NR royalty_accounting REPLICA' mock_hook.return_value.run.return_value = True snapshot_contract_term_schedules_nr_task(mock_accounting_run_calculate_nr_dag_run) mock_helpers.get_event_from_params.assert_called_once_with( mock_accounting_run_calculate_nr_dag_run ) 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, env='qa', schema=config.OWS_ENV, ) mock_hook.return_value.run.assert_called_once()