Skip to content

Commit a7ae93c

Browse files
committed
Write test for fallback if hide submission result & fix clippy
1 parent 11ca2bd commit a7ae93c

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

tmc-langs/src/course_refresher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ fn execute_zip(
392392
let tmcproject_yml_path = exercise_root.join(".tmcproject.yml");
393393
if tmcproject_yml_path.exists() {
394394
let tmcproject_yml = file_util::read_file(&tmcproject_yml_path)?;
395-
let relative_path = tmcproject_yml_path.strip_prefix(&root_path).unwrap(); // safe
395+
let relative_path = tmcproject_yml_path.strip_prefix(&root_path).expect("relative path failed for tmcproject yml"); // safe
396396
writer.start_file(
397397
relative_path.to_string_lossy(),
398398
zip::write::FileOptions::default(),

tmc-langs/src/lib.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,12 +1054,14 @@ mod test {
10541054
course_name: "some course".to_string(),
10551055
exercise_name: "some exercise".to_string(),
10561056
checksum: "new checksum".to_string(),
1057+
hide_submission_results: false,
10571058
},
10581059
ExercisesDetails {
10591060
id: 2,
10601061
course_name: "some course".to_string(),
10611062
exercise_name: "another exercise".to_string(),
10621063
checksum: "old checksum".to_string(),
1064+
hide_submission_results: false,
10631065
},
10641066
];
10651067
let mut response = HashMap::new();
@@ -1159,24 +1161,35 @@ checksum = 'new checksum'
11591161
checksum: "new checksum".to_string(),
11601162
course_name: "some course".to_string(),
11611163
exercise_name: "on disk exercise with update and submission".to_string(),
1164+
hide_submission_results: false,
11621165
},
11631166
ExercisesDetails {
11641167
id: 2,
11651168
checksum: "new checksum".to_string(),
11661169
course_name: "some course".to_string(),
11671170
exercise_name: "on disk exercise without update".to_string(),
1171+
hide_submission_results: false,
11681172
},
11691173
ExercisesDetails {
11701174
id: 3,
11711175
checksum: "new checksum".to_string(),
11721176
course_name: "another course".to_string(),
11731177
exercise_name: "not on disk exercise with submission".to_string(),
1178+
hide_submission_results: false,
11741179
},
11751180
ExercisesDetails {
11761181
id: 4,
11771182
checksum: "new checksum".to_string(),
11781183
course_name: "another course".to_string(),
11791184
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: "not on disk exercise with submission exercise hide submission result".to_string(),
1192+
hide_submission_results: true,
11801193
},
11811194
],
11821195
);
@@ -1254,6 +1267,16 @@ checksum = 'new checksum'
12541267
.with_body(serde_json::to_string(&[0; 0]).unwrap())
12551268
.create();
12561269

1270+
let _m = mockito::mock(
1271+
"GET",
1272+
mockito::Matcher::AllOf(vec![
1273+
mockito::Matcher::Regex("exercises/5".to_string()),
1274+
mockito::Matcher::Regex("submissions".to_string()),
1275+
]),
1276+
)
1277+
.with_body(serde_json::to_string(&sub_body).unwrap())
1278+
.create();
1279+
12571280
let mut template_zw = zip::ZipWriter::new(std::io::Cursor::new(vec![]));
12581281
template_zw
12591282
.start_file("src/student_file.py", zip::write::FileOptions::default())
@@ -1312,6 +1335,15 @@ checksum = 'new checksum'
13121335
)
13131336
.with_body(&template_z)
13141337
.create();
1338+
let _m = mockito::mock(
1339+
"GET",
1340+
mockito::Matcher::AllOf(vec![
1341+
mockito::Matcher::Regex("exercises/5".to_string()),
1342+
mockito::Matcher::Regex("download".to_string()),
1343+
]),
1344+
)
1345+
.with_body(&template_z)
1346+
.create();
13151347

13161348
let mut sub_zw = zip::ZipWriter::new(std::io::Cursor::new(vec![]));
13171349
sub_zw
@@ -1356,13 +1388,14 @@ checksum = 'new checksum'
13561388
other => panic!("{:?}", other),
13571389
};
13581390

1359-
assert_eq!(downloaded.len(), 3);
1391+
assert_eq!(downloaded.len(), 4);
13601392
assert_eq!(skipped.len(), 1);
13611393

13621394
let e1 = downloaded.iter().find(|e| e.id == 1).unwrap();
13631395
let _e2 = skipped.iter().find(|e| e.id == 2).unwrap();
13641396
let e3 = downloaded.iter().find(|e| e.id == 3).unwrap();
13651397
let e4 = downloaded.iter().find(|e| e.id == 4).unwrap();
1398+
let e5 = downloaded.iter().find(|e|e.id == 5).unwrap();
13661399

13671400
// did not download submission even though it was available because it was on disk
13681401
let f = file_util::read_file_to_string(e1.path.join("src/student_file.py")).unwrap();
@@ -1385,9 +1418,16 @@ checksum = 'new checksum'
13851418
// did not download submission because one was not available
13861419
let f = file_util::read_file_to_string(e4.path.join("src/student_file.py")).unwrap();
13871420
assert_eq!(f, "template");
1388-
assert!(e1.path.join("src/template_only_student_file.py").exists());
1421+
assert!(e4.path.join("src/template_only_student_file.py").exists());
13891422
let f = file_util::read_file_to_string(e4.path.join("test/exercise_file.py")).unwrap();
13901423
assert_eq!(f, "template");
1424+
1425+
// did not download submission because exercise hides submission results, for example exam exercise
1426+
let f = file_util::read_file_to_string(e5.path.join("src/student_file.py")).unwrap();
1427+
assert_eq!(f, "template");
1428+
assert!(e5.path.join("src/template_only_student_file.py").exists());
1429+
let f = file_util::read_file_to_string(e5.path.join("test/exercise_file.py")).unwrap();
1430+
assert_eq!(f, "template");
13911431
}
13921432

13931433
#[test]

0 commit comments

Comments
 (0)