"""Tests for the Flow.""" from unittest.mock import ANY from unittest.mock import Mock from unittest.mock import call from analytics_aggregation.flows.spotify_sos import flow as spotify_flow def test_decider(monkeypatch): """Test Flow decider if 'bootstrap.reload' is True.""" activity_creator = Mock() activity_creator.return_value.return_value = 'activity' monkeypatch.setattr('garcon.activity.create', activity_creator) scheduler = Mock(name='sheduler') scheduler.return_value.result = {'bootstrap.reload': True} flow = spotify_flow.Flow() flow.decider(scheduler) scheduler.assert_has_calls([ call('bootstrap', 'activity'), call('check_sos_reports_ingested', 'activity', requires=[ANY]), call('populate_staging_sos', 'activity', requires=[ANY]), call('set_status_to_ingested', 'activity', requires=[ANY])]) def test_for_decider_stop_after_bootstrap(): """Test for Flow decider.""" activity = Mock() activity.result = {'bootstrap.stop': True} scheduler = Mock(return_value=activity) f = spotify_flow.Flow() f.create = Mock(return_value='activity') f.decider(scheduler) scheduler.assert_has_calls([call('bootstrap', 'activity')]) def test_for_decider_stop_after_check_spotify_ingested(): """Test for Flow decider.""" activity = Mock() activity.result = {'check_spotify_ingested.stop': True} scheduler = Mock(return_value=activity) f = spotify_flow.Flow() f.create = Mock(return_value='activity') f.decider(scheduler) scheduler.assert_has_calls([ call('bootstrap', 'activity'), call('check_sos_reports_ingested', 'activity', requires=[ANY])])