Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
rashikaqureshi committed Aug 6, 2020
2 parents 9e16dec + a3f42bf commit 266c429
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions app/api/dao/mentorship_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,22 @@ def accept_request(user_id: int, request_id: int):

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

# verify if I'm the receiver of the request
if request.action_user_id == user_id:
return messages.CANT_ACCEPT_MENTOR_REQ_SENT_BY_USER, HTTPStatus.BAD_REQUEST
return messages.CANT_ACCEPT_MENTOR_REQ_SENT_BY_USER, 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_ACCEPT_UNINVOLVED_MENTOR_RELATION, HTTPStatus.BAD_REQUEST
return messages.CANT_ACCEPT_UNINVOLVED_MENTOR_RELATION, HTTPStatus.FORBIDDEN

my_requests = user.mentee_relations + user.mentor_relations

# verify if I'm on a current relation
for my_request in my_requests:
if my_request.state == MentorshipRelationState.ACCEPTED:
return messages.USER_IS_INVOLVED_IN_A_MENTORSHIP_RELATION, HTTPStatus.BAD_REQUEST
return messages.USER_IS_INVOLVED_IN_A_MENTORSHIP_RELATION, HTTPStatus.FORBIDDEN

mentee = request.mentee
mentor = request.mentor
Expand Down
2 changes: 1 addition & 1 deletion app/api/dao/task_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def delete_comment(user_id, _id, task_id, relation_id):
return messages.TASK_COMMENT_DOES_NOT_EXIST, HTTPStatus.NOT_FOUND

if task_comment.user_id != user_id:
return messages.TASK_COMMENT_WAS_NOT_CREATED_BY_YOU_DELETE, HTTPStatus.BAD_REQUEST
return messages.TASK_COMMENT_WAS_NOT_CREATED_BY_YOU_DELETE, HTTPStatus.FORBIDDEN

