from unittest.mock import MagicMock from ows_accounting import config from ows_accounting.constants import utils as utils_constants from ows_accounting.utils import swf def test_execute_workflow(monkeypatch): """Test execute_workflow. """ mock_client = MagicMock() monkeypatch.setattr( swf, '_get_client', MagicMock(return_value=mock_client)) swf.execute_workflow( 'workflow_id', 'correlation_id', period_ids='202,203,204', user_type='subaccount', payment_interval='month') mock_client.start_workflow_execution.assert_any_call( domain=config.SWF_DOMAIN, workflowId='workflow_id', workflowType={ 'name': 'custom_export_processing-accounting', 'version': '1.0' }, taskList={ 'name': 'custom_export_processing-accounting' }, input=( '{"Correlation-Id": "correlation_id.1", ' '"payment_interval": "month", "period_ids": "202,203,204", ' '"user_type": "subaccount"}'), executionStartToCloseTimeout=str( utils_constants.SWF_EXECUTION_START_TO_CLOSE_TIMEOUT), taskStartToCloseTimeout=str( utils_constants.SWF_TASK_START_TO_CLOSE_TIMEOUT), childPolicy=utils_constants.SWF_CHILD_POLICY) def test_generate_workflow_id(): """Test generate_workflow_id. """ prefix = 'custom_export' params = { 'user_id': '1234', 'user_type': 'label', 'period_ids': '217', 'transaction_types': 'all', 'locale': 'en_US', 'file_format': 'xls', 'client_email': 'test@example.com', 'report_version': 1, } expected = ( 'custom_export-1234-label-217-all-en_US-xls-1-test@example.com') actual = swf.generate_workflow_id(prefix, **params) assert actual == expected