Skip to content

Commit 1549331

Browse files
committed
[Tests] Challenge Prizes
1 parent 9c834f6 commit 1549331

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

tests/unit/challenges/test_views.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
DatasetSplit,
3232
Leaderboard,
3333
StarChallenge,
34+
ChallengePrize,
3435
)
3536
from participants.models import Participant, ParticipantTeam
3637
from hosts.models import ChallengeHost, ChallengeHostTeam
@@ -76,6 +77,7 @@ def setUp(self):
7677
terms_and_conditions="Terms and conditions for test challenge",
7778
submission_guidelines="Submission guidelines for test challenge",
7879
creator=self.challenge_host_team,
80+
has_prizes=False,
7981
published=False,
8082
is_registration_open=True,
8183
enable_forum=True,
@@ -155,6 +157,7 @@ def test_get_challenge(self):
155157
"created_by": self.challenge.creator.created_by.username,
156158
"team_url": self.challenge.creator.team_url,
157159
},
160+
"has_prizes": self.challenge.has_prizes,
158161
"published": self.challenge.published,
159162
"submission_time_limit": self.challenge.submission_time_limit,
160163
"is_registration_open": self.challenge.is_registration_open,
@@ -313,6 +316,7 @@ def test_get_particular_challenge(self):
313316
"created_by": self.challenge.creator.created_by.username,
314317
"team_url": self.challenge.creator.team_url,
315318
},
319+
"has_prizes": self.challenge.has_prizes,
316320
"published": self.challenge.published,
317321
"submission_time_limit": self.challenge.submission_time_limit,
318322
"is_registration_open": self.challenge.is_registration_open,
@@ -396,6 +400,7 @@ def test_update_challenge_when_user_is_its_creator(self):
396400
"created_by": self.challenge.creator.created_by.username,
397401
"team_url": self.challenge.creator.team_url,
398402
},
403+
"has_prizes": self.challenge.has_prizes,
399404
"published": self.challenge.published,
400405
"submission_time_limit": self.challenge.submission_time_limit,
401406
"is_registration_open": self.challenge.is_registration_open,
@@ -500,6 +505,7 @@ def test_particular_challenge_partial_update(self):
500505
"created_by": self.challenge.creator.created_by.username,
501506
"team_url": self.challenge.creator.team_url,
502507
},
508+
"has_prizes": self.challenge.has_prizes,
503509
"published": self.challenge.published,
504510
"submission_time_limit": self.challenge.submission_time_limit,
505511
"is_registration_open": self.challenge.is_registration_open,
@@ -560,6 +566,7 @@ def test_particular_challenge_update(self):
560566
"created_by": self.challenge.creator.created_by.username,
561567
"team_url": self.challenge.creator.team_url,
562568
},
569+
"has_prizes": self.challenge.has_prizes,
563570
"published": self.challenge.published,
564571
"submission_time_limit": self.challenge.submission_time_limit,
565572
"is_registration_open": self.challenge.is_registration_open,
@@ -1136,6 +1143,7 @@ def test_get_past_challenges(self):
11361143
"created_by": self.challenge3.creator.created_by.username,
11371144
"team_url": self.challenge3.creator.team_url,
11381145
},
1146+
"has_prizes": self.challenge3.has_prizes,
11391147
"published": self.challenge3.published,
11401148
"submission_time_limit": self.challenge3.submission_time_limit,
11411149
"is_registration_open": self.challenge3.is_registration_open,
@@ -1202,6 +1210,7 @@ def test_get_present_challenges(self):
12021210
"created_by": self.challenge2.creator.created_by.username,
12031211
"team_url": self.challenge2.creator.team_url,
12041212
},
1213+
"has_prizes": self.challenge2.has_prizes,
12051214
"published": self.challenge2.published,
12061215
"submission_time_limit": self.challenge2.submission_time_limit,
12071216
"is_registration_open": self.challenge2.is_registration_open,
@@ -1268,6 +1277,7 @@ def test_get_future_challenges(self):
12681277
"created_by": self.challenge4.creator.created_by.username,
12691278
"team_url": self.challenge4.creator.team_url,
12701279
},
1280+
"has_prizes": self.challenge4.has_prizes,
12711281
"published": self.challenge4.published,
12721282
"submission_time_limit": self.challenge4.submission_time_limit,
12731283
"is_registration_open": self.challenge4.is_registration_open,
@@ -1334,6 +1344,7 @@ def test_get_all_challenges(self):
13341344
"created_by": self.challenge4.creator.created_by.username,
13351345
"team_url": self.challenge4.creator.team_url,
13361346
},
1347+
"has_prizes": self.challenge4.has_prizes,
13371348
"published": self.challenge4.published,
13381349
"submission_time_limit": self.challenge4.submission_time_limit,
13391350
"is_registration_open": self.challenge4.is_registration_open,
@@ -1384,6 +1395,7 @@ def test_get_all_challenges(self):
13841395
"created_by": self.challenge3.creator.created_by.username,
13851396
"team_url": self.challenge3.creator.team_url,
13861397
},
1398+
"has_prizes": self.challenge3.has_prizes,
13871399
"published": self.challenge3.published,
13881400
"submission_time_limit": self.challenge3.submission_time_limit,
13891401
"is_registration_open": self.challenge3.is_registration_open,
@@ -1434,6 +1446,7 @@ def test_get_all_challenges(self):
14341446
"created_by": self.challenge2.creator.created_by.username,
14351447
"team_url": self.challenge2.creator.team_url,
14361448
},
1449+
"has_prizes": self.challenge2.has_prizes,
14371450
"published": self.challenge2.published,
14381451
"submission_time_limit": self.challenge2.submission_time_limit,
14391452
"is_registration_open": self.challenge2.is_registration_open,
@@ -1549,6 +1562,7 @@ def test_get_featured_challenges(self):
15491562
"created_by": self.challenge3.creator.created_by.username,
15501563
"team_url": self.challenge3.creator.team_url,
15511564
},
1565+
"has_prizes": self.challenge3.has_prizes,
15521566
"published": self.challenge3.published,
15531567
"submission_time_limit": self.challenge3.submission_time_limit,
15541568
"is_registration_open": self.challenge3.is_registration_open,
@@ -1687,6 +1701,7 @@ def test_get_challenge_by_pk_when_user_is_challenge_host(self):
16871701
"created_by": self.challenge3.creator.created_by.username,
16881702
"team_url": self.challenge3.creator.team_url,
16891703
},
1704+
"has_prizes": self.challenge3.has_prizes,
16901705
"published": self.challenge3.published,
16911706
"submission_time_limit": self.challenge3.submission_time_limit,
16921707
"is_registration_open": self.challenge3.is_registration_open,
@@ -1761,6 +1776,7 @@ def test_get_challenge_by_pk_when_user_is_participant(self):
17611776
"created_by": self.challenge4.creator.created_by.username,
17621777
"team_url": self.challenge4.creator.team_url,
17631778
},
1779+
"has_prizes": self.challenge4.has_prizes,
17641780
"published": self.challenge4.published,
17651781
"submission_time_limit": self.challenge4.submission_time_limit,
17661782
"is_registration_open": self.challenge4.is_registration_open,
@@ -1891,6 +1907,7 @@ def test_get_challenge_when_host_team_is_given(self):
18911907
"created_by": self.challenge2.creator.created_by.username,
18921908
"team_url": self.challenge2.creator.team_url,
18931909
},
1910+
"has_prizes": self.challenge2.has_prizes,
18941911
"published": self.challenge2.published,
18951912
"submission_time_limit": self.challenge2.submission_time_limit,
18961913
"is_registration_open": self.challenge2.is_registration_open,
@@ -1953,6 +1970,7 @@ def test_get_challenge_when_participant_team_is_given(self):
19531970
"created_by": self.challenge2.creator.created_by.username,
19541971
"team_url": self.challenge2.creator.team_url,
19551972
},
1973+
"has_prizes": self.challenge2.has_prizes,
19561974
"published": self.challenge2.published,
19571975
"submission_time_limit": self.challenge2.submission_time_limit,
19581976
"is_registration_open": self.challenge2.is_registration_open,
@@ -2015,6 +2033,7 @@ def test_get_challenge_when_mode_is_participant(self):
20152033
"created_by": self.challenge2.creator.created_by.username,
20162034
"team_url": self.challenge2.creator.team_url,
20172035
},
2036+
"has_prizes": self.challenge2.has_prizes,
20182037
"published": self.challenge2.published,
20192038
"submission_time_limit": self.challenge2.submission_time_limit,
20202039
"is_registration_open": self.challenge2.is_registration_open,
@@ -2075,6 +2094,7 @@ def test_get_challenge_when_mode_is_host(self):
20752094
"created_by": self.challenge.creator.created_by.username,
20762095
"team_url": self.challenge.creator.team_url,
20772096
},
2097+
"has_prizes": self.challenge.has_prizes,
20782098
"published": self.challenge.published,
20792099
"submission_time_limit": self.challenge.submission_time_limit,
20802100
"is_registration_open": self.challenge.is_registration_open,
@@ -2125,6 +2145,7 @@ def test_get_challenge_when_mode_is_host(self):
21252145
"created_by": self.challenge2.creator.created_by.username,
21262146
"team_url": self.challenge2.creator.team_url,
21272147
},
2148+
"has_prizes": self.challenge2.has_prizes,
21282149
"published": self.challenge2.published,
21292150
"submission_time_limit": self.challenge2.submission_time_limit,
21302151
"is_registration_open": self.challenge2.is_registration_open,
@@ -2186,6 +2207,66 @@ def test_get_challenge_with_incorrect_url_pattern_with_all_values(self):
21862207
self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE)
21872208

