1import boto.swf.layer2 2from boto.swf.layer2 import Domain, ActivityType, WorkflowType, WorkflowExecution 3from tests.unit import unittest 4from mock import Mock 5 6 7class TestDomain(unittest.TestCase): 8 9 def setUp(self): 10 boto.swf.layer2.Layer1 = Mock() 11 self.domain = Domain(name='test-domain', description='My test domain') 12 self.domain.aws_access_key_id = 'inheritable access key' 13 self.domain.aws_secret_access_key = 'inheritable secret key' 14 self.domain.region = 'test-region' 15 16 def test_domain_instantiation(self): 17 self.assertEquals('test-domain', self.domain.name) 18 self.assertEquals('My test domain', self.domain.description) 19 20 def test_domain_list_activities(self): 21 self.domain._swf.list_activity_types.return_value = { 22 'typeInfos': [{'activityType': {'name': 'DeleteLocalFile', 23 'version': '1.0'}, 24 'creationDate': 1332853651.235, 25 'status': 'REGISTERED'}, 26 {'activityType': {'name': 'DoUpdate', 'version': 'test'}, 27 'creationDate': 1333463734.528, 28 'status': 'REGISTERED'}, 29 {'activityType': {'name': 'GrayscaleTransform', 30 'version': '1.0'}, 31 'creationDate': 1332853651.18, 32 'status': 'REGISTERED'}, 33 {'activityType': {'name': 'S3Download', 'version': '1.0'}, 34 'creationDate': 1332853651.264, 35 'status': 'REGISTERED'}, 36 {'activityType': {'name': 'S3Upload', 'version': '1.0'}, 37 'creationDate': 1332853651.314, 38 'status': 'REGISTERED'}, 39 {'activityType': {'name': 'SepiaTransform', 'version': '1.1'}, 40 'creationDate': 1333373797.734, 41 'status': 'REGISTERED'}]} 42 43 expected_names = ('DeleteLocalFile', 'GrayscaleTransform', 'S3Download', 44 'S3Upload', 'SepiaTransform', 'DoUpdate') 45 46 activity_types = self.domain.activities() 47 self.assertEquals(6, len(activity_types)) 48 for activity_type in activity_types: 49 self.assertIsInstance(activity_type, ActivityType) 50 self.assertTrue(activity_type.name in expected_names) 51 self.assertEquals(self.domain.region, activity_type.region) 52 53 def test_domain_list_workflows(self): 54 self.domain._swf.list_workflow_types.return_value = { 55 'typeInfos': [{'creationDate': 1332853651.136, 56 'description': 'Image processing sample workflow type', 57 'status': 'REGISTERED', 58 'workflowType': {'name': 'ProcessFile', 'version': '1.0'}}, 59 {'creationDate': 1333551719.89, 60 'status': 'REGISTERED', 61 'workflowType': {'name': 'test_workflow_name', 62 'version': 'v1'}}]} 63 expected_names = ('ProcessFile', 'test_workflow_name') 64 65 workflow_types = self.domain.workflows() 66 self.assertEquals(2, len(workflow_types)) 67 for workflow_type in workflow_types: 68 self.assertIsInstance(workflow_type, WorkflowType) 69 self.assertTrue(workflow_type.name in expected_names) 70 self.assertEquals(self.domain.aws_access_key_id, workflow_type.aws_access_key_id) 71 self.assertEquals(self.domain.aws_secret_access_key, workflow_type.aws_secret_access_key) 72 self.assertEquals(self.domain.name, workflow_type.domain) 73 self.assertEquals(self.domain.region, workflow_type.region) 74 75 def test_domain_list_executions(self): 76 self.domain._swf.list_open_workflow_executions.return_value = { 77 'executionInfos': [{'cancelRequested': False, 78 'execution': {'runId': '12OeDTyoD27TDaafViz/QIlCHrYzspZmDgj0coIfjm868=', 79 'workflowId': 'ProcessFile-1.0-1378933928'}, 80 'executionStatus': 'OPEN', 81 'startTimestamp': 1378933928.676, 82 'workflowType': {'name': 'ProcessFile', 83 'version': '1.0'}}, 84 {'cancelRequested': False, 85 'execution': {'runId': '12GwBkx4hH6t2yaIh8LYxy5HyCM6HcyhDKePJCg0/ciJk=', 86 'workflowId': 'ProcessFile-1.0-1378933927'}, 87 'executionStatus': 'OPEN', 88 'startTimestamp': 1378933927.919, 89 'workflowType': {'name': 'ProcessFile', 90 'version': '1.0'}}, 91 {'cancelRequested': False, 92 'execution': {'runId': '12oRG3vEWrQ7oYBV+Bqi33Fht+ZRCYTt+tOdn5kLVcwKI=', 93 'workflowId': 'ProcessFile-1.0-1378933926'}, 94 'executionStatus': 'OPEN', 95 'startTimestamp': 1378933927.04, 96 'workflowType': {'name': 'ProcessFile', 97 'version': '1.0'}}, 98 {'cancelRequested': False, 99 'execution': {'runId': '12qrdcpYmad2cjnqJcM4Njm3qrCGvmRFR1wwQEt+a2ako=', 100 'workflowId': 'ProcessFile-1.0-1378933874'}, 101 'executionStatus': 'OPEN', 102 'startTimestamp': 1378933874.956, 103 'workflowType': {'name': 'ProcessFile', 104 'version': '1.0'}}]} 105 106 executions = self.domain.executions() 107 self.assertEquals(4, len(executions)) 108 for wf_execution in executions: 109 self.assertIsInstance(wf_execution, WorkflowExecution) 110 self.assertEquals(self.domain.aws_access_key_id, wf_execution.aws_access_key_id) 111 self.assertEquals(self.domain.aws_secret_access_key, wf_execution.aws_secret_access_key) 112 self.assertEquals(self.domain.name, wf_execution.domain) 113 self.assertEquals(self.domain.region, wf_execution.region) 114 115if __name__ == '__main__': 116 unittest.main() 117