예제 #1
0
 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)
예제 #2
0
 def test_delete(self, mock_delete):
     task = TaskInst()
     mock_step = MagicMock()
     task.steps = [mock_step] * 2
     task.delete()
     self.assertEqual(2, mock_step.delete.call_count)
     mock_delete.assert_called_once()
예제 #3
0
 def test_update_roles(self, mock_set_diff, mock_update_step_roles,
                       mock_update_user_roles):
     task = TaskInst()
     task.update_roles({})
     mock_set_diff.assert_called_once()
     mock_update_user_roles.assert_called_once()
     mock_update_user_roles.assert_called_once()
예제 #4
0
 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)
예제 #5
0
    def test_assert_no_user(self):
        user = UserNode(uid='abc').save()
        task = user.create_task(name='name')
        with self.assertRaises(BadRequest):
            task.assert_no_user()

        task = TaskInst(name='name').save()
        task.assert_no_user()
예제 #6
0
 def test_get_info_origin(self):
     task = TaskInst()
     task.origin = MagicMock()
     origin_task = MagicMock()
     origin_task.tid = 'hello'
     task.origin.all = MagicMock(return_value=[origin_task])
     origin = task.get_origin()
     self.assertEqual(origin_task, origin)
     info = task.get_info()
     info['tid'] = 'hello'
예제 #7
0
 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()
예제 #8
0
 def test_upload(self, mock_assert_owner, mock_assert_original, mock_clone,
                 mock_upgrade_graph):
     user = UserNode()
     task = TaskInst()
     new_task = TaskInst()
     mock_clone.return_value = new_task
     result = user.upload(task)
     self.assertTrue(new_task is result)
     mock_assert_original.assert_called_once()
     mock_assert_owner.assert_called_once_with(task)
     mock_clone.assert_called_once()
     mock_upgrade_graph.assert_not_called()
예제 #9
0
 def test_upload_existing_task(self, mock_assert_owner,
                               mock_assert_original, mock_clone,
                               mock_upgrade_graph):
     user = UserNode()
     task = TaskInst()
     target_task = TaskInst()
     new_task = user.upload(task, target_task)
     self.assertIs(new_task, target_task)
     mock_assert_owner.assert_called_once_with(task)
     mock_assert_original.assert_called_once()
     mock_clone.assert_not_called()
     mock_upgrade_graph.assert_called_once()
예제 #10
0
 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)
예제 #11
0
 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'
예제 #12
0
 def test_update_user_roles(self):
     task = TaskInst()
     user1 = MagicMock()
     user2 = MagicMock()
     user1_has_task = MagicMock()
     user1_has_task.role = 'role1'
     user2_has_task = MagicMock()
     user2_has_task.role = 'role2'
     user1.tasks.relationship = MagicMock(return_value=user1_has_task)
     user2.tasks.relationship = MagicMock(return_value=user2_has_task)
     task.users.all = MagicMock(return_value=[user1, user2])
     task.update_user_roles(['role2', 'role3'])
     self.assertEqual('role1', user1_has_task.role)
     self.assertEqual(None, user2_has_task.role)
     user1_has_task.save.assert_not_called()
     user2_has_task.save.assert_called_once()
예제 #13
0
 def test_invite_success(self, mock_relationship, mock_is_connected, mock_connect, mock_invite):
     user = UserNode()
     user.uid = 'abc'
     target_user = UserNode()
     target_user.uid = 'def'
     task = TaskInst(roles=['teacher'])
     task.tid = 'xyz'
     user.invite(task, target_user, role='teacher')
     mock_connect.assert_called_once_with(task, {
         'role': 'teacher',
         'super_role': SUPER_ROLE.STANDARD
     })
     mock_invite.assert_called_once_with(
         [target_user.uid],
         inviter_id=user.uid,
         task_id=task.tid)
예제 #14
0
 def test_respond_invitation_success(self, mock_save):
     user = UserNode()
     task = TaskInst()
     mock_has_task = HasTask(super_role=SUPER_ROLE.STANDARD, acceptance=ACCEPTANCE.WAITING)
     user.tasks.relationship = MagicMock(return_value=mock_has_task)
     user.respond_invitation(task, ACCEPTANCE.ACCEPT)
     self.assertEqual(ACCEPTANCE.ACCEPT, mock_has_task.acceptance)
