"""Unit tests for tasks of Amazon Unlimited Marketshare Workflow.""" from unittest.mock import MagicMock from unittest.mock import patch import pytest from feed_ingestion.flows.amazon_unlimited_marketshare import config from feed_ingestion.flows.amazon_unlimited_marketshare import tasks @pytest.fixture def context(): """Context for Amazon Unlimited Marketshare tasks.""" return { 'activity': MagicMock(), 'date': '2017-11-01', 'reload': False} @pytest.fixture def expected_bootstrap_response(): """Response for bootstrap task.""" return { 'feed_name': config.feed_name, 'secrets_path': config.secrets_path, 'date': '2017-11-01', 's3_archive_path': 's3://dev-cucumbers/AmazonUnlimitedMarketShare/archives/2017-11/', 'file_pattern': '_Monthly_AMU_Summary_201711', 'staging_raw_table': 'staging_raw_amazon_unlimited_market_share', 'temp_staging_raw_table': 'temp_staging_raw_amazon_unlimited_market_share_20171101', } def test_bootstrap(context, expected_bootstrap_response): """Test bootstrap task.""" result = tasks.bootstrap(**context) assert result == expected_bootstrap_response @pytest.fixture def mock_executor_context(): """Yield executor context.""" sf_executor_class_path = ( 'feed_ingestion.flows.amazon_unlimited_marketshare.tasks.' 'AmazonUnlimitedMarketshareSF') with patch(sf_executor_class_path) as sf_executor: mock_executor_context = sf_executor.return_value.__enter__.return_value yield mock_executor_context def test_drop_temp_table(mock_executor_context): """Test drop_temp_table task.""" tasks.drop_temp_table(MagicMock(), 'test_table') mock_executor_context.drop_table.assert_called_with('test_table')