21882209

2210+
class ChallengePrizesTest(BaseAPITestClass):
2211+
2212+
def setUp(self):
2213+
super().setUp()
2214+
self.challenge = Challenge.objects.create(
2215+
title="Test Challenge",
2216+
short_description="Short description for test challenge",
2217+
description="Description for test challenge",
2218+
terms_and_conditions="Terms and conditions for test challenge",
2219+
submission_guidelines="Submission guidelines for test challenge",
2220+
creator=self.challenge_host_team,
2221+
published=True,
2222+
is_registration_open=True,
2223+
enable_forum=True,
2224+
approved_by_admin=True,
2225+
anonymous_leaderboard=False,
2226+
start_date=timezone.now() - timedelta(days=2),
2227+
end_date=timezone.now() + timedelta(days=1),
2228+
)
2229+
2230+
def test_challenge_has_prizes_false(self):
2231+
self.url = reverse_lazy(
2232+
"challenges:get_challenge_by_pk",
2233+
kwargs={"pk": self.challenge.pk + 10},
2234+
)
2235+
2236+
self.challenge.has_prizes = False
2237+
self.challenge.save()
2238+
response = self.client.get(self.url, {})
2239+
self.assertEqual(response.status_code, status.HTTP_200_OK)
2240+
self.assertFalse(response.data["has_prizes"])
2241+
2242+
def test_challenge_has_prizes_true(self):
2243+
self.url = reverse_lazy(
2244+
"challenges:get_prizes_by_challenge",
2245+
kwargs={"challenge_pk": self.challenge.pk},
2246+
)
2247+
2248+
self.challenge.has_prizes = True
2249+
self.challenge.save()
2250+
prize = ChallengePrize.objects.create(
2251+
challenge=self.challenge,
2252+
amount="100USD",
2253+
rank=1,
2254+
)
2255+
prize1 = ChallengePrize.objects.create(
2256+
challenge=self.challenge,
2257+
amount="500USD",
2258+
rank=2,
2259+
)
2260+
response = self.client.get(self.url, format="json")
2261+
self.assertEqual(response.status_code, status.HTTP_200_OK)
2262+
self.assertEqual(response.data[0]["id"], prize.challenge.pk)
2263+
self.assertEqual(response.data[0]["amount"], prize.amount)
2264+
self.assertEqual(response.data[0]["rank"], prize.rank)
2265+
self.assertEqual(response.data[1]["id"], prize1.challenge.pk)
2266+
self.assertEqual(response.data[1]["amount"], prize1.amount)
2267+
self.assertEqual(response.data[1]["rank"], prize1.rank)
2268+
2269+
21892270
class BaseChallengePhaseClass(BaseAPITestClass):
21902271
def setUp(self):
21912272
super(BaseChallengePhaseClass, self).setUp()

tests/unit/participants/test_views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ def test_get_teams_and_corresponding_challenges_for_a_participant(self):
836836
"created_by": self.challenge_host_team.created_by.username,
837837
"team_url": self.challenge_host_team.team_url,
838838
},
839+
"has_prizes": self.challenge1.has_prizes,
839840
"published": self.challenge1.published,
840841
"submission_time_limit": self.challenge1.submission_time_limit,
841842
"is_registration_open": self.challenge1.is_registration_open,
@@ -913,6 +914,7 @@ def test_get_participant_team_challenge_list(self):
913914
"created_by": self.challenge_host_team.created_by.username,
914915
"team_url": self.challenge_host_team.team_url,
915916
},
917+
"has_prizes": self.challenge1.has_prizes,
916918
"published": self.challenge1.published,
917919
"submission_time_limit": self.challenge1.submission_time_limit,
918920
"is_registration_open": self.challenge1.is_registration_open,

0 commit comments

Comments
 (0)