Пример #1
0
    def test_creating_a_time_log_for_a_task_whose_dependent_tasks_has_not_finished_yet(self):
        """testing if a HTTPServer error will be raised when a time log tried
        to be created for a Task whose dependent tasks has not finished yet
        """
        # create a new task
        task2 = Task(
            name='Test Task 2',
            project=self.proj1,
            depends=[self.task1],
            resources=[self.user1],
            schedule_timing=4,
            schedule_unit='d',
            schedule_model='effort',
            status_list=self.task_status_list
        )
        DBSession.add(task2)
        DBSession.flush()
        transaction.commit()

        # now because task2 is depending on to the task1
        # and task1 is not finished yet (where the status is not
        # set to Complete, we should expect an HTTPServerError()
        # to be raised
        request = testing.DummyRequest()
        request.params['task_id'] = task2.id
        request.params['resource_id'] = self.user1.id
        request.params['start'] = "Fri, 01 Nov 2013 08:00:00 GMT"
        request.params['end'] = "Fri, 01 Nov 2013 17:00:00 GMT"

        response = time_log.create_time_log(request)
        self.assertEqual(
            response.status_int, 500
        )
Пример #2
0
    def test_deleting_time_log_for_a_task_with_status_complete(self):
        """testing if it is not allowed to delete a time log of a task with
        status completed
        """
        # TODO: This is also testing some functionality from view.task, slit it
        # create two new task
        task0 = Task(
            name='Test Task 0',
            project=self.proj1,
            status_list=self.task_status_list
        )
        task1 = Task(
            name='Test Task 1',
            parent=task0,
            status_list=self.task_status_list,
            resources=[self.user1]
        )
        task1.status = self.status_wip
        DBSession.add_all([task0, task1])
        DBSession.commit()
        DBSession.flush()
        transaction.commit()

        self.assertEqual(task0.status, self.status_new)
        self.assertEqual(task1.status, self.status_wip)

        # now add a time log for task3 through create_time_log view
        request = testing.DummyRequest()

        # patch get_logged_in_user
        admins = Group.query.filter(Group.name == 'admins').first()
        self.user1.groups.append(admins)
        m = mocker.Mocker()
        obj = m.replace("stalker_pyramid.views.auth.get_logged_in_user")
        obj(request)
        m.result(self.user1)
        m.count(1, 1000000000)
        m.replay()
        request.route_url = lambda x, id=1: 'view_user'

        request.params['task_id'] = task1.id
        request.params['resource_id'] = self.user1.id
        request.params['start'] = "Fri, 19 Nov 2013 08:00:00 GMT"
        request.params['end'] = "Fri, 19 Nov 2013 17:00:00 GMT"
        response = time_log.create_time_log(request)
        self.assertEqual(response.status_int, 200)

        # set it to complete
        task1.status = self.status_cmpl

        # now try to remove it
        request.matchdict['id'] = task1.time_logs[0].id
        response = time_log.delete_time_log(request)
        self.assertEqual(response.status_int, 500)
        self.assertEqual(
            response.body,
            'Error: You can not delete a TimeLog of a Task with status CMPL'
        )
Пример #3
0
    def test_creating_a_time_log_for_a_task_whose_dependending_tasks_already_has_time_logs(self):
        """testing if a HTTPServer error will be raised when a time log tried
        to be for a task whose depending tasks already has time logs created
        (This test should be in Stalker)
        """
        # create a new task
        task2 = Task(
            name='Test Task 2',
            project=self.proj1,
            depends=[self.task1],
            resources=[self.user1],
            schedule_timing=4,
            schedule_unit= 'd',
            schedule_model='effort',
            status_list=self.task_status_list
        )
        DBSession.add(task2)
        DBSession.flush()
        transaction.commit()

        # set the status of task1 to complete
        self.task1.status = self.status_cmpl
        # artificially update task2 status to rts
        task2.status = self.status_rts
        DBSession.flush()
        transaction.commit()

        # and now create time logs for task2
        request = testing.DummyRequest()
        request.params['task_id'] = task2.id
        request.params['resource_id'] = self.user1.id
        request.params['start'] = "Fri, 01 Nov 2013 08:00:00 GMT"
        request.params['end'] = "Fri, 01 Nov 2013 17:00:00 GMT"
        response = time_log.create_time_log(request)
        self.assertEqual(response.status_int, 200)
        DBSession.add(task2)
        DBSession.flush()
        transaction.commit()

        # now because task2 is depending on to the task1
        # and task2 has now started, entering any new time logs to task1
        # is forbidden
        request = testing.DummyRequest()
        request.params['task_id'] = self.task1.id
        request.params['resource_id'] = self.user1.id
        request.params['start'] = "Fri, 02 Nov 2013 08:00:00 GMT"
        request.params['end'] = "Fri, 02 Nov 2013 17:00:00 GMT"

        response = time_log.create_time_log(request)
        self.assertEqual(
            response.status_int, 500
        )
