Skip to content

Commit

Permalink
fix: refactor HTTP error codes PUT /mentorship_relation/{request_id}/…
Browse files Browse the repository at this point in the history
…cancel (#991)
  • Loading branch information
vj-codes authored May 16, 2021
1 parent bab703c commit 23f28d8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/api/dao/mentorship_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ def cancel_relation(user_id: int, relation_id: int):

# verify if request is in pending state
if request.state != MentorshipRelationState.ACCEPTED:
return messages.UNACCEPTED_STATE_RELATION, HTTPStatus.BAD_REQUEST
return messages.UNACCEPTED_STATE_RELATION, HTTPStatus.FORBIDDEN

# verify if I'm involved in this relation
if not (request.mentee_id == user_id or request.mentor_id == user_id):
return messages.CANT_CANCEL_UNINVOLVED_REQUEST, HTTPStatus.BAD_REQUEST
return messages.CANT_CANCEL_UNINVOLVED_REQUEST, HTTPStatus.FORBIDDEN

# All was checked
request.state = MentorshipRelationState.CANCELLED
Expand Down
2 changes: 1 addition & 1 deletion app/api/resources/mentorship_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class CancelMentorshipRelation(Resource):
HTTPStatus.OK, f"{messages.MENTORSHIP_RELATION_WAS_CANCELLED_SUCCESSFULLY}"
)
@mentorship_relation_ns.response(
HTTPStatus.BAD_REQUEST,
HTTPStatus.FORBIDDEN,
f"{messages.UNACCEPTED_STATE_RELATION}\n"
f"{messages.CANT_CANCEL_UNINVOLVED_REQUEST}",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_api_cancel_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_cancel_mentorship_relation_notinvolvedinrelation(self):
headers=get_test_request_header(self.admin_user.id),
)

self.assertEqual(HTTPStatus.BAD_REQUEST, response.status_code)
self.assertEqual(HTTPStatus.FORBIDDEN, response.status_code)
self.assertDictEqual(expected_response, json.loads(response.data))


Expand Down
8 changes: 4 additions & 4 deletions tests/mentorship_relation/test_dao_cancel_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_dao_mentorship_cancel_relation_not_in_accepted_state(self):

result = DAO.cancel_relation(self.second_user.id, self.mentorship_relation.id)
self.assertEqual(
(messages.UNACCEPTED_STATE_RELATION, HTTPStatus.BAD_REQUEST), result
(messages.UNACCEPTED_STATE_RELATION, HTTPStatus.FORBIDDEN), result
)

self.mentorship_relation.state = MentorshipRelationState.COMPLETED
Expand All @@ -114,7 +114,7 @@ def test_dao_mentorship_cancel_relation_not_in_accepted_state(self):

result = DAO.cancel_relation(self.second_user.id, self.mentorship_relation.id)
self.assertEqual(
(messages.UNACCEPTED_STATE_RELATION, HTTPStatus.BAD_REQUEST), result
(messages.UNACCEPTED_STATE_RELATION, HTTPStatus.FORBIDDEN), result
)

self.mentorship_relation.state = MentorshipRelationState.CANCELLED
Expand All @@ -123,7 +123,7 @@ def test_dao_mentorship_cancel_relation_not_in_accepted_state(self):

result = DAO.cancel_relation(self.second_user.id, self.mentorship_relation.id)
self.assertEqual(
(messages.UNACCEPTED_STATE_RELATION, HTTPStatus.BAD_REQUEST), result
(messages.UNACCEPTED_STATE_RELATION, HTTPStatus.FORBIDDEN), result
)

self.mentorship_relation.state = MentorshipRelationState.REJECTED
Expand All @@ -132,5 +132,5 @@ def test_dao_mentorship_cancel_relation_not_in_accepted_state(self):

result = DAO.cancel_relation(self.second_user.id, self.mentorship_relation.id)
self.assertEqual(
(messages.UNACCEPTED_STATE_RELATION, HTTPStatus.BAD_REQUEST), result
(messages.UNACCEPTED_STATE_RELATION, HTTPStatus.FORBIDDEN), result
)

0 comments on commit 23f28d8

Please sign in to comment.