예제 #15
0
 def test_upgrade_graph(self):
     data = {'nodes': 'abc', 'edges': 'def', 'task_info': 'ghi'}
     t1 = TaskInst()
     t2 = TaskInst()
     t1.save_graph = MagicMock()
     t2.get_graph = MagicMock(return_value=data)
     t1.upgrade_graph(t2)
     t2.get_graph.assert_called_once()
     t1.save_graph.assert_called_once_with('abc', 'def', 'ghi')
예제 #16
0
 def test_save_graph(self, mock_assert_start_end, mock_get_sid_edge_sets,
                     mock_set_diff, mock_get_node_edge_map,
                     mock_remove_edges, mock_remove_nodes,
                     mock_change_edges, mock_change_nodes, mock_add_edges,
                     mock_add_nodes, mock_preprocess_edges,
                     mock_get_user_list):
     task = TaskInst(name='task').save()
     task.save_graph('my nodes', 'my edges')
     mock_assert_start_end.assert_called_once_with('my nodes')
     self.assertEqual(2, mock_get_sid_edge_sets.call_count)
     self.assertEqual(2, mock_set_diff.call_count)
     mock_get_node_edge_map.assert_called_once_with('my nodes',
                                                    'processed_edges')
     mock_remove_edges.assert_called_once()
     mock_remove_nodes.assert_called_once()
     mock_change_edges.assert_called_once()
     mock_change_nodes.assert_called_once()
     mock_add_edges.assert_called_once()
     mock_add_nodes.assert_called_once()
예제 #17
0
 def test_download(self, mock_assert_no_user, mock_clone_task):
     user = UserNode()
     task = TaskInst()
     new_task = MagicMock()
     mock_clone_task.return_value = new_task
     result = user.download(task)
     self.assertEqual(new_task, result)
     mock_assert_no_user.assert_called_once()
     mock_clone_task.assert_called_once_with(task)
     new_task.set_origin.assert_called_once_with(task)
예제 #18
0
 def test_add_nodes(self, mock_save, mock_connect):
     sids = ['newsid']
     node_map = {
         'newsid': {
             'name': 'new node',
             'description': 'new description',
             'sid': 'sid123',
             'id': '123'
         }
     }
     task = TaskInst()
     sid_map = task.add_nodes(sids, node_map)
     node = mock_connect.call_args[0][0]
     mock_save.assert_called_once()
     mock_connect.assert_called_once()
     self.assertEqual({'newsid': node.sid}, sid_map)
     self.assertEqual('new node', node.name)
     self.assertEqual('new description', node.description)
     self.assertNotEqual('sid123', node.sid)
예제 #19
0
 def test_change_invitation_change_super_role_admin(self, mock_save):
     mock_owner_has_task = HasTask(super_role=SUPER_ROLE.OWNER, acceptance=ACCEPTANCE.ACCEPT)
     mock_user_has_task = HasTask(super_role=SUPER_ROLE.STANDARD, acceptance=ACCEPTANCE.ACCEPT)
     user = UserNode()
     task = TaskInst()
     target_user = UserNode()
     user.tasks.relationship = MagicMock(return_value=mock_owner_has_task)
     target_user.tasks.relationship = MagicMock(return_value=mock_user_has_task)
     user.change_invitation(task, target_user, super_role=SUPER_ROLE.ADMIN)
     self.assertEqual(SUPER_ROLE.ADMIN, mock_user_has_task.super_role)
     self.assertEqual(SUPER_ROLE.OWNER, mock_owner_has_task.super_role)
예제 #20
0
 def test_change_invitation_change_role(self, mock_save):
     mock_owner_has_task = HasTask(super_role=SUPER_ROLE.OWNER, acceptance=ACCEPTANCE.ACCEPT)
     mock_user_has_task = HasTask(super_role=SUPER_ROLE.OWNER, acceptance=ACCEPTANCE.ACCEPT)
     user = UserNode()
     task = TaskInst(roles=['teacher'])
     target_user = UserNode()
     user.tasks.relationship = MagicMock(return_value=mock_owner_has_task)
     target_user.tasks.relationship = MagicMock(return_value=mock_user_has_task)
     user.change_invitation(task, target_user, role='teacher')
     self.assertEqual('teacher', mock_user_has_task.role)
     self.assertEqual(SUPER_ROLE.OWNER, mock_user_has_task.super_role)