Пример #4
0
    def test_creating_a_time_log_for_a_leaf_task_will_set_its_parents_status_to_wip(self):
        """testing if the status of the parent task will turn to wip if time
        log is entered to a child task
        """
        # TODO: This is also testing some functionality from view.task, slit it
        # create two new task
        task0 = Task(
            name='Test Task 0',
            project=self.proj1,
            status_list=self.task_status_list
        )
        task1 = Task(
            name='Test Task 1',
            parent=task0,
            status_list=self.task_status_list
        )
        task2 = Task(
            name='Test Task 2',
            parent=task1,
            resources=[self.user1],
            status_list=self.task_status_list,
            status=self.status_rts
        )
        task3 = Task(
            name='Test Task 3',
            parent=task1,
            resources=[self.user1],
            status_list=self.task_status_list,
            status=self.status_rts
        )
        task4 = Task(
            name='Test Task 4',
            parent=task0,
            resources=[self.user1],
            status_list=self.task_status_list,
            status=self.status_rts
        )
        DBSession.add_all([task0, task1, task2, task3, task4])
        DBSession.commit()
        DBSession.flush()
        transaction.commit()

        self.assertEqual(task0.status, self.status_new)
        self.assertEqual(task1.status, self.status_new)
        self.assertEqual(task2.status, self.status_rts)
        self.assertEqual(task3.status, self.status_rts)
        self.assertEqual(task4.status, self.status_rts)

        # now add a time log for task3 through create_time_log view
        request = testing.DummyRequest()

        # patch get_logged_in_user
        admins = Group.query.filter(Group.name == 'admins').first()
        self.user1.groups.append(admins)
        m = mocker.Mocker()
        obj = m.replace("stalker_pyramid.views.auth.get_logged_in_user")
        obj(request)
        m.result(self.user1)
        m.count(1, 1000000000)
        m.replay()
        request.route_url = lambda x, id=1: 'view_user'

        request.params['task_id'] = task3.id
        request.params['resource_id'] = self.user1.id
        request.params['start'] = "Fri, 19 Nov 2013 08:00:00 GMT"
        request.params['end'] = "Fri, 19 Nov 2013 17:00:00 GMT"
        response = time_log.create_time_log(request)
        self.assertEqual(response.status_int, 200)

        # now expect to have the status of task1 to be wip
        self.assertEqual(task3.status, self.status_wip)
        self.assertEqual(task2.status, self.status_rts)
        self.assertEqual(task1.status, self.status_wip)
        self.assertEqual(task0.status, self.status_wip)
        self.assertEqual(task4.status, self.status_rts)

        request.params['task_id'] = task2.id
        request.params['resource_id'] = self.user1.id
        request.params['start'] = "Fri, 18 Nov 2013 08:00:00 GMT"
        request.params['end'] = "Fri, 18 Nov 2013 17:00:00 GMT"
        response = time_log.create_time_log(request)
        self.assertEqual(response.status_int, 200)

        # now expect to have the status of task1 to be wip
        self.assertEqual(task3.status, self.status_wip)
        self.assertEqual(task2.status, self.status_wip)
        self.assertEqual(task1.status, self.status_wip)
        self.assertEqual(task0.status, self.status_wip)
        self.assertEqual(task4.status, self.status_rts)

        # now request a review and approve the task2 and task3 and expect the
        # task1 status is complete
        from stalker_pyramid.views.task import request_review, review_task
        #request = testing.DummyRequest()
        request.matchdict['id'] = task2.id
        request.params['send_email'] = 0
        request.route_url = lambda x, id: 'localhost:6453/tasks/23/view'
        request.route_path = lambda x, id: '/tasks/23/view'

        response = request_review(request)
        self.assertEqual(response.status_int, 200)

        #request = testing.DummyRequest()
        request.matchdict['id'] = task3.id
        request.params['send_email'] = 0
        response = request_review(request)
        print response.body
        self.assertEqual(response.status_int, 200)

        self.assertEqual(task3.status, self.status_prev)
        self.assertEqual(task2.status, self.status_prev)
        self.assertEqual(task1.status, self.status_wip)
        self.assertEqual(task0.status, self.status_wip)
        self.assertEqual(task4.status, self.status_rts)

        # approve the task2
        request.matchdict['id'] = task2.id
        request.params['review'] = 'Approve'
        response = review_task(request)
        self.assertEqual(response.status_int, 200)

        # and except task1 is still wip
        self.assertEqual(task3.status, self.status_prev)
        self.assertEqual(task2.status, self.status_cmpl)
        self.assertEqual(task1.status, self.status_wip)
        self.assertEqual(task0.status, self.status_wip)
        self.assertEqual(task4.status, self.status_rts)

        # approve the task3
        request.matchdict['id'] = task3.id
        request.params['review'] = 'Approve'
        response = review_task(request)
        self.assertEqual(response.status_int, 200)

        # now check the statuses
        self.assertEqual(task3.status, self.status_cmpl)
        self.assertEqual(task2.status, self.status_cmpl)
        self.assertEqual(task1.status, self.status_cmpl)
        self.assertEqual(task0.status, self.status_wip)
        self.assertEqual(task4.status, self.status_rts)