"""Unit tests for YouTubeVideoSL.""" from unittest import mock from unittest.mock import MagicMock from unittest.mock import patch import pytest from feed_ingestion.flows.youtube_video.stage_loader import YouTubeVideoSL class TestStageLoader(object): """Unit tests for YouTubeVideoSL.""" @pytest.fixture def mock_sql_loader(self): """Return sql_loader mock.""" sql_loader_path = ( 'feed_ingestion.flows.spotify.snowflake_executor.sql_loader') with patch(sql_loader_path) as sql_loader: yield sql_loader @pytest.fixture def mock_stage_loader(self, mock_sql_loader): """Yield executor context.""" stage_loader = YouTubeVideoSL(MagicMock(), mock_sql_loader) stage_loader.resolve_sql_loader_and_execute = MagicMock() yield stage_loader def test_load_temp_staging_raw_table(self, mock_stage_loader): """Test load_temp_staging_raw_table.""" stage_name = 'test_stage' skip_corrupted_rows = 'True' temp_staging_raw = 'test_temp_staging_raw' date = '2018-01-01' source_files_dict = { 'files': [ {'file_name': 'test1', 'file_size': 42}, {'file_name': 'dmgi', 'file_size': 42}, {'file_name': 'test2', 'file_size': 73}]} mock_stage_loader.load_temp_staging_raw_table( temp_staging_raw_table=temp_staging_raw, source_files_dict=source_files_dict, date=date, stage_name=stage_name, skip_corrupted_rows=skip_corrupted_rows, licensor='theorchard') assert mock_stage_loader.resolve_sql_loader_and_execute.call_count == 3 for file in source_files_dict['files']: mock_stage_loader.resolve_sql_loader_and_execute.assert_any_call( 'load_temp_staging_raw', params=dict( db=mock.ANY, schema=mock.ANY, stage=stage_name, on_error='CONTINUE', temp_staging_raw_table=temp_staging_raw, file_name=file['file_name'], file_size=file['file_size'], download_date=date, licensor='theorchard', ingestion_time=mock.ANY))