Beispiel #1
0
    def test_list_tasks(self):

        expected_response = self.tasks_list_1.tasks
        actual_response = TaskDAO.list_tasks(
            self.first_user.id, self.mentorship_relation_w_second_user.id)

        self.assertEqual(expected_response, actual_response)
Beispiel #2
0
    def test_list_empty_tasks(self):

        expected_response = []
        actual_response = TaskDAO.list_tasks(
            self.admin_user.id, self.mentorship_relation_without_first_user.id)

        self.assertEqual(expected_response, actual_response)
    def post(cls, request_id):
        """
        Create a task for a mentorship relation.

        Input:
        1. Header: valid access token
        2. Path: ID of request for which task is being created (request_id)
        3. Body: JSON object containing description of task.

        Returns:
        Success or failure message. It gets added to GET /tasks endpoint and
        is visible to the other person in the mentorship relation.
        """

        # TODO check if user id is well parsed, if it is an integer

        user_id = get_jwt_identity()
        request_body = request.json

        is_valid = CreateTask.is_valid_data(request_body)

        if is_valid != {}:
            return is_valid, HTTPStatus.BAD_REQUEST

        response = TaskDAO.create_task(user_id=user_id,
                                       mentorship_relation_id=request_id,
                                       data=request_body)

        return response
Beispiel #4
0
    def test_list_tasks_with_user_not_involved(self):

        expected_response = messages.USER_NOT_INVOLVED_IN_THIS_MENTOR_RELATION, 401
        actual_response = TaskDAO.list_tasks(
            self.admin_user.id, self.mentorship_relation_w_second_user.id)

        self.assertEqual(expected_response, actual_response)
