Merge branch 'master' of https://github.com/kchenweijie/TaskFlow
This commit is contained in:
		| @@ -31,16 +31,20 @@ from taskflow.openstack.common import exception | ||||
| db_api.configure() | ||||
| db_api.SQL_CONNECTION = 'sqlite:///test.db' | ||||
|  | ||||
|  | ||||
| def setUpModule(): | ||||
|     if not path.isfile('test.db'): | ||||
|         models.create_tables() | ||||
|  | ||||
|  | ||||
| def tearDownModule(): | ||||
|     os.remove('test.db') | ||||
|  | ||||
| """ | ||||
| JobTest | ||||
| """ | ||||
|  | ||||
|  | ||||
| class JobTest(unittest.TestCase): | ||||
|     wf_ids = [] | ||||
|     wf_names = [] | ||||
| @@ -83,6 +87,7 @@ class JobTest(unittest.TestCase): | ||||
|         cls.job_names = [] | ||||
|  | ||||
|     def test_job_get(self): | ||||
|         print '\nTesting job_get...' | ||||
|         expected = self.job_names[0] | ||||
|         actual = db_api.job_get('', self.job_ids[0]).name | ||||
|  | ||||
| @@ -91,6 +96,7 @@ class JobTest(unittest.TestCase): | ||||
|         self.assertRaises(exception.NotFound, db_api.job_get, '', 9001) | ||||
|  | ||||
|     def test_job_update(self): | ||||
|         print '\nTesting job_update...' | ||||
|         db_api.job_update('', 1, dict(owner='OwnerTest', state=states.CLAIMED)) | ||||
|         job = db_api.job_get('', 1) | ||||
|  | ||||
| @@ -104,9 +110,11 @@ class JobTest(unittest.TestCase): | ||||
|  | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
| 		self.assertRaises(exception.NotFound, db_api.job_update, '', 9001, dict(owner='OwnerTest', state=states.CLAIMED)) | ||||
|         self.assertRaises(exception.NotFound, db_api.job_update, '', 9001, | ||||
|                           dict(owner='OwnerTest', state=states.CLAIMED)) | ||||
|  | ||||
|     def test_job_add_workflow(self): | ||||
|         print '\nTesting job_add_workflow...' | ||||
|         db_api.workflow_create('', u'workflow_10') | ||||
|         self.wf_ids.append(10) | ||||
|         self.wf_names.append(u'workflow_10') | ||||
| @@ -120,10 +128,13 @@ class JobTest(unittest.TestCase): | ||||
|  | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
| 		self.assertRaises(exception.NotFound, db_api.job_add_workflow, '', 9001, u'workflow_10') | ||||
| 		self.assertRaises(exception.NotFound, db_api.job_add_workflow, '', 1, u'workflow_9001') | ||||
|         self.assertRaises(exception.NotFound, db_api.job_add_workflow, '', | ||||
|                           9001, u'workflow_10') | ||||
|         self.assertRaises(exception.NotFound, db_api.job_add_workflow, '', | ||||
|                           1, u'workflow_9001') | ||||
|  | ||||
|     def test_job_get_owner(self): | ||||
|         print '\nTesting job_get_owner...' | ||||
|         actual = db_api.job_get_owner('', 1) | ||||
|  | ||||
|         self.assertIsNone(actual) | ||||
| @@ -131,6 +142,7 @@ class JobTest(unittest.TestCase): | ||||
|         self.assertRaises(exception.NotFound, db_api.job_get_owner, '', 9001) | ||||
|  | ||||
|     def test_job_get_state(self): | ||||
|         print '\nTesting job_get_state...' | ||||
|         expected = states.UNCLAIMED | ||||
|         actual = db_api.job_get_state('', 1) | ||||
|  | ||||
| @@ -139,6 +151,7 @@ class JobTest(unittest.TestCase): | ||||
|         self.assertRaises(exception.NotFound, db_api.job_get_state, '', 9001) | ||||
|  | ||||
|     def test_job_get_logbook(self): | ||||
|         print '\nTesting job_get_logbook...' | ||||
|         expected = self.lb_names[0] | ||||
|         actual = db_api.job_get_logbook('', 1).name | ||||
|  | ||||
| @@ -147,6 +160,7 @@ class JobTest(unittest.TestCase): | ||||
|         self.assertRaises(exception.NotFound, db_api.job_get_logbook, '', 9001) | ||||
|  | ||||
|     def test_job_create(self): | ||||
|         print '\nTesting job_create...' | ||||
|         id = 1 | ||||
|         while (self.job_ids.count(id) > 0): | ||||
|             id = id + 1 | ||||
| @@ -158,6 +172,7 @@ class JobTest(unittest.TestCase): | ||||
|         self.assertIsNotNone(actual) | ||||
|  | ||||
|     def test_job_destroy(self): | ||||
|         print '\nTesting job_destroy...' | ||||
|         id = self.job_ids.pop() | ||||
|         db_api.job_destroy('', id) | ||||
|         self.job_names.pop() | ||||
| @@ -167,6 +182,8 @@ class JobTest(unittest.TestCase): | ||||
| """ | ||||
| LogBookTest | ||||
| """ | ||||
|  | ||||
|  | ||||
| class LogBookTest(unittest.TestCase): | ||||
|     wf_ids = [] | ||||
|     wf_names = [] | ||||
| @@ -199,6 +216,7 @@ class LogBookTest(unittest.TestCase): | ||||
|         cls.lb_names = [] | ||||
|  | ||||
|     def test_logbook_get(self): | ||||
|         print '\nTesting logbook_get...' | ||||
|         expected = self.lb_names[0] | ||||
|         actual = db_api.logbook_get('', self.lb_ids[0]).name | ||||
|  | ||||
| @@ -207,6 +225,7 @@ class LogBookTest(unittest.TestCase): | ||||
|         self.assertRaises(exception.NotFound, db_api.logbook_get, '', 9001) | ||||
|  | ||||
|     def test_logbook_get_by_name(self): | ||||
|         print '\nTesting logbook_get_by_name...' | ||||
|         expected = [self.lb_ids[0]] | ||||
|         actual = [] | ||||
|         for logbook in db_api.logbook_get_by_name('', self.lb_names[0]): | ||||
| @@ -214,9 +233,11 @@ class LogBookTest(unittest.TestCase): | ||||
|  | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
| 		self.assertRaises(exception.NotFound, db_api.logbook_get_by_name, '', u'logbook_9001') | ||||
|         self.assertRaises(exception.NotFound, db_api.logbook_get_by_name, '', | ||||
|                           u'logbook_9001') | ||||
|  | ||||
|     def test_logbook_create(self): | ||||
|         print '\nTesting logbook_create...' | ||||
|         id = 1 | ||||
|         while (self.lb_ids.count(id) > 0): | ||||
|             id = id + 1 | ||||
| @@ -229,6 +250,7 @@ class LogBookTest(unittest.TestCase): | ||||
|         self.assertIsNotNone(actual) | ||||
|  | ||||
|     def test_logbook_get_workflows(self): | ||||
|         print '\nTesting logbook_get_workflows...' | ||||
|         expected = self.wf_ids | ||||
|         actual = [] | ||||
|         wfs = db_api.logbook_get_workflows('', self.lb_ids[0]) | ||||
| @@ -238,9 +260,11 @@ class LogBookTest(unittest.TestCase): | ||||
|  | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
| 		self.assertRaises(exception.NotFound, db_api.logbook_get_workflows, '', 9001) | ||||
|         self.assertRaises(exception.NotFound, db_api.logbook_get_workflows, | ||||
|                           '', 9001) | ||||
|  | ||||
|     def test_logbook_add_workflow(self): | ||||
|         print '\nTesting logbook_add_workflow...' | ||||
|         db_api.workflow_create('', u'workflow_10') | ||||
|         self.wf_ids.append(10) | ||||
|         self.wf_names.append(u'workflow_10') | ||||
| @@ -254,10 +278,13 @@ class LogBookTest(unittest.TestCase): | ||||
|  | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
| 		self.assertRaises(exception.NotFound, db_api.logbook_add_workflow, '', 9001, u'workflow_10') | ||||
| 		self.assertRaises(exception.NotFound, db_api.logbook_add_workflow, '', 1, u'workflow_9001') | ||||
|         self.assertRaises(exception.NotFound, db_api.logbook_add_workflow, '', | ||||
|                           9001, u'workflow_10') | ||||
|         self.assertRaises(exception.NotFound, db_api.logbook_add_workflow, '', | ||||
|                           1, u'workflow_9001') | ||||
|  | ||||
|     def test_logbook_destroy(self): | ||||
|         print '\nTesting logbook_destroy...' | ||||
|         id = self.lb_ids.pop() | ||||
|         db_api.logbook_destroy('', id) | ||||
|         self.lb_names.pop() | ||||
| @@ -267,6 +294,8 @@ class LogBookTest(unittest.TestCase): | ||||
| """ | ||||
| WorkflowTest | ||||
| """ | ||||
|  | ||||
|  | ||||
| class WorkflowTest(unittest.TestCase): | ||||
|     tsk_ids = [] | ||||
|     tsk_names = [] | ||||
| @@ -300,14 +329,17 @@ class WorkflowTest(unittest.TestCase): | ||||
|         cls.wf_names = [] | ||||
|  | ||||
|     def test_workflow_get(self): | ||||
|         print '\nTesting workflow_get...' | ||||
|         expected = self.wf_ids[0] | ||||
|         actual = db_api.workflow_get('', self.wf_names[0]).id | ||||
|  | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
| 		self.assertRaises(exception.NotFound, db_api.workflow_get, '', u'workflow_9001') | ||||
|         self.assertRaises(exception.NotFound, db_api.workflow_get, '', | ||||
|                           u'workflow_9001') | ||||
|  | ||||
|     def test_workflow_get_all(self): | ||||
|         print '\nTesting workflow_get_all...' | ||||
|         expected = self.wf_ids | ||||
|         actual = [] | ||||
|         temp = db_api.workflow_get_all('') | ||||
| @@ -318,6 +350,7 @@ class WorkflowTest(unittest.TestCase): | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
|     def test_workflow_get_names(self): | ||||
|         print '\nTesting workflow_get_names...' | ||||
|         expected = [] | ||||
|         for name in self.wf_names: | ||||
|             expected.append(name) | ||||
| @@ -328,6 +361,7 @@ class WorkflowTest(unittest.TestCase): | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
|     def test_workflow_get_tasks(self): | ||||
|         print '\nTesting workflow_get_tasks...' | ||||
|         expected = [self.tsk_names[0], self.tsk_names[9]] | ||||
|         actual = [] | ||||
|         temp = db_api.workflow_get_tasks('', u'workflow_1') | ||||
| @@ -337,9 +371,11 @@ class WorkflowTest(unittest.TestCase): | ||||
|  | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
| 		self.assertRaises(exception.NotFound, db_api.workflow_get_tasks, '', u'workflow_9001') | ||||
|         self.assertRaises(exception.NotFound, db_api.workflow_get_tasks, '', | ||||
|                           u'workflow_9001') | ||||
|  | ||||
|     def test_workflow_add_task(self): | ||||
|         print '\nTesting workflow_add_task...' | ||||
|         tsk_tmp = db_api.task_create('', u'task_10', 1, 10) | ||||
|         db_api.workflow_add_task('', u'workflow_1', 10) | ||||
|         self.tsk_ids.append(10) | ||||
| @@ -350,10 +386,13 @@ class WorkflowTest(unittest.TestCase): | ||||
|  | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
| 		self.assertRaises(exception.NotFound, db_api.workflow_add_task, '', u'workflow_9001', 10) | ||||
| 		self.assertRaises(exception.NotFound, db_api.workflow_add_task, '', u'workflow_1', 9001) | ||||
|         self.assertRaises(exception.NotFound, db_api.workflow_add_task, '', | ||||
|                           u'workflow_9001', 10) | ||||
|         self.assertRaises(exception.NotFound, db_api.workflow_add_task, '', | ||||
|                           u'workflow_1', 9001) | ||||
|  | ||||
|     def test_workflow_create(self): | ||||
|         print '\nTesting workflow_create...' | ||||
|         id = 0 | ||||
|         while (self.wf_ids.count(id) > 0): | ||||
|             id = id + 1 | ||||
| @@ -361,9 +400,11 @@ class WorkflowTest(unittest.TestCase): | ||||
|         self.wf_ids.append(id) | ||||
|         self.wf_names.append(u'workflow_{}'.format(id)) | ||||
|  | ||||
| 		self.assertIsNotNone(db_api.workflow_get('', u'workflow_{}'.format(id))) | ||||
|         self.assertIsNotNone(db_api.workflow_get('', | ||||
|                              u'workflow_{}'.format(id))) | ||||
|  | ||||
|     def test_workflow_destroy(self): | ||||
|         print '\nTesting workflow_destroy...' | ||||
|         name = self.wf_names.pop() | ||||
|         db_api.workflow_destroy('', name) | ||||
|         self.wf_ids.pop() | ||||
| @@ -373,6 +414,8 @@ class WorkflowTest(unittest.TestCase): | ||||
| """ | ||||
| TaskTest | ||||
| """ | ||||
|  | ||||
|  | ||||
| class TaskTest(unittest.TestCase): | ||||
|     tsk_ids = [] | ||||
|     tsk_names = [] | ||||
| @@ -393,6 +436,7 @@ class TaskTest(unittest.TestCase): | ||||
|         cls.tsk_names = [] | ||||
|  | ||||
|     def test_task_get(self): | ||||
|         print '\nTesting task_get...' | ||||
|         expected = self.tsk_names[0] | ||||
|         actual = db_api.task_get('', self.tsk_ids[0]) | ||||
|  | ||||
| @@ -401,6 +445,7 @@ class TaskTest(unittest.TestCase): | ||||
|         self.assertRaises(exception.NotFound, db_api.task_get, '', 9001) | ||||
|  | ||||
|     def test_task_create(self): | ||||
|         print '\nTesting task_create...' | ||||
|         id = 1 | ||||
|         while (self.tsk_ids.count(id) > 0): | ||||
|             id = id + 1 | ||||
| @@ -411,7 +456,9 @@ class TaskTest(unittest.TestCase): | ||||
|         self.assertIsNotNone(db_api.task_get('', id)) | ||||
|  | ||||
|     def test_task_update(self): | ||||
| 		db_api.task_update('', 1, dict(exception='ExceptionTest', stacktrace='StacktraceTest')) | ||||
|         print '\nTesting task_update...' | ||||
|         db_api.task_update('', 1, dict(exception='ExceptionTest', | ||||
|                            stacktrace='StacktraceTest')) | ||||
|         task = db_api.task_get('', 1) | ||||
|  | ||||
|         expected = 'ExceptionTest' | ||||
| @@ -424,9 +471,11 @@ class TaskTest(unittest.TestCase): | ||||
|  | ||||
|         self.assertEquals(expected, actual) | ||||
|  | ||||
| 		self.assertRaises(exception.NotFound, db_api.task_update, '', 9001, dict(exception='ExceptionTest', stacktrace='StacktraceTest')) | ||||
|         self.assertRaises(exception.NotFound, db_api.task_update, '', 9001, | ||||
|                           dict(exception='ExceptionTest', stacktrace='StacktraceTest')) | ||||
|  | ||||
|     def test_task_destroy(self): | ||||
|         print '\nTesting task_destroy...' | ||||
|         id = self.tsk_ids.pop() | ||||
|         db_api.task_destroy('', id) | ||||
|         self.tsk_names.pop() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kevin Chen
					Kevin Chen