From a589dc08b50b360b2c4b27280663b9ac6b257273 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Barth Date: Fri, 2 Oct 2015 09:41:29 +0200 Subject: [PATCH] Make workflow_id a required property of WorkflowExecution Given the response of DescribeWorkflowExecution endpoint, the WorkflowExecution has to know about its own workflowId. --- moto/swf/models.py | 19 +++++++++++-------- tests/test_swf/test_models.py | 8 ++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/moto/swf/models.py b/moto/swf/models.py index 6fe724038..dc29dc664 100644 --- a/moto/swf/models.py +++ b/moto/swf/models.py @@ -78,10 +78,11 @@ class Domain(object): _all.append(_type) return _all - def add_workflow_execution(self, workflow_execution_id, workflow_execution): - if self.workflow_executions.get(workflow_execution_id): + def add_workflow_execution(self, workflow_execution): + _id = workflow_execution.workflow_id + if self.workflow_executions.get(_id): raise SWFWorkflowExecutionAlreadyStartedFault() - self.workflow_executions[workflow_execution_id] = workflow_execution + self.workflow_executions[_id] = workflow_execution class GenericType(object): @@ -172,8 +173,9 @@ class WorkflowType(GenericType): class WorkflowExecution(object): - def __init__(self, workflow_type, **kwargs): + def __init__(self, workflow_type, workflow_id, **kwargs): self.workflow_type = workflow_type + self.workflow_id = workflow_id self.run_id = uuid.uuid4().hex for key, value in kwargs.iteritems(): self.__setattr__(key, value) @@ -295,11 +297,11 @@ class SWFBackend(BaseBackend): # TODO: find what triggers a "DefaultUndefinedFault" and implement it # (didn't found in boto source code, nor in the docs, nor on a Google search) # (will try to reach support) - def start_workflow_execution(self, domain_name, workflow_execution_id, + def start_workflow_execution(self, domain_name, workflow_id, workflow_name, workflow_version, tag_list=None, **kwargs): self._check_string(domain_name) - self._check_string(workflow_execution_id) + self._check_string(workflow_id) self._check_string(workflow_name) self._check_string(workflow_version) self._check_none_or_list_of_strings(tag_list) @@ -310,8 +312,9 @@ class SWFBackend(BaseBackend): wf_type = domain.get_type("workflow", workflow_name, workflow_version) if wf_type.status == "DEPRECATED": raise SWFTypeDeprecatedFault(wf_type) - wfe = WorkflowExecution(wf_type, tag_list=tag_list, **kwargs) - domain.add_workflow_execution(workflow_execution_id, wfe) + wfe = WorkflowExecution(wf_type, workflow_id, + tag_list=tag_list, **kwargs) + domain.add_workflow_execution(wfe) return wfe diff --git a/tests/test_swf/test_models.py b/tests/test_swf/test_models.py index 7f636673c..33006cbf7 100644 --- a/tests/test_swf/test_models.py +++ b/tests/test_swf/test_models.py @@ -77,15 +77,15 @@ def test_type_string_representation(): # WorkflowExecution def test_workflow_execution_creation(): - wfe = WorkflowExecution("workflow_type_whatever", child_policy="TERMINATE") + wfe = WorkflowExecution("workflow_type_whatever", "ab1234", child_policy="TERMINATE") wfe.workflow_type.should.equal("workflow_type_whatever") wfe.child_policy.should.equal("TERMINATE") def test_workflow_execution_string_representation(): - wfe = WorkflowExecution("workflow_type_whatever", child_policy="TERMINATE") + wfe = WorkflowExecution("workflow_type_whatever", "ab1234", child_policy="TERMINATE") str(wfe).should.match(r"^WorkflowExecution\(run_id: .*\)") def test_workflow_execution_generates_a_random_run_id(): - wfe1 = WorkflowExecution("workflow_type_whatever") - wfe2 = WorkflowExecution("workflow_type_whatever") + wfe1 = WorkflowExecution("workflow_type_whatever", "ab1234") + wfe2 = WorkflowExecution("workflow_type_whatever", "ab1235") wfe1.run_id.should_not.equal(wfe2.run_id)