"""Test cases for spotify_artificial_streams flow Snowflake executor.""" __all__ = [ 'TestSpotifyArtificialStreamsSnowflakeExecutor', ] from unittest import TestCase from unittest.mock import patch import moto from feed_ingestion.flows.spotify_artificial_streams \ import snowflake_executor as se from tests.flows.spotify_artificial_streams import constants class TestSpotifyArtificialStreamsSnowflakeExecutor(TestCase): """Test cases for Snowflake executor.""" @patch(constants.snowflake_executor_methods['get_connection']) @patch(constants.snowflake_executor_methods['execute_query']) def test_create_temp_staging_raw_table( self, execute_query, get_connection, ): """Test if the method create_temp_staging_raw_table is working.""" executor = se.SpotifyArtificialStreamsSnowflakeSQLExecutor( sf_config={ 'db': 'ANY_DB', 'schema': 'ANY_SCHEMA', }, ) executor.create_temp_staging_raw_table( temp_staging_raw_table='ANY_TABLE_NAME', query_file_name='some_name', ) @patch(constants.snowflake_executor_methods['get_connection']) @patch(constants.snowflake_executor_methods['fetchall_query']) @moto.mock_aws def test_load_temp_staging_raw_table( self, fetchall_query, get_connection, ): """Test if the method load_temp_staging_raw_table is working.""" fetchall_query.return_value = [ ( 'file', 'status', 'rows_parsed', 'rows_loaded', 'error_limit', 'errors_seen', 'first_error', 'first_error_line', 'first_error_character', 'first_error_column_name', ), ] executor = se.SpotifyArtificialStreamsSnowflakeSQLExecutor( sf_config={ 'db': 'ANY_DB', 'schema': 'ANY_SCHEMA', }, ) executor.load_temp_staging_raw_table( temp_staging_raw_table='ANY_TABLE_NAME', aws={ 'access_key': '***', 'access_secret': '***', }, key_dir='ANY_SOURCE_BLOB_PREFIX', query_file_name='some_name', file_pattern='any_blob_name', snowflake_error_limit='20', ) @patch(constants.snowflake_executor_methods['get_connection']) @patch(constants.snowflake_executor_methods['execute_query']) def test_load_staging_raw_table( self, execute_query, get_connection, ): """Test if the method load_staging_raw_table is working.""" executor = se.SpotifyArtificialStreamsSnowflakeSQLExecutor( sf_config={ 'db': 'ANY_DB', 'schema': 'ANY_SCHEMA', }, ) executor.load_staging_raw_table( temp_staging_raw_table='ANY_TEMP_STAGING_RAW_TABLE_NAME', staging_raw_table='ANY_STAGING_RAW_TABLE_NAME', date='2023-08-11', query_file_name='some_name', blob_path='any_blob_path', ) @patch(constants.snowflake_executor_methods['get_connection']) @patch(constants.snowflake_executor_methods['execute_query']) def test_clean_staging_raw_on_date( self, execute_query, get_connection, ): """Test if the method clean_staging_raw_on_date is working.""" executor = se.SpotifyArtificialStreamsSnowflakeSQLExecutor( sf_config={ 'db': 'ANY_DB', 'schema': 'ANY_SCHEMA', }, ) executor.clean_staging_raw_on_date( staging_raw_table='ANY_STAGING_RAW_TABLE_NAME', date='2023-08-11', query_file_name='some_name', )