Beispiel #5
0
    def test_list_tasks_with_non_existent_user(self):

        expected_response = messages.USER_DOES_NOT_EXIST, 404
        actual_response = TaskDAO.list_tasks(
            123123, self.mentorship_relation_w_second_user.id)

        self.assertEqual(expected_response, actual_response)
    def test_achieve_not_existent_task(self):

        expected_response = messages.TASK_DOES_NOT_EXIST, 404
        actual_response = TaskDAO.complete_task(
            self.first_user.id, self.mentorship_relation_w_second_user.id,
            123123)

        self.assertEqual(expected_response, actual_response)
    def test_achieve_achieved_task(self):
        self.assertTrue(self.tasks_list_1.find_task_by_id(2).get("is_done"))

        expected_response = messages.TASK_WAS_ALREADY_ACHIEVED, 400
        actual_response = TaskDAO.complete_task(
            self.first_user.id, self.mentorship_relation_w_second_user.id, 2)

        self.assertTrue(self.tasks_list_1.find_task_by_id(2).get("is_done"))
        self.assertEqual(expected_response, actual_response)
    def test_achieve_not_achieved_task(self):
        self.assertFalse(self.tasks_list_1.find_task_by_id(1).get("is_done"))

        expected_response = messages.TASK_WAS_ACHIEVED_SUCCESSFULLY, 200
        actual_response = TaskDAO.complete_task(
            self.first_user.id, self.mentorship_relation_w_second_user.id, 1)

        self.assertTrue(self.tasks_list_1.find_task_by_id(1).get("is_done"))
        self.assertEqual(expected_response, actual_response)
    def test_create_task_with_non_existing_mentorship_relation(self):

        expected_response = messages.MENTORSHIP_RELATION_DOES_NOT_EXIST, 404

        actual_response = TaskDAO.create_task(
            user_id=self.first_user.id,
            mentorship_relation_id=123123,
            data=dict(description=self.test_description,
                      is_done=self.test_is_done),
        )

        self.assertEqual(expected_response, actual_response)
    def test_create_task_with_mentorship_relation_non_accepted_state(self):

        expected_response = messages.UNACCEPTED_STATE_RELATION, 400
        self.mentorship_relation_w_second_user.state = MentorshipRelationState.CANCELLED

        actual_response = TaskDAO.create_task(
            user_id=self.first_user.id,
            mentorship_relation_id=self.mentorship_relation_w_second_user.id,
            data=dict(description=self.test_description,
                      is_done=self.test_is_done),
        )

        self.assertEqual(expected_response, actual_response)
    def test_create_task_with_user_not_involved_in_mentorship(self):

        expected_response = messages.USER_NOT_INVOLVED_IN_THIS_MENTOR_RELATION, 403
        self.mentorship_relation_w_second_user.state = MentorshipRelationState.ACCEPTED

        actual_response = TaskDAO.create_task(
            user_id=self.fourth_user.id,
            mentorship_relation_id=self.mentorship_relation_w_second_user.id,
            data=dict(description=self.test_description,
                      is_done=self.test_is_done),
        )

        self.assertEqual(expected_response, actual_response)
    def test_delete_existent_task(self):

        expected_response = messages.TASK_WAS_DELETED_SUCCESSFULLY, 200
        first_task_id = 1

        not_deleted_yet_task = self.tasks_list_1.find_task_by_id(
            task_id=first_task_id)
        self.assertIsNotNone(not_deleted_yet_task)

        actual_response = TaskDAO.delete_task(
            self.first_user.id, self.mentorship_relation_w_second_user.id,
            first_task_id)
        self.assertEqual(expected_response, actual_response)

        deleted_task = self.tasks_list_1.find_task_by_id(task_id=first_task_id)
        self.assertIsNone(deleted_task)
    def test_create_task(self):

        expected_response = messages.TASK_WAS_CREATED_SUCCESSFULLY, 201

        non_existent_task = self.tasks_list_1.find_task_by_id(3)
        self.assertIsNone(non_existent_task)

        actual_response = TaskDAO.create_task(
            user_id=self.first_user.id,
            mentorship_relation_id=self.mentorship_relation_w_second_user.id,
            data=dict(description=self.test_description,
                      is_done=self.test_is_done),
        )
        self.assertEqual(expected_response, actual_response)

        new_task = self.tasks_list_1.find_task_by_id(3)
        self.assertIsNotNone(new_task)
        self.assertEqual(self.test_description, new_task.get("description"))
        self.assertEqual(self.test_is_done, new_task.get("is_done"))
    def delete(cls, request_id, task_id):
        """
        Delete a task.

        Input:
        1. Header: valid access token
        2. Path: ID of the task to be deleted (task_id) and it ID of the associated
        mentorship relation (request_id).
        3. Body: JSON object containing description of task.

        Returns:
        Success or failure message. Task is deleted if request is successful.
        """

        # TODO check if user id is well parsed, if it is an integer

        user_id = get_jwt_identity()

        response = TaskDAO.delete_task(user_id=user_id,
                                       mentorship_relation_id=request_id,
                                       task_id=task_id)

        return response
    def put(cls, request_id, task_id):
        """
        Update a task to mark it as complate

        Input:
        1. Header: valid access token
        2. Path: ID of task (task_id) and ID of the associated mentorship
        relation (request_id). The user must be involved in this relation.
        3. Body:

        Returns:
        Success or failure message. The task is marked as complete if succesful.
        """

        # TODO check if user id is well parsed, if it is an integer

        user_id = get_jwt_identity()

        response = TaskDAO.complete_task(user_id=user_id,
                                         mentorship_relation_id=request_id,
                                         task_id=task_id)

        return response
    def get(cls, request_id):
        """
        List all tasks from a mentorship relation.

        Input:
        1. Header: valid access token
        2. Path: ID of the mentorship relation for which tasks are to be
        displayed(request_id). The user must be involved in this relation.

        Returns:
        JSON array containing task details as objects is displayed on success.
        """

        # TODO check if user id is well parsed, if it is an integer

        user_id = get_jwt_identity()

        response = TaskDAO.list_tasks(user_id=user_id,
                                      mentorship_relation_id=request_id)

        if isinstance(response, tuple):
            return response

        return marshal(response, list_tasks_response_body), HTTPStatus.OK
Beispiel #17
0
    def test_list_tasks_with_non_existent_relation(self):

        expected_response = messages.MENTORSHIP_RELATION_DOES_NOT_EXIST, 404
        actual_response = TaskDAO.list_tasks(self.first_user.id, 123123)

        self.assertEqual(expected_response, actual_response)