@@ -581,20 +581,23 @@ def test_get_remaining_submission_when_submission_made_three_days_back(self):
581
581
'challenge_pk' : self .challenge .pk
582
582
})
583
583
self .submission3 .status = 'cancelled'
584
- self .submission2 .status = 'failed'
585
584
self .submission3 .save ()
585
+ self .submission2 .status = 'failed'
586
586
self .submission2 .save ()
587
+ self .submission1 .submitted_at = timezone .now () - timedelta (days = 3 )
588
+ self .submission1 .save ()
589
+ self .challenge .participant_teams .add (self .participant_team )
590
+ self .challenge .save ()
591
+
592
+ monthly_count = 0 if self .submission1 .submitted_at .month != timezone .now ().month else 1
593
+ remaining_monthly_submissions = self .challenge_phase .max_submissions_per_month - monthly_count
587
594
588
595
expected = {
589
596
'remaining_submissions_today_count' : 10 ,
590
- 'remaining_submissions_this_month_count' : 19 ,
597
+ 'remaining_submissions_this_month_count' : remaining_monthly_submissions ,
591
598
'remaining_submissions' : 99
592
599
}
593
600
594
- self .challenge .participant_teams .add (self .participant_team )
595
- self .challenge .save ()
596
- self .submission1 .submitted_at = timezone .now () - timedelta (days = 3 )
597
- self .submission1 .save ()
598
601
response = self .client .get (self .url , {})
599
602
self .assertEqual (response .data , expected )
600
603
self .assertEqual (response .status_code , status .HTTP_200_OK )
@@ -1278,26 +1281,44 @@ def setUp(self):
1278
1281
method_name = "Test Method" ,
1279
1282
method_description = "Test Description" ,
1280
1283
project_url = "http://testserver/" ,
1281
- publication_url = "http://testserver/"
1284
+ publication_url = "http://testserver/" ,
1285
+ is_public = True
1286
+ )
1287
+
1288
+ self .submission_2 = Submission .objects .create (
1289
+ participant_team = self .participant_team ,
1290
+ challenge_phase = self .challenge_phase ,
1291
+ created_by = self .user1 ,
1292
+ status = "submitted" ,
1293
+ input_file = self .challenge_phase .test_annotation ,
1294
+ method_name = "Test Method" ,
1295
+ method_description = "Test Description" ,
1296
+ project_url = "http://testserver/" ,
1297
+ publication_url = "http://testserver/" ,
1298
+ is_public = False
1282
1299
)
1283
1300
1284
1301
self .private_submission = Submission .objects .create (
1285
1302
participant_team = self .host_participant_team ,
1286
1303
challenge_phase = self .private_challenge_phase ,
1287
- created_by = self .user ,
1304
+ created_by = self .user1 ,
1288
1305
status = "submitted" ,
1289
1306
input_file = self .private_challenge_phase .test_annotation ,
1290
1307
method_name = "Test Method" ,
1291
1308
method_description = "Test Description" ,
1292
1309
project_url = "http://testserver/" ,
1293
- publication_url = "http://testserver/"
1310
+ publication_url = "http://testserver/" ,
1294
1311
)
1295
1312
1296
1313
self .submission .is_public = True
1297
1314
self .submission .status = Submission .FINISHED
1298
1315
self .submission .save ()
1299
1316
1300
- self .private_submission .is_public = True
1317
+ self .submission_2 .is_public = False
1318
+ self .submission_2 .status = Submission .FINISHED
1319
+ self .submission_2 .save ()
1320
+
1321
+ self .private_submission .is_public = False
1301
1322
self .private_submission .status = Submission .FINISHED
1302
1323
self .private_submission .save ()
1303
1324
@@ -1306,6 +1327,11 @@ def setUp(self):
1306
1327
'test-score' : 75.0
1307
1328
}
1308
1329
1330
+ self .result_json_2 = {
1331
+ 'score' : 10.0 ,
1332
+ 'test-score' : 20.0
1333
+ }
1334
+
1309
1335
self .expected_results = [self .result_json ['score' ], self .result_json ['test-score' ]]
1310
1336
self .filtering_score = self .result_json [self .leaderboard .schema ['default_order_by' ]]
1311
1337
@@ -1316,6 +1342,13 @@ def setUp(self):
1316
1342
result = self .result_json
1317
1343
)
1318
1344
1345
+ self .leaderboard_data_2 = LeaderboardData .objects .create (
1346
+ challenge_phase_split = self .challenge_phase_split ,
1347
+ submission = self .submission ,
1348
+ leaderboard = self .leaderboard ,
1349
+ result = self .result_json_2
1350
+ )
1351
+
1319
1352
self .private_leaderboard_data = LeaderboardData .objects .create (
1320
1353
challenge_phase_split = self .private_challenge_phase_split ,
1321
1354
submission = self .private_submission ,
@@ -1414,3 +1447,17 @@ def test_get_leaderboard_for_host_submissions_on_private_challenge_phase(self):
1414
1447
self .assertEqual (response .data ['previous' ], expected ['previous' ])
1415
1448
self .assertEqual (response .data ['results' ], expected ['results' ])
1416
1449
self .assertEqual (response .status_code , status .HTTP_200_OK )
1450
+
1451
+ def test_get_private_leaderboard_when_user_is_participant (self ):
1452
+ self .url = reverse_lazy ('jobs:leaderboard' ,
1453
+ kwargs = {'challenge_phase_split_id' : self .private_challenge_phase_split .id })
1454
+
1455
+ expected = {
1456
+ 'error' : 'Sorry, the leaderboard is not public!'
1457
+ }
1458
+
1459
+ self .client .force_authenticate (user = self .user1 )
1460
+
1461
+ response = self .client .get (self .url , {})
1462
+ self .assertEqual (response .data , expected )
1463
+ self .assertEqual (response .status_code , status .HTTP_400_BAD_REQUEST )
0 commit comments