Skip to content

Commit e805507

Browse files
committed
more test fixes, removed URLs from the CLI API
1 parent 6141683 commit e805507

File tree

6 files changed

+49
-941
lines changed

6 files changed

+49
-941
lines changed

tmc-client/src/tmc_client.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -356,19 +356,16 @@ impl TmcClient {
356356
api_v8::submission::get_exercise_submissions_for_current_user(self, exercise_id)
357357
}
358358

359-
/// Waits for a submission to finish. May require authentication.
360-
///
361-
/// # Errors
362-
/// If authentication is required but the client is not authenticated, there's some problem reaching the API, or if the API returns an error.
363-
pub fn wait_for_submission(
359+
// abstracts waiting for submission over different functions for getting the submission status
360+
fn wait_for_submission_inner(
364361
&self,
365-
submission_url: &str,
362+
f: impl Fn() -> Result<SubmissionProcessingStatus, ClientError>,
366363
) -> Result<SubmissionFinished, ClientError> {
367364
start_stage(4, "Waiting for submission", None);
368365

369366
let mut previous_status = None;
370367
loop {
371-
match self.check_submission(submission_url)? {
368+
match f()? {
372369
SubmissionProcessingStatus::Finished(f) => {
373370
finish_stage("Submission finished processing!", None);
374371
return Ok(*f);
@@ -435,6 +432,24 @@ impl TmcClient {
435432
}
436433
}
437434

435+
pub fn wait_for_submission_at(
436+
&self,
437+
submission_url: Url,
438+
) -> Result<SubmissionFinished, ClientError> {
439+
self.wait_for_submission_inner(|| api_v8::get_json(self, submission_url.clone(), &[]))
440+
}
441+
442+
/// Waits for a submission to finish. May require authentication.
443+
///
444+
/// # Errors
445+
/// If authentication is required but the client is not authenticated, there's some problem reaching the API, or if the API returns an error.
446+
pub fn wait_for_submission(
447+
&self,
448+
submission_id: u32,
449+
) -> Result<SubmissionFinished, ClientError> {
450+
self.wait_for_submission_inner(|| api_v8::get_submission(self, submission_id))
451+
}
452+
438453
/// Fetches the course's exercises from the server,
439454
/// and finds new or updated exercises. Requires authentication.
440455
/// If an exercise's id is not found in the checksum map, it is considered new.
@@ -550,11 +565,9 @@ impl TmcClient {
550565
/// If authentication is required but the client is not authenticated, if there's some problem reaching the API, or if the API returns an error.
551566
pub fn check_submission(
552567
&self,
553-
submission_url: &str,
568+
submission_id: u32,
554569
) -> Result<SubmissionProcessingStatus, ClientError> {
555-
let url = Url::parse(submission_url)
556-
.map_err(|e| ClientError::UrlParse(submission_url.to_string(), e))?;
557-
api_v8::get_submission_processing_status(self, url)
570+
api_v8::get_submission(self, submission_id)
558571
}
559572

560573
/// Request code review. Requires authentication.

0 commit comments

Comments
 (0)