"""spotify_artificial_streams flow check_feed_status task tests.""" __all__ = [ 'TestCheckFeedStatusTask', ] from datetime import date from unittest.mock import patch from garcon_contrib.dynamo_feed_status.garcon_feed_status import ( STATUS_INGESTED, ) from feed_ingestion.flows.spotify_artificial_streams import config from feed_ingestion.flows.spotify_artificial_streams import tasks from tests.flows.spotify_artificial_streams.constants import garcon_methods from tests.flows.spotify_artificial_streams.tasks import base_test_case class TestCheckFeedStatusTask( base_test_case.BaseSpotifyArtificialStreamsTestTask, ): """Test spotify_artificial_streams flow check_feed_status task tests.""" def setUp(self): """Initialize the test cases common properties.""" super().setUp() current_date = date.today() self.string_date = date( current_date.year, current_date.month, config.workflow_month_day, ).isoformat() @patch(garcon_methods['delete_status']) def test_check_feed_status_reload_true(self, delete_status): """Test the task under data reload condition.""" # inputs check_feed_status_kwargs = { 'activity': self.activity, 'date': self.string_date, 'reload': 'True', } response = tasks.check_feed_status(**check_feed_status_kwargs) expected_response = {'feed_name': config.feed_name} self.assertEqual(response, expected_response) @patch(garcon_methods['get_overall_status']) def test_check_feed_status_reload_false_already_loaded( self, get_overall_status, ): """Test the task with no reload condition, but already loaded data.""" check_feed_status_kwargs = { 'activity': self.activity, 'date': self.string_date, 'reload': 'False', } get_overall_status.return_value = STATUS_INGESTED response = tasks.check_feed_status(**check_feed_status_kwargs) expected_response = tasks._STOP_RESPONSE self.assertEqual(response, expected_response) @patch(garcon_methods['get_overall_status']) def test_check_feed_status_reload_false_first_load( self, get_overall_status, ): """Test the task with no need in reload and no data loaded.""" check_feed_status_kwargs = { 'activity': self.activity, 'date': self.string_date, 'reload': 'False', } response = tasks.check_feed_status(**check_feed_status_kwargs) expected_response = {'feed_name': config.feed_name} self.assertEqual(response, expected_response) def test_check_feed_status_raise_error_on_non_spec_day(self): """Test error raising on non spec day.""" current_date = date.today() context_date = date( current_date.year, current_date.month, 1, ).isoformat() check_feed_status_kwargs = { 'activity': self.activity, 'date': context_date, 'reload': 'False', } with self.assertRaises(ValueError): tasks.check_feed_status(**check_feed_status_kwargs)