コード例 #1
0
    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
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    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)
コード例 #5
0
    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"))