def run_fake_child_workflow_task(domain, task_list, workflow_type_name, workflow_type_version, workflow_id, input=None, result=None, child_policy=None, control=None, tag_list=None): conn = ConnectedSWFObject().connection conn.start_child_workflow_execution(workflow_type_name, workflow_type_version, workflow_id, child_policy=child_policy, control=control, tag_list=tag_list, task_list=task_list) resp = conn.poll_for_decision_task( domain, task_list, identity=swf_identity(), ) conn.respond_decision_task_completed( resp['taskToken'], decisions=[{ 'decisionType': 'CompleteWorkflowExecution', 'completeWorkflowExecutionDecisionAttributes': { 'result': result, }, }])
def test_swf_identity_standard_case(self, mock_pid, mock_user, mock_host): mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 expect(json.loads(swf_identity())).to.equal({ "hostname": "foo.example.com", "user": "******", "pid": 1234, })
def run_fake_activity_task(domain, task_list, result): conn = ConnectedSWFObject().connection resp = conn.poll_for_activity_task( domain, task_list, identity=swf_identity(), ) conn.respond_activity_task_completed( resp['taskToken'], result, )
def test_swf_identity_truncated(self, mock_pid, mock_user, mock_host): """ The result should be truncated to 256 characters. Producing an invalid JSON string is better than producing an invalid SWF response (for now). Later we might externalize this another way (think Data Converters). """ mock_host.return_value = "a" * 250 mock_user.return_value = "root" mock_pid.return_value = 1234 expect(swf_identity()).to.have.length_of(256)
def test_swf_identity_standard_case(self, mock_pid, mock_user, mock_host): mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 expect( json.loads(swf_identity()) ).to.equal({ "hostname": "foo.example.com", "user": "******", "pid": 1234, })
def identity(self): """Identity when polling decision task. http://docs.aws.amazon.com/amazonswf/latest/apireference/API_PollForDecisionTask.html Identity of the decider making the request, which is recorded in the DecisionTaskStarted event in the workflow history. This enables diagnostic tracing when problems arise. The form of this identity is user defined. Minimum length of 0. Maximum length of 256. """ return swf_identity()
def test_swf_identity_with_invalid_extra_environment(self, mock_pid, mock_user, mock_host): """ If SIMPLEFLOW_IDENTITY is invalid, it should just be ignored. """ mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 with patch.dict("os.environ", {"SIMPLEFLOW_IDENTITY": 'not a json string'}): identity = json.loads(swf_identity()) expect(identity["hostname"]).to.equal("foo.example.com") expect(identity).to_not.have.key("version")
def test_swf_identity_with_extra_environment(self, mock_pid, mock_user, mock_host): """ SIMPLEFLOW_IDENTITY environment variable can provide extra keys. """ mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 with patch.dict("os.environ", {"SIMPLEFLOW_IDENTITY": '{"version":"1.2.3","hostname":"bar.example.com"}'}): identity = json.loads(swf_identity()) expect(identity["hostname"]).to.equal("bar.example.com") expect(identity).to.have.key("version").being.equal("1.2.3")
def test_swf_identity_with_invalid_extra_environment( self, mock_pid, mock_user, mock_host): """ If SIMPLEFLOW_IDENTITY is invalid, it should just be ignored. """ mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 os.environ["SIMPLEFLOW_IDENTITY"] = 'not a json string' identity = json.loads(swf_identity()) expect(identity["hostname"]).to.equal("foo.example.com") expect(identity).to_not.have.key("version")
def run_fake_child_workflow_task(domain, task_list, result=None): conn = ConnectedSWFObject().connection resp = conn.poll_for_decision_task( domain, task_list, identity=swf_identity(), ) conn.respond_decision_task_completed( resp['taskToken'], decisions=[{ 'decisionType': 'CompleteWorkflowExecution', 'completeWorkflowExecutionDecisionAttributes': { 'result': result, }, }])
def test_swf_identity_with_null_values_in_environment(self, mock_pid, mock_user, mock_host): """ SIMPLEFLOW_IDENTITY null values can remove default keys. """ mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 with patch.dict("os.environ", {"SIMPLEFLOW_IDENTITY": '{"foo":null,"user":null}'}): identity = json.loads(swf_identity()) # key removed expect(identity).to_not.have.key("user") # key ignored expect(identity).to_not.have.key("foo")
def test_swf_identity_with_extra_environment(self, mock_pid, mock_user, mock_host): """ SIMPLEFLOW_IDENTITY environment variable can provide extra keys. """ mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 os.environ[ "SIMPLEFLOW_IDENTITY"] = '{"version":"1.2.3","hostname":"bar.example.com"}' identity = json.loads(swf_identity()) expect(identity["hostname"]).to.equal("bar.example.com") expect(identity).to.have.key("version").being.equal("1.2.3")
def test_swf_identity_with_invalid_extra_environment( self, mock_process, mock_pid, mock_user, mock_host): """ If SIMPLEFLOW_IDENTITY is invalid, it should just be ignored. """ mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 mock_process.return_value.exe.return_value = "/bin/python8" with patch.dict("os.environ", {"SIMPLEFLOW_IDENTITY": "not a json string"}): identity = json.loads(swf_identity()) expect(identity["hostname"]).to.equal("foo.example.com") expect(identity).to_not.have.key("version")
def test_swf_identity_with_null_values_in_environment( self, mock_pid, mock_user, mock_host): """ SIMPLEFLOW_IDENTITY null values can remove default keys. """ mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 os.environ["SIMPLEFLOW_IDENTITY"] = '{"foo":null,"user":null}' identity = json.loads(swf_identity()) # key removed expect(identity).to_not.have.key("user") # key ignored expect(identity).to_not.have.key("foo")
def test_swf_identity_with_null_values_in_environment( self, mock_process, mock_pid, mock_user, mock_host): """ SIMPLEFLOW_IDENTITY null values can remove default keys. """ mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 mock_process.return_value.exe.return_value = "/bin/python8" with patch.dict("os.environ", {"SIMPLEFLOW_IDENTITY": '{"foo":null,"user":null}'}): identity = json.loads(swf_identity()) # key removed expect(identity).to_not.have.key("user") # key ignored expect(identity).to_not.have.key("foo")
def test_swf_identity_with_extra_environment(self, mock_process, mock_pid, mock_user, mock_host): """ SIMPLEFLOW_IDENTITY environment variable can provide extra keys. """ mock_host.return_value = "foo.example.com" mock_user.return_value = "root" mock_pid.return_value = 1234 mock_process.return_value.exe.return_value = "/bin/python8" with patch.dict( "os.environ", { "SIMPLEFLOW_IDENTITY": '{"version":"1.2.3","hostname":"bar.example.com"}' }, ): identity = json.loads(swf_identity()) expect(identity["hostname"]).to.equal("bar.example.com") expect(identity).to.have.key("version").being.equal("1.2.3")