"""Unit tests for snowflake_calculate_mechanical_deductions task.""" from unittest.mock import patch from lib import config from tasks.accounting_run_calculate.snowflake_calculate_mechanical_deductions \ import calculate_mech_deductions_task import_path = 'tasks.accounting_run_calculate.snowflake_calculate_mechanical_deductions' @patch(f'{import_path}.RoyaltySnowflakeHook') @patch(f'{import_path}.helpers') @patch(f'{import_path}.calculate_mech_deductions_template') def test_calculate_mech_deductions( mock_template, mock_helpers, mock_snowflake_hook, mock_accounting_run_calculate_dag_run ): """Test task uses snowflake template to calculate and insert mech deductions.""" accounting_run_id = 123 mock_helpers.get_event_from_params.return_value.target_id = accounting_run_id mock_snowflake_hook.return_value.run.return_value = True mock_template.return_value.render.return_value = \ 'CALCULATE MECH DEDUCTIONS AND INSERT INTO ACCOUNTING_RUN_RESULTS_DISTRO_MECH_STAGING' # noqa E501 calculate_mech_deductions_task(mock_accounting_run_calculate_dag_run) mock_helpers.get_event_from_params.assert_called_once_with( mock_accounting_run_calculate_dag_run ) mock_snowflake_hook.assert_called_once_with( snowflake_conn_id=config.SNOWFLAKE_CONN_NAME ) mock_template.return_value.render.called_once_with( accounting_run_id=accounting_run_id, schema=config.OWS_ENV )