"""Tests for sales data flow class.""" from unittest import TestCase from unittest.mock import Mock from unittest.mock import patch from flows.sales_data.flow import Flow class FlowTest(TestCase): """Test flow class.""" def setUp(self): """Setup function.""" self.patched_tasks = patch('flows.sales_data.flow.tasks') self.tasks = self.patched_tasks.start() self.addCleanup(self.patched_tasks.stop) self.all_tasks = { 'bootstrap', 'unload_sales_data', 'load_raw_table', 'insert_daily_revenue', 'send_notification', 'set_status'} def test_decider(self): """Test decider function with correct accounting period id.""" flow = Flow('test', 'test_sales_data', '1.0') schedule = Mock() schedule.return_value = Mock(result={'non': 'stop'}) flow.decider(schedule) for call in schedule.call_args_list: self.all_tasks.remove(call[0][0]) assert not self.all_tasks def test_decider_stop(self): """Test decider function with bad accounting period id.""" flow = Flow('test', 'test_sales_data', '1.0') schedule = Mock() schedule.return_value = Mock(result={'bootstrap.stop': True}) flow.decider(schedule) wont_run = { 'unload_sales_data', 'load_raw_table', 'insert_daily_revenue', 'send_notification', 'set_status'} for call in schedule.call_args_list: self.all_tasks.remove(call[0][0]) assert self.all_tasks == wont_run