"""Unit tests for Snowflake executor.""" from unittest.mock import call from unittest.mock import MagicMock import pytest from dim_refresh_etl.flows.dynamo_sync.snowflake_executor import \ SnowflakeSyncExecutor from dim_refresh_etl.flows.dynamo_sync.snowflake_executor import sql_loader @pytest.yield_fixture def mock_executor(mocker, sf_config_mock): """Yield executor context.""" executor = SnowflakeSyncExecutor(sf_config_mock) with mocker.patch.object(executor, 'execute', wraps=executor.execute) as \ executor.ex_mock: yield executor @pytest.fixture def load_query_spy(mocker): """Set spy on sql_loader.""" return mocker.spy(sql_loader, 'load_query') def test_unload_to_s3_load_query( mock_executor, load_query_spy, sf_config_mock): """Test correct SQL templates load.""" model_type = 'analytics_metadata' mock_executor.unload_to_s3( model_type, MagicMock(), MagicMock(), MagicMock(), MagicMock()) load_query_spy.assert_has_calls([call(model_type), call('unload_to_s3')]) def test_unload_to_s3_correct_params( mocker, mock_executor, load_query_spy, sf_config_mock, aws_config): """Check SQL execution params.""" model_type = 'analytics_metadata' test_s3_path = 'test_s3_path' sync_from_date = '2018-01-01 10:00:00' full_refresh = True expected_params = { 's3_path': test_s3_path, 'full_refresh': full_refresh, 'sync_from_date': sync_from_date, 'aws_key_id': aws_config['access_key'], 'aws_secret_key': aws_config['access_secret']} mock_executor.unload_to_s3( model_type, test_s3_path, sync_from_date, full_refresh, aws_config) mock_executor.execute.assert_called_once_with( mocker.ANY, params=expected_params)