예제 #21
0
 def test_update(self, mock_update_roles, mock_save):
     t = '2018-05-12T21:54:43.562037Z'
     task_info = {
         'id': 'test id',
         'tid': 'test tid',
         'name': 'new task',
         'deadline': t,
         'description': 'new description',
         'roles': ['role1', 'role2']
     }
     task = TaskInst(name='hello', roles=['role2', 'role3'])
     task.update(task_info)
     self.assertEqual('new task', task.name)
     self.assertEqual('new description', task.description)
     self.assertEqual(['role1', 'role2'], task.roles)
     self.assertEqual(['role1', 'role2'], task.roles)
     self.assertFalse(hasattr(task, 'id'))
     self.assertNotEqual('test tid', task.tid)
     self.assertEqual(parse(t), task.deadline)
     mock_update_roles.assert_called_once_with(['role2', 'role3'])
예제 #22
0
 def test_update_task_success(self, mock_update, mock_assert_admin, mock_assert_accept):
     user = UserNode()
     task = TaskInst()
     data = {
         'name': 'task name',
         'description': 'task description'
     }
     user.update_task(task, data)
     mock_update.assert_called_once()
     mock_assert_admin.assert_called_once()
     mock_assert_accept.assert_called_once()
예제 #23
0
 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)
예제 #24
0
 def test_preprocess_edges(self):
     sample_edges = [{
         'from': 'node1',
         'to': 'node2'
     }, {
         'from': 'node1',
         'to': 'node2'
     }, {
         'from': 'node1',
         'to': 'node2'
     }, {
         'from': 'node3',
         'to': 'node3'
     }]
     processed_edges = TaskInst.preprocess_edges(sample_edges)
     self.assertEqual([{'from': 'node1', 'to': 'node2'}], processed_edges)
예제 #25
0
    def test_tid_to_task(self):
        user = UserNode(uid='abc').save()
        task = TaskInst(name='hi').save()

        kwargs = {'tid': task.tid}
        with self.assertRaises(DoesNotExist):
            utils.tid_to_task(user, kwargs)

        task.allow_link_sharing = True
        task.save()

        utils.tid_to_task(user, kwargs)
        self.assertNotIn('tid', kwargs)
        self.assertEqual(task, kwargs['task'])
        has_task = user.tasks.relationship(task)
        self.assertEqual(ACCEPTANCE.ACCEPT, has_task.acceptance)

        has_task.acceptance = ACCEPTANCE.REJECT
        has_task.save()
        kwargs = {'tid': task.tid}
        utils.tid_to_task(user, kwargs)
        self.assertNotIn('tid', kwargs)
        self.assertEqual(task, kwargs['task'])
        has_task = user.tasks.relationship(task)
        self.assertEqual(ACCEPTANCE.ACCEPT, has_task.acceptance)

        task.allow_link_sharing = False
        has_task.acceptance = ACCEPTANCE.REJECT
        task.save()
        has_task.save()
        kwargs = {'tid': task.tid}
        utils.tid_to_task(user, kwargs)
        self.assertNotIn('tid', kwargs)
        self.assertEqual(task, kwargs['task'])
        has_task = user.tasks.relationship(task)
        self.assertEqual(ACCEPTANCE.ACCEPT, has_task.acceptance)
예제 #26
0
 def test_assert_has_task(self):
     user = UserNode(uid='user node test uid 1').save()
     task = TaskInst(name='new task').save()
     with self.assertRaises(BadRequest):
         user.assert_has_task(task)
예제 #27
0
 def test_assert_original(self):
     task = TaskInst(name='name').save()
     task.assert_original()
     new_task = TaskInst(name='new').save()
     new_task.set_origin(task)
     task.assert_original()
     with self.assertRaises(BadRequest):
         new_task.assert_original()
예제 #28
0
 def test_complete(self, mock_save):
     task = TaskInst()
     task.complete()
     self.assertEqual(STATUS.COMPLETED, task.status)
     mock_save.assert_called_once()
예제 #29
0
 def test_get_info_no_origin(self):
     task = TaskInst()
     task.origin = MagicMock()
     task.origin.all = MagicMock(return_value=[])
     origin = task.get_origin()
     self.assertIs(None, origin)
예제 #30
0
 def test_start(self, mock_save):
     task = TaskInst()
     task.start()
     self.assertEqual(STATUS.IN_PROGRESS, task.status)
     mock_save.assert_called_once()