forked from Cloud-CV/EvalAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend: Fix bug in add_participant_to_challenge API to check if all …
…members of team are in allowed email domain(Cloud-CV#3591) * [BugFix] Verify all members of team have a allowed email domain * Fix tests * Fix tests Co-authored-by: Rishabh Jain <[email protected]>
- Loading branch information
1 parent
c40ccb3
commit ceadf9c
Showing
2 changed files
with
52 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -632,6 +632,13 @@ def setUp(self): | |
verified=True, | ||
) | ||
|
||
EmailAddress.objects.create( | ||
user=self.user2, | ||
email="[email protected]", | ||
primary=True, | ||
verified=True, | ||
) | ||
|
||
self.challenge_host_team2 = ChallengeHostTeam.objects.create( | ||
team_name="Some Test Challenge Host Team", created_by=self.user2 | ||
) | ||
|
@@ -695,6 +702,16 @@ def setUp(self): | |
team=self.participant_team3, | ||
) | ||
|
||
self.participant_team4 = ParticipantTeam.objects.create( | ||
team_name="Some Participant Team 2 by User 2", created_by=self.user2 | ||
) | ||
|
||
self.participant5 = Participant.objects.create( | ||
user=self.user3, | ||
status=Participant.ACCEPTED, | ||
team=self.participant_team4, | ||
) | ||
|
||
def test_registration_is_closed_for_a_particular_challenge(self): | ||
self.challenge2.is_registration_open = False | ||
self.challenge2.save() | ||
|
@@ -781,7 +798,7 @@ def test_particular_participant_team_for_mapping_with_challenge_does_not_exist( | |
"challenges:add_participant_team_to_challenge", | ||
kwargs={ | ||
"challenge_pk": self.challenge.pk, | ||
"participant_team_pk": self.participant_team.pk + 3, | ||
"participant_team_pk": self.participant_team.pk + 4, | ||
}, | ||
) | ||
expected = {"error": "ParticipantTeam does not exist"} | ||
|
@@ -853,7 +870,28 @@ def test_participation_when_participant_is_not_in_allowed_list(self): | |
) | ||
|
||
response = self.client.post(self.url, {}) | ||
message = "Sorry, users with {} email domain(s) are only allowed to participate in this challenge." | ||
message = "Sorry, team consisting of users with non-{} email domain(s) are not allowed \ | ||
to participate in this challenge." | ||
expected = {"error": message.format("example1/example2")} | ||
|
||
self.assertEqual(response.data, expected) | ||
self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE) | ||
|
||
def test_participation_when_participant_team_member_is_not_in_allowed_list(self): | ||
self.client.force_authenticate(user=self.participant_team4.created_by) | ||
self.challenge2.allowed_email_domains.extend(["example1", "example2"]) | ||
self.challenge2.save() | ||
self.url = reverse_lazy( | ||
"challenges:add_participant_team_to_challenge", | ||
kwargs={ | ||
"challenge_pk": self.challenge2.pk, | ||
"participant_team_pk": self.participant_team4.pk, | ||
}, | ||
) | ||
|
||
response = self.client.post(self.url, {}) | ||
message = "Sorry, team consisting of users with non-{} email domain(s) are not allowed \ | ||
to participate in this challenge." | ||
expected = {"error": message.format("example1/example2")} | ||
|
||
self.assertEqual(response.data, expected) | ||
|