if task_comment.task_id != task_id:
return messages.TASK_COMMENT_WITH_GIVEN_TASK_ID_DOES_NOT_EXIST, HTTPStatus.NOT_FOUND
Expand Down
6 changes: 3 additions & 3 deletions app/api/resources/mentorship_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class AcceptMentorshipRelation(Resource):
HTTPStatus.OK, "%s" % messages.MENTORSHIP_RELATION_WAS_ACCEPTED_SUCCESSFULLY
)
@mentorship_relation_ns.response(
HTTPStatus.BAD_REQUEST,
HTTPStatus.FORBIDDEN,
"%s\n%s\n%s\n%s"
% (
messages.NOT_PENDING_STATE_RELATION,
Expand Down Expand Up @@ -786,12 +786,12 @@ def put(cls, relation_id, task_id, comment_id):
@mentorship_relation_ns.doc(
responses={
HTTPStatus.OK: f"{messages.TASK_COMMENT_WAS_DELETED_SUCCESSFULLY}",
HTTPStatus.BAD_REQUEST: f"{messages.UNACCEPTED_STATE_RELATION}<br>"
f"{messages.TASK_COMMENT_WAS_NOT_CREATED_BY_YOU_DELETE}",
HTTPStatus.BAD_REQUEST: f"{messages.UNACCEPTED_STATE_RELATION}",
HTTPStatus.UNAUTHORIZED: f"{messages.TOKEN_HAS_EXPIRED}<br>"
f"{messages.TOKEN_IS_INVALID}<br>"
f"{messages.AUTHORISATION_TOKEN_IS_MISSING}<br>"
f"{messages.USER_NOT_INVOLVED_IN_THIS_MENTOR_RELATION}",
HTTPStatus.FORBIDDEN: f"{messages.TASK_COMMENT_WAS_NOT_CREATED_BY_YOU_DELETE}",
HTTPStatus.NOT_FOUND: f"{messages.USER_DOES_NOT_EXIST}<br>"
f"{messages.MENTORSHIP_RELATION_DOES_NOT_EXIST}<br>"
f"{messages.TASK_DOES_NOT_EXIST}<br>"
Expand Down
6 changes: 3 additions & 3 deletions tests/mentorship_relation/test_api_accept_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_recepient_already_in_relation_accept_request(self):
"/mentorship_relation/%s/accept" % self.mentorship_relation.id,
headers=get_test_request_header(self.second_user.id),
)
self.assertEqual(400, response.status_code)
self.assertEqual(403, response.status_code)
self.assertEqual(
MentorshipRelationState.ACCEPTED, mentorship_relation_current.state
) # current
Expand All @@ -112,7 +112,7 @@ def test_accept_own_request(self):
"/mentorship_relation/%s/accept" % self.mentorship_relation.id,
headers=get_test_request_header(self.first_user.id),
)
self.assertEqual(400, response.status_code)
self.assertEqual(403, response.status_code)
self.assertEqual(
MentorshipRelationState.PENDING, self.mentorship_relation.state
)
Expand All @@ -134,7 +134,7 @@ def test_accept_request_by_uninvolved_user(self):
"/mentorship_relation/%s/accept" % self.mentorship_relation.id,
headers=get_test_request_header(self.admin_user.id),
)
self.assertEqual(400, response.status_code)
self.assertEqual(403, response.status_code)
self.assertEqual(
MentorshipRelationState.PENDING, self.mentorship_relation.state
)
Expand Down
10 changes: 5 additions & 5 deletions tests/mentorship_relation/test_dao_accept_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_dao_requester_tries_to_accept_mentorship_request(self):

result = DAO.accept_request(self.first_user.id, self.mentorship_relation.id)

self.assertEqual((messages.CANT_ACCEPT_MENTOR_REQ_SENT_BY_USER, 400), result)
self.assertEqual((messages.CANT_ACCEPT_MENTOR_REQ_SENT_BY_USER, 403), result)
self.assertEqual(
MentorshipRelationState.PENDING, self.mentorship_relation.state
)
Expand Down Expand Up @@ -117,28 +117,28 @@ def test_dao_mentorship_request_is_not_in_pending_state(self):
db.session.commit()

result = DAO.accept_request(self.second_user.id, self.mentorship_relation.id)
self.assertEqual((messages.NOT_PENDING_STATE_RELATION, 400), result)
self.assertEqual((messages.NOT_PENDING_STATE_RELATION, 403), result)

self.mentorship_relation.state = MentorshipRelationState.COMPLETED
db.session.add(self.mentorship_relation)
db.session.commit()

result = DAO.accept_request(self.second_user.id, self.mentorship_relation.id)
self.assertEqual((messages.NOT_PENDING_STATE_RELATION, 400), result)
self.assertEqual((messages.NOT_PENDING_STATE_RELATION, 403), result)

self.mentorship_relation.state = MentorshipRelationState.CANCELLED
db.session.add(self.mentorship_relation)
db.session.commit()

result = DAO.accept_request(self.second_user.id, self.mentorship_relation.id)
self.assertEqual((messages.NOT_PENDING_STATE_RELATION, 400), result)
self.assertEqual((messages.NOT_PENDING_STATE_RELATION, 403), result)

self.mentorship_relation.state = MentorshipRelationState.REJECTED
db.session.add(self.mentorship_relation)
db.session.commit()

result = DAO.accept_request(self.second_user.id, self.mentorship_relation.id)
self.assertEqual((messages.NOT_PENDING_STATE_RELATION, 400), result)
self.assertEqual((messages.NOT_PENDING_STATE_RELATION, 403), result)

def test_dao_mentor_user_already_in_relationship(self):
DAO = MentorshipRelationDAO()
Expand Down
2 changes: 1 addition & 1 deletion tests/task_comments/test_api_delete_task_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_task_comment_deletion_api_not_created_by_user(self):
content_type="application/json",
)

self.assertEqual(400, actual_response.status_code)
self.assertEqual(403, actual_response.status_code)
self.assertDictEqual(expected_response, json.loads(actual_response.data))

def test_task_comment_deletion_api_with_relation_not_existing(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/users/test_api_get_other_user.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

from flask import json
from flask_restplus import marshal
from flask_restx import marshal
from http import HTTPStatus

from app.api.models.user import public_user_api_model
Expand Down

0 comments on commit 266c429

Please sign in to comment.