@@ -5,7 +5,6 @@ use self::api_v8::{PasteData, ReviewData};
55use crate :: error:: ClientError ;
66use crate :: request:: * ;
77use crate :: response:: * ;
8- use crate :: Language ;
98use oauth2:: {
109 basic:: BasicClient , AuthUrl , ClientId , ClientSecret , ResourceOwnerPassword ,
1110 ResourceOwnerUsername , TokenUrl ,
@@ -19,6 +18,7 @@ use std::thread;
1918use std:: time:: Duration ;
2019use std:: { collections:: HashMap , io:: Cursor } ;
2120use std:: { io:: Write , u32} ;
21+ use tmc_langs_plugins:: Language ;
2222use tmc_langs_util:: progress_reporter;
2323
2424/// Authentication token.
@@ -571,17 +571,6 @@ impl TmcClient {
571571 Ok ( ( ) )
572572 }
573573
574- /// Checks the status of a submission on the server. May require authentication.
575- ///
576- /// # Errors
577- /// 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.
578- pub fn check_submission (
579- & self ,
580- submission_id : u32 ,
581- ) -> Result < SubmissionProcessingStatus , ClientError > {
582- api_v8:: get_submission ( self , submission_id)
583- }
584-
585574 /// Request code review. Requires authentication.
586575 ///
587576 /// # Errors
@@ -596,12 +585,6 @@ impl TmcClient {
596585 }
597586}
598587
599- impl AsRef < TmcCore > for TmcClient {
600- fn as_ref ( & self ) -> & TmcCore {
601- & self . 0
602- }
603- }
604-
605588fn start_stage ( steps : u32 , message : impl Into < String > , data : impl Into < Option < ClientUpdateData > > ) {
606589 progress_reporter:: start_stage ( steps, message. into ( ) , data. into ( ) )
607590}
@@ -617,6 +600,9 @@ fn finish_stage(message: impl Into<String>, data: impl Into<Option<ClientUpdateD
617600#[ cfg( test) ]
618601#[ allow( clippy:: clippy:: unwrap_used) ]
619602mod test {
603+ use std:: sync:: atomic:: AtomicBool ;
604+
605+ // many of TmcClient's functions simply call already tested functions from api_v8 and don't need testing
620606 use super :: * ;
621607 use mockito:: Matcher ;
622608 use oauth2:: { basic:: BasicTokenType , AccessToken , EmptyExtraTokenFields } ;
@@ -760,4 +746,57 @@ mod test {
760746 assert_eq ! ( update_result. updated. len( ) , 1 ) ;
761747 assert_eq ! ( update_result. updated[ 0 ] . checksum, "zz" ) ;
762748 }
749+
750+ #[ test]
751+ fn waits_for_submission ( ) {
752+ init ( ) ;
753+
754+ let client = make_client ( ) ;
755+ let m = mockito:: mock ( "GET" , "/api/v8/core/submission/0" )
756+ . match_query ( Matcher :: AllOf ( vec ! [
757+ Matcher :: UrlEncoded ( "client" . into( ) , "some_client" . into( ) ) ,
758+ Matcher :: UrlEncoded ( "client_version" . into( ) , "some_ver" . into( ) ) ,
759+ ] ) )
760+ . with_body_from_fn ( |w| {
761+ static CALLED : AtomicBool = AtomicBool :: new ( false ) ;
762+ if !CALLED . load ( std:: sync:: atomic:: Ordering :: SeqCst ) {
763+ CALLED . store ( true , std:: sync:: atomic:: Ordering :: SeqCst ) ;
764+ w. write_all (
765+ br#"
766+ {
767+ "status": "processing",
768+ "sandbox_status": "created"
769+ }
770+ "# ,
771+ )
772+ . unwrap ( ) ;
773+ } else {
774+ w. write_all (
775+ br#"
776+ {
777+ "api_version": 0,
778+ "user_id": 1,
779+ "login": "",
780+ "course": "",
781+ "exercise_name": "",
782+ "status": "processing",
783+ "points": [],
784+ "submission_url": "",
785+ "submitted_at": "",
786+ "reviewed": false,
787+ "requests_review": false,
788+ "missing_review_points": []
789+ }
790+ "# ,
791+ )
792+ . unwrap ( ) ;
793+ }
794+ Ok ( ( ) )
795+ } )
796+ . expect ( 2 )
797+ . create ( ) ;
798+
799+ let _res = client. wait_for_submission ( 0 ) . unwrap ( ) ;
800+ m. assert ( ) ;
801+ }
763802}
0 commit comments