def test_get_todo_list_with_role(self): user = UserNode(uid='test_get_todo_list_with_role').save() task = user.create_task('task', { 'status': STATUS.IN_PROGRESS, 'roles': ['teacher', 'student', 'parent'] }) step1 = StepInst(name='s1', status=STATUS.IN_PROGRESS, assignees=['student', 'parent'], reviewers=['student', 'teacher']).save() step2 = StepInst(name='s2', status=STATUS.READY_FOR_REVIEW, assignees=['student', 'parent'], reviewers=['student', 'teacher']).save() step3 = StepInst(name='s3', status=STATUS.IN_PROGRESS, assignees=['parent'], reviewers=['teacher']).save() step4 = StepInst(name='s4', status=STATUS.IN_PROGRESS, assignees=['parent'], reviewers=['teacher']).save() task.steps.connect(step1) task.steps.connect(step2) task.steps.connect(step3) task.steps.connect(step4) user.change_role(task, user, 'student') todo_list = user.get_todo_list() todo_set = set(todo['step']['sid'] for todo in todo_list) self.assertEqual(2, len(todo_set)) self.assertIn(step1.sid, todo_set) self.assertIn(step2.sid, todo_set)
def setUp(self): neo4jdb.delete_all() sat = StepInst(name='SAT', status=STATUS.SKIPPED).save() ps = StepInst(name='PS', status=STATUS.READY_FOR_REVIEW).save() submit = StepInst(name='Submit', status=STATUS.NEW).save() ps.nexts.connect(sat) sat.nexts.connect(submit)
def test_trigger_start(self, mock_complete): node = StepInst(node_type=NODE_TYPE.START, status=STATUS.NEW) mock_task = MagicMock() node.task.get = MagicMock(return_value=mock_task) node.trigger() mock_complete.assert_called_once() mock_task.start.assert_called_once()
def test_trigger_self_end(self, mock_save): node = StepInst(node_type=NODE_TYPE.END, status=STATUS.NEW) mock_task = MagicMock() node.task.get = MagicMock(return_value=mock_task) node.trigger_self() mock_task.complete.assert_called_once() self.assertEqual(STATUS.COMPLETED, node.status)
def test_remove_nodes(self, mock_delete, mock_delete_components): node1 = StepInst() node2 = StepInst() task = TaskInst() task.steps.get = MagicMock(side_effect=[node1, node2]) task.remove_nodes([node1.sid, node2.sid]) self.assertEqual(2, mock_delete.call_count)
def test_remove_edges(self, mock_disconnect): node1 = StepInst() node2 = StepInst() edges = [(node1.sid, node2.sid)] task = TaskInst() task.steps.get = MagicMock(side_effect=[node1, node2]) task.remove_edges(edges) node1.nexts.disconnect.assert_called_once_with(node2)
def setUp(self): neo4jdb.delete_all() node1 = StepInst(name='SAT', status=STATUS.READY_FOR_REVIEW).save() node2 = StepInst(name='PS', status=STATUS.READY_FOR_REVIEW).save() node3 = StepInst(name='Submit', status=STATUS.NEW).save() node4 = StepInst(name='Toefl', status=STATUS.COMPLETED).save() node4.nexts.connect(node3) node1.nexts.connect(node3) node2.nexts.connect(node3)
def test_add_edges(self, mock_connect): edges = [('old_sid_123', 'old_sid_321')] sid_map = {'old_sid_123': 'new_sid_123', 'old_sid_321': 'new_sid_321'} node1 = StepInst() node2 = StepInst() task = TaskInst() task.steps.get = MagicMock(side_effect=[node1, node2]) task.add_edges(edges, sid_map) sid_args_list = task.steps.get.call_args_list self.assertEqual('new_sid_123', sid_args_list[0][1]['sid']) self.assertEqual('new_sid_321', sid_args_list[1][1]['sid']) mock_connect.assert_called_once()
def test_change_edges(self): node1 = StepInst() node2 = StepInst() task = TaskInst() next_step = MagicMock() node1.nexts.relationship = MagicMock(return_value=next_step) task.steps.get = MagicMock(side_effect=[node1, node2]) task.change_edges( [(node1.sid, node2.sid)], {node1.sid + '->' + node2.sid: { 'label': 'test_value' }}) next_step.save.assert_called_once() next_step.value = 'test_value'
def test_update_step_roles(self, mock_save): task = TaskInst() step1 = StepInst(assignees=['role1', 'role2'], reviewers=['role3', 'role4']) step2 = StepInst(assignees=['role2', 'role3'], reviewers=['role2', 'role4']) task.steps.all = MagicMock(return_value=[step1, step2]) roles = ['role2', 'role4'] task.update_step_roles(roles) self.assertEqual(['role1'], step1.assignees) self.assertEqual(['role3'], step1.reviewers) self.assertEqual(['role3'], step2.assignees) self.assertEqual([], step2.reviewers) self.assertEqual(2, mock_save.call_count)
def test_update(self, mock_save): t = '2018-05-12T21:54:43.562037Z' data = { 'id': '123', 'sid': 'sid123', 'deadline': t, 'name': 'new step', 'description': 'new description' } step = StepInst() step.update(data) self.assertEqual('new step', step.name) self.assertEqual('new description', step.description) self.assertEqual(parse(t), step.deadline) self.assertNotIn('id', data) self.assertNotIn('sid', data)
def test_in_progress_not_assignee(self): node = StepInst(name='hello') node.assignees = ['parent'] node.reviewers = ['teacher'] node.status = STATUS.IN_PROGRESS with self.assertRaises(CannotComplete): node.trigger('student')
def test_submit_for_review(self, mock_submit_for_review): node = StepInst(name='hello') node.assignees = ['student'] node.reviewers = ['teacher'] node.status = STATUS.IN_PROGRESS node.trigger('student') mock_submit_for_review.assert_called_once()
def test_complete(self, mock_complete): node = StepInst(name='hello') node.assignees = ['student'] node.reviewers = ['teacher'] node.status = STATUS.READY_FOR_REVIEW node.trigger('teacher') mock_complete.assert_called_once()
def test_add_then_delete(self): self.maxDiff = 1000 s = StepInst(name='s').save() components = s.add_components([{ 'app': 'Hello', 'cmp': 'World', 'oid': '12345' }, { 'app': 'Test', 'cmp': 'OBJ', 'oid': '23456' }, { 'app': 'Happy', 'cmp': 'Lemon', 'oid': '34567' }]) self.assertEqual( components, { '12345': { 'app': 'Hello', 'cmp': 'World', 'oid': '12345' }, '23456': { 'app': 'Test', 'cmp': 'OBJ', 'oid': '23456' }, '34567': { 'app': 'Happy', 'cmp': 'Lemon', 'oid': '34567' } }) components = s.delete_components(['23456', '34567']) self.assertEqual( components, {'12345': { 'app': 'Hello', 'cmp': 'World', 'oid': '12345' }}) components = s.delete_components(['12345']) self.assertEqual(components, {})
def test_change_node(self, mock_save): node1 = StepInst() node2 = StepInst() task = TaskInst() task.steps.get = MagicMock(side_effect=[node1, node2]) task.change_nodes( [node1.sid, node2.sid], { node1.sid: { 'name': 'node1 name', 'description': 'my description 1' }, node2.sid: { 'name': 'node2 name', 'description': 'my description 2' } }) self.assertEqual('node1 name', node1.name) self.assertEqual('node2 name', node2.name) self.assertEqual('my description 1', node1.description) self.assertEqual('my description 2', node2.description) self.assertEqual(2, mock_save.call_count)
def test_get_todo_list(self): user = UserNode(uid='test_get_todo_list').save() task1 = user.create_task('t1') task2 = user.create_task('t2') task3 = user.create_task('t3') self.assertEqual([], user.get_todo_list()) task1.status = STATUS.IN_PROGRESS task2.status = STATUS.IN_PROGRESS task3.status = STATUS.COMPLETED task1.save() task2.save() task3.save() step1_1 = StepInst(name='s1_1', status=STATUS.COMPLETED).save() step1_2 = StepInst(name='s1_2', status=STATUS.IN_PROGRESS).save() step2_1 = StepInst(name='s2_1', status=STATUS.READY_FOR_REVIEW).save() step2_2 = StepInst(name='s2_2', status=STATUS.SKIPPED).save() step3_1 = StepInst(name='s3_1', status=STATUS.IN_PROGRESS).save() step3_2 = StepInst(name='s3_2', status=STATUS.READY_FOR_REVIEW).save() task1.steps.connect(step1_1) task1.steps.connect(step1_2) task2.steps.connect(step2_1) task2.steps.connect(step2_2) task3.steps.connect(step3_1) task3.steps.connect(step3_2) todo_list = user.get_todo_list() todo_set = set(todo['task']['tid'] + todo['step']['sid'] for todo in todo_list) self.assertEqual(2, len(todo_set)) self.assertIn(task1.tid + step1_2.sid, todo_set) self.assertIn(task2.tid + step2_1.sid, todo_set)
def test_clone(self, mock_get_user): user = UserNode(uid='sample').save() task = user.create_task('task') task.status = STATUS.IN_PROGRESS step = StepInst(name='step', status=STATUS.IN_PROGRESS).save() start = task.steps.get(node_type=NODE_TYPE.START) end = task.steps.get(node_type=NODE_TYPE.END) start.nexts.connect(step) step.nexts.connect(end) task.steps.connect(step) new_task = task.clone() self.assertEqual(new_task.name, task.name) self.assertEqual(new_task.status, STATUS.NEW) new_start = new_task.steps.get(node_type=NODE_TYPE.START) new_step = new_task.steps.get(node_type=NODE_TYPE.NORMAL) new_end = new_task.steps.get(node_type=NODE_TYPE.END) self.assertEqual(new_step.name, 'step') self.assertEqual(new_step.status, STATUS.NEW) self.assertTrue(new_start.nexts.is_connected(new_step)) self.assertTrue(new_step.nexts.is_connected(new_end))
def test_no_reviewer(self, mock_complete): node = StepInst(name='hello') node.assignees = ['student'] node.status = STATUS.IN_PROGRESS node.trigger('student') mock_complete.assert_called_once()
def test_status_not_correct(self): node = StepInst(name='hello') node.assignees = ['student'] node.reviewers = ['teacher'] with self.assertRaises(CannotComplete): node.trigger('student')
def test_ready_for_review_not_reviewer(self): node = StepInst(name='hello') node.status = STATUS.READY_FOR_REVIEW node.reviewers = ['parent'] with self.assertRaises(CannotComplete): node.trigger('teacher')
def setUp(self): neo4jdb.delete_all() node = StepInst(name='world') node.save()
def setUp(Self): neo4jdb.delete_all() node2 = StepInst(name='PS', status=STATUS.READY_FOR_REVIEW).save() node3 = StepInst(name='Submit', status=STATUS.READY_FOR_REVIEW).save() node2.nexts.connect(node3)