"""spotify_artificial_streams flow copy_blob_to_archive task tests.""" __all__ = [ 'TestCopyBlobToArchiveTask', ] from unittest.mock import patch from botocore.exceptions import ClientError from feed_ingestion.flows.spotify_artificial_streams import tasks from tests.flows.spotify_artificial_streams import constants from tests.flows.spotify_artificial_streams.tasks import base_test_case class TestCopyBlobToArchiveTask( base_test_case.BaseSpotifyArtificialStreamsTestTask, ): """Test cases for spotify_artificial_streams copy_blob_to_archive task.""" @patch(constants.garcon_methods['get_overall_status']) @patch(constants.garcon_methods['set_overall_status']) @patch(constants.garcon_related_methods['is_completed_task']) @patch(constants.garcon_related_methods['mark_completed_task']) @patch(constants.s3_related_methods['copy_files']) @patch(constants.s3_related_methods['source_files']) def test_success_copy_reload_false( self, source_files, copy_files, mark_completed_task, is_completed_task, set_overall_status, get_overall_status, ): """Test task when the blob copy is success.""" is_completed_task.return_value = False # inputs copy_blob_to_archive_kwargs = { 'activity': self.activity, 'date': self.string_date, 'archive_blob_prefix': 'any_blob_prefix', 'drop_bucket_name': 'drop_bucket_name', 'drop_blob_path': 'drop_blob_path', 'drop_blob_wildcard': 'drop_blob_wildcard', 'reload': 'False', } response = tasks.copy_blob_to_archive(**copy_blob_to_archive_kwargs) expected_response = None self.assertEqual(response, expected_response) @patch(constants.garcon_methods['get_overall_status']) @patch(constants.garcon_methods['set_overall_status']) @patch(constants.garcon_related_methods['is_completed_task']) @patch(constants.garcon_related_methods['mark_completed_task']) @patch(constants.s3_related_methods['copy_files']) @patch(constants.s3_related_methods['source_files']) def test_failed_copy_reload_false( self, source_files, copy_files, mark_completed_task, is_completed_task, set_overall_status, get_overall_status, ): """Test task when the blob copy is not success.""" is_completed_task.return_value = False copy_files.side_effect = ClientError( error_response={ 'Error': {}, }, operation_name='test', ) # inputs copy_blob_to_archive_kwargs = { 'activity': self.activity, 'date': self.string_date, 'archive_blob_prefix': 'any_blob_prefix', 'drop_bucket_name': 'drop_bucket_name', 'drop_blob_path': 'drop_blob_path', 'drop_blob_wildcard': 'drop_blob_wildcard', 'reload': 'False', } response = tasks.copy_blob_to_archive(**copy_blob_to_archive_kwargs) expected_response = tasks._STOP_RESPONSE self.assertEqual(response, expected_response)