|
31 | 31 | DatasetSplit, |
32 | 32 | Leaderboard, |
33 | 33 | StarChallenge, |
| 34 | + ChallengePrize, |
34 | 35 | ) |
35 | 36 | from participants.models import Participant, ParticipantTeam |
36 | 37 | from hosts.models import ChallengeHost, ChallengeHostTeam |
@@ -76,6 +77,7 @@ def setUp(self): |
76 | 77 | terms_and_conditions="Terms and conditions for test challenge", |
77 | 78 | submission_guidelines="Submission guidelines for test challenge", |
78 | 79 | creator=self.challenge_host_team, |
| 80 | + has_prizes=False, |
79 | 81 | published=False, |
80 | 82 | is_registration_open=True, |
81 | 83 | enable_forum=True, |
@@ -155,6 +157,7 @@ def test_get_challenge(self): |
155 | 157 | "created_by": self.challenge.creator.created_by.username, |
156 | 158 | "team_url": self.challenge.creator.team_url, |
157 | 159 | }, |
| 160 | + "has_prizes": self.challenge.has_prizes, |
158 | 161 | "published": self.challenge.published, |
159 | 162 | "submission_time_limit": self.challenge.submission_time_limit, |
160 | 163 | "is_registration_open": self.challenge.is_registration_open, |
@@ -313,6 +316,7 @@ def test_get_particular_challenge(self): |
313 | 316 | "created_by": self.challenge.creator.created_by.username, |
314 | 317 | "team_url": self.challenge.creator.team_url, |
315 | 318 | }, |
| 319 | + "has_prizes": self.challenge.has_prizes, |
316 | 320 | "published": self.challenge.published, |
317 | 321 | "submission_time_limit": self.challenge.submission_time_limit, |
318 | 322 | "is_registration_open": self.challenge.is_registration_open, |
@@ -396,6 +400,7 @@ def test_update_challenge_when_user_is_its_creator(self): |
396 | 400 | "created_by": self.challenge.creator.created_by.username, |
397 | 401 | "team_url": self.challenge.creator.team_url, |
398 | 402 | }, |
| 403 | + "has_prizes": self.challenge.has_prizes, |
399 | 404 | "published": self.challenge.published, |
400 | 405 | "submission_time_limit": self.challenge.submission_time_limit, |
401 | 406 | "is_registration_open": self.challenge.is_registration_open, |
@@ -500,6 +505,7 @@ def test_particular_challenge_partial_update(self): |
500 | 505 | "created_by": self.challenge.creator.created_by.username, |
501 | 506 | "team_url": self.challenge.creator.team_url, |
502 | 507 | }, |
| 508 | + "has_prizes": self.challenge.has_prizes, |
503 | 509 | "published": self.challenge.published, |
504 | 510 | "submission_time_limit": self.challenge.submission_time_limit, |
505 | 511 | "is_registration_open": self.challenge.is_registration_open, |
@@ -560,6 +566,7 @@ def test_particular_challenge_update(self): |
560 | 566 | "created_by": self.challenge.creator.created_by.username, |
561 | 567 | "team_url": self.challenge.creator.team_url, |
562 | 568 | }, |
| 569 | + "has_prizes": self.challenge.has_prizes, |
563 | 570 | "published": self.challenge.published, |
564 | 571 | "submission_time_limit": self.challenge.submission_time_limit, |
565 | 572 | "is_registration_open": self.challenge.is_registration_open, |
@@ -1136,6 +1143,7 @@ def test_get_past_challenges(self): |
1136 | 1143 | "created_by": self.challenge3.creator.created_by.username, |
1137 | 1144 | "team_url": self.challenge3.creator.team_url, |
1138 | 1145 | }, |
| 1146 | + "has_prizes": self.challenge3.has_prizes, |
1139 | 1147 | "published": self.challenge3.published, |
1140 | 1148 | "submission_time_limit": self.challenge3.submission_time_limit, |
1141 | 1149 | "is_registration_open": self.challenge3.is_registration_open, |
@@ -1202,6 +1210,7 @@ def test_get_present_challenges(self): |
1202 | 1210 | "created_by": self.challenge2.creator.created_by.username, |
1203 | 1211 | "team_url": self.challenge2.creator.team_url, |
1204 | 1212 | }, |
| 1213 | + "has_prizes": self.challenge2.has_prizes, |
1205 | 1214 | "published": self.challenge2.published, |
1206 | 1215 | "submission_time_limit": self.challenge2.submission_time_limit, |
1207 | 1216 | "is_registration_open": self.challenge2.is_registration_open, |
@@ -1268,6 +1277,7 @@ def test_get_future_challenges(self): |
1268 | 1277 | "created_by": self.challenge4.creator.created_by.username, |
1269 | 1278 | "team_url": self.challenge4.creator.team_url, |
1270 | 1279 | }, |
| 1280 | + "has_prizes": self.challenge4.has_prizes, |
1271 | 1281 | "published": self.challenge4.published, |
1272 | 1282 | "submission_time_limit": self.challenge4.submission_time_limit, |
1273 | 1283 | "is_registration_open": self.challenge4.is_registration_open, |
@@ -1334,6 +1344,7 @@ def test_get_all_challenges(self): |
1334 | 1344 | "created_by": self.challenge4.creator.created_by.username, |
1335 | 1345 | "team_url": self.challenge4.creator.team_url, |
1336 | 1346 | }, |
| 1347 | + "has_prizes": self.challenge4.has_prizes, |
1337 | 1348 | "published": self.challenge4.published, |
1338 | 1349 | "submission_time_limit": self.challenge4.submission_time_limit, |
1339 | 1350 | "is_registration_open": self.challenge4.is_registration_open, |
@@ -1384,6 +1395,7 @@ def test_get_all_challenges(self): |
1384 | 1395 | "created_by": self.challenge3.creator.created_by.username, |
1385 | 1396 | "team_url": self.challenge3.creator.team_url, |
1386 | 1397 | }, |
| 1398 | + "has_prizes": self.challenge3.has_prizes, |
1387 | 1399 | "published": self.challenge3.published, |
1388 | 1400 | "submission_time_limit": self.challenge3.submission_time_limit, |
1389 | 1401 | "is_registration_open": self.challenge3.is_registration_open, |
@@ -1434,6 +1446,7 @@ def test_get_all_challenges(self): |
1434 | 1446 | "created_by": self.challenge2.creator.created_by.username, |
1435 | 1447 | "team_url": self.challenge2.creator.team_url, |
1436 | 1448 | }, |
| 1449 | + "has_prizes": self.challenge2.has_prizes, |
1437 | 1450 | "published": self.challenge2.published, |
1438 | 1451 | "submission_time_limit": self.challenge2.submission_time_limit, |
1439 | 1452 | "is_registration_open": self.challenge2.is_registration_open, |
@@ -1549,6 +1562,7 @@ def test_get_featured_challenges(self): |
1549 | 1562 | "created_by": self.challenge3.creator.created_by.username, |
1550 | 1563 | "team_url": self.challenge3.creator.team_url, |
1551 | 1564 | }, |
| 1565 | + "has_prizes": self.challenge3.has_prizes, |
1552 | 1566 | "published": self.challenge3.published, |
1553 | 1567 | "submission_time_limit": self.challenge3.submission_time_limit, |
1554 | 1568 | "is_registration_open": self.challenge3.is_registration_open, |
@@ -1687,6 +1701,7 @@ def test_get_challenge_by_pk_when_user_is_challenge_host(self): |
1687 | 1701 | "created_by": self.challenge3.creator.created_by.username, |
1688 | 1702 | "team_url": self.challenge3.creator.team_url, |
1689 | 1703 | }, |
| 1704 | + "has_prizes": self.challenge3.has_prizes, |
1690 | 1705 | "published": self.challenge3.published, |
1691 | 1706 | "submission_time_limit": self.challenge3.submission_time_limit, |
1692 | 1707 | "is_registration_open": self.challenge3.is_registration_open, |
@@ -1761,6 +1776,7 @@ def test_get_challenge_by_pk_when_user_is_participant(self): |
1761 | 1776 | "created_by": self.challenge4.creator.created_by.username, |
1762 | 1777 | "team_url": self.challenge4.creator.team_url, |
1763 | 1778 | }, |
| 1779 | + "has_prizes": self.challenge4.has_prizes, |
1764 | 1780 | "published": self.challenge4.published, |
1765 | 1781 | "submission_time_limit": self.challenge4.submission_time_limit, |
1766 | 1782 | "is_registration_open": self.challenge4.is_registration_open, |
@@ -1891,6 +1907,7 @@ def test_get_challenge_when_host_team_is_given(self): |
1891 | 1907 | "created_by": self.challenge2.creator.created_by.username, |
1892 | 1908 | "team_url": self.challenge2.creator.team_url, |
1893 | 1909 | }, |
| 1910 | + "has_prizes": self.challenge2.has_prizes, |
1894 | 1911 | "published": self.challenge2.published, |
1895 | 1912 | "submission_time_limit": self.challenge2.submission_time_limit, |
1896 | 1913 | "is_registration_open": self.challenge2.is_registration_open, |
@@ -1953,6 +1970,7 @@ def test_get_challenge_when_participant_team_is_given(self): |
1953 | 1970 | "created_by": self.challenge2.creator.created_by.username, |
1954 | 1971 | "team_url": self.challenge2.creator.team_url, |
1955 | 1972 | }, |
| 1973 | + "has_prizes": self.challenge2.has_prizes, |
1956 | 1974 | "published": self.challenge2.published, |
1957 | 1975 | "submission_time_limit": self.challenge2.submission_time_limit, |
1958 | 1976 | "is_registration_open": self.challenge2.is_registration_open, |
@@ -2015,6 +2033,7 @@ def test_get_challenge_when_mode_is_participant(self): |
2015 | 2033 | "created_by": self.challenge2.creator.created_by.username, |
2016 | 2034 | "team_url": self.challenge2.creator.team_url, |
2017 | 2035 | }, |
| 2036 | + "has_prizes": self.challenge2.has_prizes, |
2018 | 2037 | "published": self.challenge2.published, |
2019 | 2038 | "submission_time_limit": self.challenge2.submission_time_limit, |
2020 | 2039 | "is_registration_open": self.challenge2.is_registration_open, |
@@ -2075,6 +2094,7 @@ def test_get_challenge_when_mode_is_host(self): |
2075 | 2094 | "created_by": self.challenge.creator.created_by.username, |
2076 | 2095 | "team_url": self.challenge.creator.team_url, |
2077 | 2096 | }, |
| 2097 | + "has_prizes": self.challenge.has_prizes, |
2078 | 2098 | "published": self.challenge.published, |
2079 | 2099 | "submission_time_limit": self.challenge.submission_time_limit, |
2080 | 2100 | "is_registration_open": self.challenge.is_registration_open, |
@@ -2125,6 +2145,7 @@ def test_get_challenge_when_mode_is_host(self): |
2125 | 2145 | "created_by": self.challenge2.creator.created_by.username, |
2126 | 2146 | "team_url": self.challenge2.creator.team_url, |
2127 | 2147 | }, |
| 2148 | + "has_prizes": self.challenge2.has_prizes, |
2128 | 2149 | "published": self.challenge2.published, |
2129 | 2150 | "submission_time_limit": self.challenge2.submission_time_limit, |
2130 | 2151 | "is_registration_open": self.challenge2.is_registration_open, |
@@ -2186,6 +2207,66 @@ def test_get_challenge_with_incorrect_url_pattern_with_all_values(self): |
2186 | 2207 | self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE) |
2187 | 2208 |
|
2188 | 2209 |
|
| 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 | + |
2189 | 2270 | class BaseChallengePhaseClass(BaseAPITestClass): |
2190 | 2271 | def setUp(self): |
2191 | 2272 | super(BaseChallengePhaseClass, self).setUp() |
|
0 commit comments