"""Test cases for spotify_artificial_streams flow.""" __all__ = [ 'TestSpotifyArtificialStreamsFlow', ] from unittest import TestCase from unittest.mock import MagicMock, patch from feed_ingestion.flows.spotify_artificial_streams import flow from feed_ingestion.flows.spotify_artificial_streams.tasks import ( _STOP_RESPONSE, # noqa ) class TestSpotifyArtificialStreamsFlow(TestCase): """Unit tests for spotify_artificial_streams flow.""" _PROPERTIES_PREFIX = ( 'feed_ingestion.flows.spotify_artificial_streams.flow.Flow' ) @staticmethod def _schedule( activity_name, # noqa activity_function, **kwargs, # noqa ): m = MagicMock() m.result = { f'{activity_name}.{k}': v for k, v in (activity_function() or {}).items() } return m @patch(f'{_PROPERTIES_PREFIX}.check_feed_status_activity') @patch(f'{_PROPERTIES_PREFIX}.bootstrap_activity') @patch(f'{_PROPERTIES_PREFIX}.copy_blob_to_archive_activity') @patch(f'{_PROPERTIES_PREFIX}.create_temp_staging_raw_table_activity') @patch(f'{_PROPERTIES_PREFIX}.load_temp_staging_raw_table_activity') @patch(f'{_PROPERTIES_PREFIX}.load_staging_raw_table_activity') @patch(f'{_PROPERTIES_PREFIX}.set_overall_status') def test_stop_decider_on_data_ingested( self, set_overall_status, load_staging_raw_table_activity, load_temp_staging_raw_table_activity, create_temp_staging_raw_table_activity, copy_blob_to_archive_activity, bootstrap_activity, check_feed_status_activity, ): """Test the case when data has already been ingested.""" check_feed_status_activity.return_value = _STOP_RESPONSE sas_flow = flow.Flow() sas_flow.decider(self._schedule) check_feed_status_activity.assert_called_once() bootstrap_activity.assert_not_called() copy_blob_to_archive_activity.assert_not_called() create_temp_staging_raw_table_activity.assert_not_called() load_temp_staging_raw_table_activity.assert_not_called() load_staging_raw_table_activity.assert_not_called() set_overall_status.assert_not_called() @patch(f'{_PROPERTIES_PREFIX}.check_feed_status_activity') @patch(f'{_PROPERTIES_PREFIX}.bootstrap_activity') @patch(f'{_PROPERTIES_PREFIX}.copy_blob_to_archive_activity') @patch(f'{_PROPERTIES_PREFIX}.create_temp_staging_raw_table_activity') @patch(f'{_PROPERTIES_PREFIX}.load_temp_staging_raw_table_activity') @patch(f'{_PROPERTIES_PREFIX}.load_staging_raw_table_activity') @patch(f'{_PROPERTIES_PREFIX}.set_overall_status') def test_stop_on_copy_blob_to_archive( self, set_overall_status, load_staging_raw_table_activity, load_temp_staging_raw_table_activity, create_temp_staging_raw_table_activity, copy_blob_to_archive_activity, bootstrap_activity, check_feed_status_activity, ): """Test the case when any error during blobs movement.""" copy_blob_to_archive_activity.return_value = _STOP_RESPONSE sas_flow = flow.Flow() sas_flow.decider(self._schedule) check_feed_status_activity.assert_called_once() bootstrap_activity.assert_called_once() copy_blob_to_archive_activity.assert_called_once() create_temp_staging_raw_table_activity.assert_not_called() load_temp_staging_raw_table_activity.assert_not_called() load_staging_raw_table_activity.assert_not_called() set_overall_status.assert_not_called() @patch(f'{_PROPERTIES_PREFIX}.check_feed_status_activity') @patch(f'{_PROPERTIES_PREFIX}.bootstrap_activity') @patch(f'{_PROPERTIES_PREFIX}.copy_blob_to_archive_activity') @patch(f'{_PROPERTIES_PREFIX}.create_temp_staging_raw_table_activity') @patch(f'{_PROPERTIES_PREFIX}.load_temp_staging_raw_table_activity') @patch(f'{_PROPERTIES_PREFIX}.load_staging_raw_table_activity') @patch(f'{_PROPERTIES_PREFIX}.set_overall_status') def test_staging_raw_table_load_flow( self, set_overall_status, load_staging_raw_table_activity, load_temp_staging_raw_table_activity, create_temp_staging_raw_table_activity, copy_blob_to_archive_activity, bootstrap_activity, check_feed_status_activity, ): """Test the case when all activities must be passed.""" sas_flow = flow.Flow() sas_flow.decider(self._schedule) check_feed_status_activity.assert_called_once() bootstrap_activity.assert_called_once() copy_blob_to_archive_activity.assert_called_once() create_temp_staging_raw_table_activity.assert_called_once() load_temp_staging_raw_table_activity.assert_called_once() load_staging_raw_table_activity.assert_called_once() set_overall_status.assert_called_once()