@@ -282,25 +282,27 @@ pub fn download_or_update_course_exercises(
282282 . into_iter ( )
283283 . max_by_key ( |s| s. created_at )
284284 {
285- // previous submission found
286- to_be_downloaded. push ( DownloadTarget {
287- target : ExerciseDownload {
288- id : exercise_detail. id ,
289- course_slug : exercise_detail. course_name ,
290- exercise_slug : exercise_detail. exercise_name ,
291- path : target,
292- } ,
293- checksum : exercise_detail. checksum ,
294- kind : DownloadTargetKind :: Submission {
295- submission_id : latest_submission. id ,
296- } ,
297- } ) ;
298- continue ;
285+ // previous submission found, check if exercise submission results hidden (part of exam)
286+ if !exercise_detail. hide_submission_results {
287+ to_be_downloaded. push ( DownloadTarget {
288+ target : ExerciseDownload {
289+ id : exercise_detail. id ,
290+ course_slug : exercise_detail. course_name ,
291+ exercise_slug : exercise_detail. exercise_name ,
292+ path : target,
293+ } ,
294+ checksum : exercise_detail. checksum ,
295+ kind : DownloadTargetKind :: Submission {
296+ submission_id : latest_submission. id ,
297+ } ,
298+ } ) ;
299+ continue ;
300+ }
299301 }
300302 }
301303 }
302304
303- // not skipped, either not on disk or no previous submissions, downloading template
305+ // not skipped, either not on disk or no previous submissions or submission result hidden , downloading template
304306 to_be_downloaded. push ( DownloadTarget {
305307 target : ExerciseDownload {
306308 id : exercise_detail. id ,
@@ -1052,12 +1054,14 @@ mod test {
10521054 course_name: "some course" . to_string( ) ,
10531055 exercise_name: "some exercise" . to_string( ) ,
10541056 checksum: "new checksum" . to_string( ) ,
1057+ hide_submission_results: false ,
10551058 } ,
10561059 ExercisesDetails {
10571060 id: 2 ,
10581061 course_name: "some course" . to_string( ) ,
10591062 exercise_name: "another exercise" . to_string( ) ,
10601063 checksum: "old checksum" . to_string( ) ,
1064+ hide_submission_results: false ,
10611065 } ,
10621066 ] ;
10631067 let mut response = HashMap :: new ( ) ;
@@ -1157,24 +1161,37 @@ checksum = 'new checksum'
11571161 checksum: "new checksum" . to_string( ) ,
11581162 course_name: "some course" . to_string( ) ,
11591163 exercise_name: "on disk exercise with update and submission" . to_string( ) ,
1164+ hide_submission_results: false ,
11601165 } ,
11611166 ExercisesDetails {
11621167 id: 2 ,
11631168 checksum: "new checksum" . to_string( ) ,
11641169 course_name: "some course" . to_string( ) ,
11651170 exercise_name: "on disk exercise without update" . to_string( ) ,
1171+ hide_submission_results: false ,
11661172 } ,
11671173 ExercisesDetails {
11681174 id: 3 ,
11691175 checksum: "new checksum" . to_string( ) ,
11701176 course_name: "another course" . to_string( ) ,
11711177 exercise_name: "not on disk exercise with submission" . to_string( ) ,
1178+ hide_submission_results: false ,
11721179 } ,
11731180 ExercisesDetails {
11741181 id: 4 ,
11751182 checksum: "new checksum" . to_string( ) ,
11761183 course_name: "another course" . to_string( ) ,
11771184 exercise_name: "not on disk exercise without submission" . to_string( ) ,
1185+ hide_submission_results: false ,
1186+ } ,
1187+ ExercisesDetails {
1188+ id: 5 ,
1189+ checksum: "new checksum" . to_string( ) ,
1190+ course_name: "another course" . to_string( ) ,
1191+ exercise_name:
1192+ "not on disk exercise with submission exercise hide submission result"
1193+ . to_string( ) ,
1194+ hide_submission_results: true ,
11781195 } ,
11791196 ] ,
11801197 ) ;
@@ -1252,6 +1269,16 @@ checksum = 'new checksum'
12521269 . with_body ( serde_json:: to_string ( & [ 0 ; 0 ] ) . unwrap ( ) )
12531270 . create ( ) ;
12541271
1272+ let _m = mockito:: mock (
1273+ "GET" ,
1274+ mockito:: Matcher :: AllOf ( vec ! [
1275+ mockito:: Matcher :: Regex ( "exercises/5" . to_string( ) ) ,
1276+ mockito:: Matcher :: Regex ( "submissions" . to_string( ) ) ,
1277+ ] ) ,
1278+ )
1279+ . with_body ( serde_json:: to_string ( & sub_body) . unwrap ( ) )
1280+ . create ( ) ;
1281+
12551282 let mut template_zw = zip:: ZipWriter :: new ( std:: io:: Cursor :: new ( vec ! [ ] ) ) ;
12561283 template_zw
12571284 . start_file ( "src/student_file.py" , zip:: write:: FileOptions :: default ( ) )
@@ -1310,6 +1337,15 @@ checksum = 'new checksum'
13101337 )
13111338 . with_body ( & template_z)
13121339 . create ( ) ;
1340+ let _m = mockito:: mock (
1341+ "GET" ,
1342+ mockito:: Matcher :: AllOf ( vec ! [
1343+ mockito:: Matcher :: Regex ( "exercises/5" . to_string( ) ) ,
1344+ mockito:: Matcher :: Regex ( "download" . to_string( ) ) ,
1345+ ] ) ,
1346+ )
1347+ . with_body ( & template_z)
1348+ . create ( ) ;
13131349
13141350 let mut sub_zw = zip:: ZipWriter :: new ( std:: io:: Cursor :: new ( vec ! [ ] ) ) ;
13151351 sub_zw
@@ -1354,13 +1390,14 @@ checksum = 'new checksum'
13541390 other => panic ! ( "{:?}" , other) ,
13551391 } ;
13561392
1357- assert_eq ! ( downloaded. len( ) , 3 ) ;
1393+ assert_eq ! ( downloaded. len( ) , 4 ) ;
13581394 assert_eq ! ( skipped. len( ) , 1 ) ;
13591395
13601396 let e1 = downloaded. iter ( ) . find ( |e| e. id == 1 ) . unwrap ( ) ;
13611397 let _e2 = skipped. iter ( ) . find ( |e| e. id == 2 ) . unwrap ( ) ;
13621398 let e3 = downloaded. iter ( ) . find ( |e| e. id == 3 ) . unwrap ( ) ;
13631399 let e4 = downloaded. iter ( ) . find ( |e| e. id == 4 ) . unwrap ( ) ;
1400+ let e5 = downloaded. iter ( ) . find ( |e| e. id == 5 ) . unwrap ( ) ;
13641401
13651402 // did not download submission even though it was available because it was on disk
13661403 let f = file_util:: read_file_to_string ( e1. path . join ( "src/student_file.py" ) ) . unwrap ( ) ;
@@ -1383,9 +1420,16 @@ checksum = 'new checksum'
13831420 // did not download submission because one was not available
13841421 let f = file_util:: read_file_to_string ( e4. path . join ( "src/student_file.py" ) ) . unwrap ( ) ;
13851422 assert_eq ! ( f, "template" ) ;
1386- assert ! ( e1 . path. join( "src/template_only_student_file.py" ) . exists( ) ) ;
1423+ assert ! ( e4 . path. join( "src/template_only_student_file.py" ) . exists( ) ) ;
13871424 let f = file_util:: read_file_to_string ( e4. path . join ( "test/exercise_file.py" ) ) . unwrap ( ) ;
13881425 assert_eq ! ( f, "template" ) ;
1426+
1427+ // did not download submission because exercise hides submission results, for example exam exercise
1428+ let f = file_util:: read_file_to_string ( e5. path . join ( "src/student_file.py" ) ) . unwrap ( ) ;
1429+ assert_eq ! ( f, "template" ) ;
1430+ assert ! ( e5. path. join( "src/template_only_student_file.py" ) . exists( ) ) ;
1431+ let f = file_util:: read_file_to_string ( e5. path . join ( "test/exercise_file.py" ) ) . unwrap ( ) ;
1432+ assert_eq ! ( f, "template" ) ;
13891433 }
13901434
13911435 #[ test]
0 commit comments