def workflows(self, status=REGISTERED): """Lists the current domain's workflow types :param status: Specifies the registration status of the workflow types to list. Valid values are: * swf.constants.REGISTERED * swf.constants.DEPRECATED :type status: string """ from swf.querysets.workflow import WorkflowTypeQuerySet qs = WorkflowTypeQuerySet(self) return qs.all(registration_status=status)
def upstream(self): from swf.querysets.workflow import WorkflowTypeQuerySet qs = WorkflowTypeQuerySet(self.domain) return qs.get(self.name, self.version)
def setUp(self): self.domain = Domain("TestDomain") self.wtq = WorkflowTypeQuerySet(self.domain)
class TestWorkflowTypeQuerySet(unittest.TestCase): def setUp(self): self.domain = Domain("TestDomain") self.wtq = WorkflowTypeQuerySet(self.domain) def tearDown(self): pass def test_valid_workflow_type(self): with patch.object(self.wtq.connection, 'describe_workflow_type', mock_describe_workflow_type): wt = self.wtq.get("TestType", "0.1") self.assertIsNotNone(wt) self.assertIsInstance(wt, WorkflowType) def test_get_non_existent_workflow_type(self): with patch.object(self.wtq.connection, 'describe_workflow_type') as mock: with self.assertRaises(DoesNotExistError): mock.side_effect = SWFResponseError(400, "mocked exception", { "__type": "UnknownResourceFault", "message": "Whatever", }) self.wtq.get("NonExistentWorkflowType", "0.1") def test_get_whatever_failing_workflow_type(self): with patch.object(self.wtq.connection, 'describe_workflow_type') as mock: with self.assertRaises(ResponseError): mock.side_effect = SWFResponseError(400, "mocked exception", { "__type": "Whatever Error", "message": "Whatever", }) self.wtq.get("NonExistentWorkflowType", "0.1") def test_get_or_create_existing_workflow_type(self): with patch.object(Layer1, 'describe_workflow_type', mock_describe_workflow_type): workflow_type = self.wtq.get_or_create("TestActivityType", "testversion") self.assertIsInstance(workflow_type, WorkflowType) def test_get_or_create_non_existent_workflow_type(self): with patch.object(Layer1, 'describe_workflow_type') as mock: mock.side_effect = DoesNotExistError("Mocked exception") with patch.object(Layer1, 'register_workflow_type', mock_describe_workflow_type): workflow_type = self.wtq.get_or_create("TestDomain", "testversion") self.assertIsInstance(workflow_type, WorkflowType) def test__list_non_empty_workflow_types(self): with patch.object(self.wtq.connection, 'list_workflow_types', mock_list_workflow_types): wt = self.wtq._list() self.assertIsNotNone(wt) self.assertIsInstance(wt, dict) for workflow in wt[WorkflowTypeQuerySet._infos_plural]: self.assertIsInstance(workflow, dict) def test_filter_with_registered_status(self): # Nota: mock_list_workfflow_types returned # values are REGISTERED with patch.object(self.wtq.connection, 'list_workflow_types', mock_list_workflow_types): types = self.wtq.filter(registration_status=REGISTERED) self.assertIsNotNone(types) self.assertIsInstance(types, list) for wt in types: self.assertIsInstance(wt, WorkflowType) self.assertEqual(wt.status, REGISTERED) def test_create_workflow_type(self): with patch.object(Layer1, 'register_workflow_type'): new_wt = self.wtq.create( self.domain, "TestWorkflowType", "0.test", ) self.assertIsNotNone(new_wt) self.assertIsInstance(new_wt, WorkflowType)
class TestWorkflowTypeQuerySet(unittest.TestCase): def setUp(self): self.domain = Domain("TestDomain") self.wtq = WorkflowTypeQuerySet(self.domain) def tearDown(self): pass def test_valid_workflow_type(self): with patch.object( self.wtq.connection, 'describe_workflow_type', mock_describe_workflow_type ): wt = self.wtq.get("TestType", "0.1") self.assertIsNotNone(wt) self.assertIsInstance(wt, WorkflowType) def test_get_non_existent_workflow_type(self): with patch.object(self.wtq.connection, 'describe_workflow_type') as mock: with self.assertRaises(DoesNotExistError): mock.side_effect = SWFResponseError( 400, "mocked exception", { "__type": "UnknownResourceFault", "message": "Whatever", } ) self.wtq.get("NonExistentWorkflowType", "0.1") def test_get_whatever_failing_workflow_type(self): with patch.object(self.wtq.connection, 'describe_workflow_type') as mock: with self.assertRaises(ResponseError): mock.side_effect = SWFResponseError( 400, "mocked exception", { "__type": "Whatever Error", "message": "Whatever", } ) self.wtq.get("NonExistentWorkflowType", "0.1") def test_get_or_create_existing_workflow_type(self): with patch.object(Layer1, 'describe_workflow_type', mock_describe_workflow_type): workflow_type = self.wtq.get_or_create("TestActivityType", "testversion") self.assertIsInstance(workflow_type, WorkflowType) def test_get_or_create_non_existent_workflow_type(self): with patch.object(Layer1, 'describe_workflow_type') as mock: mock.side_effect = DoesNotExistError("Mocked exception") with patch.object(Layer1, 'register_workflow_type', mock_describe_workflow_type): workflow_type = self.wtq.get_or_create("TestDomain", "testversion") self.assertIsInstance(workflow_type, WorkflowType) def test__list_non_empty_workflow_types(self): with patch.object( self.wtq.connection, 'list_workflow_types', mock_list_workflow_types ): wt = self.wtq._list() self.assertIsNotNone(wt) self.assertIsInstance(wt, dict) for workflow in wt[WorkflowTypeQuerySet._infos_plural]: self.assertIsInstance(workflow, dict) def test_filter_with_registered_status(self): # Nota: mock_list_workfflow_types returned # values are REGISTERED with patch.object( self.wtq.connection, 'list_workflow_types', mock_list_workflow_types ): types = self.wtq.filter(registration_status=REGISTERED) self.assertIsNotNone(types) self.assertIsInstance(types, list) for wt in types: self.assertIsInstance(wt, WorkflowType) self.assertEqual(wt.status, REGISTERED) def test_create_workflow_type(self): with patch.object(Layer1, 'register_workflow_type'): new_wt = self.wtq.create( self.domain, "TestWorkflowType", "0.test", ) self.assertIsNotNone(new_wt) self.assertIsInstance(new_wt, WorkflowType)