2020config .ENABLE_PREVIEWS_APIS = "true"
2121config .AUTH_USER_ENABLED = "true"
2222
23+ TRACKING_ID = "123e4567-e89b-12d3-a456-426614174000"
2324TRAINER_EXPORT_PATH = os .path .join (os .path .dirname (__file__ ), ".." , ".." , "resources" , "fixture" , "trainer_export.json" )
2425NOTE_PATH = os .path .join (os .path .dirname (__file__ ), ".." , ".." , "resources" , "fixture" , "note.txt" )
2526ANOTHER_TRAINER_EXPORT_PATH = os .path .join (os .path .dirname (__file__ ), ".." , ".." , "resources" , "fixture" , "another_trainer_export.json" )
@@ -196,6 +197,19 @@ def test_preview_trainer_export(client):
196197 assert response .headers ["Content-Type" ] == "application/octet-stream"
197198 assert len (response .text .split ("<br/>" )) == 4
198199
200+ # test with provided tracking ID
201+ with open (TRAINER_EXPORT_PATH , "rb" ) as f1 :
202+ with open (ANOTHER_TRAINER_EXPORT_PATH , "rb" ) as f2 :
203+ response = client .post (f"/preview_trainer_export?tracking_id={ TRACKING_ID } " , files = [
204+ ("trainer_export" , f1 ),
205+ ("trainer_export" , f2 ),
206+ ])
207+
208+ assert response .status_code == 200
209+ assert response .headers ["Content-Type" ] == "application/octet-stream"
210+ assert len (response .text .split ("<br/>" )) == 4
211+ assert TRACKING_ID in response .headers ["Content-Disposition" ]
212+
199213
200214def test_preview_trainer_export_str (client ):
201215 with open (TRAINER_EXPORT_PATH , "r" ) as f :
@@ -252,6 +266,16 @@ def test_train_supervised(model_service, client):
252266 assert response .json ()["message" ] == "Your training started successfully."
253267 assert "training_id" in response .json ()
254268
269+ # test with provided tracking ID
270+ with open (TRAINER_EXPORT_PATH , "rb" ) as f :
271+ response = client .post (f"/train_supervised?tracking_id={ TRACKING_ID } " , files = [("trainer_export" , f )])
272+
273+ model_service .train_supervised .assert_called ()
274+ assert response .status_code == 202
275+ assert response .json ()["message" ] == "Your training started successfully."
276+ assert "training_id" in response .json ()
277+ assert response .json ().get ("training_id" ) == TRACKING_ID
278+
255279
256280def test_train_unsupervised (model_service , client ):
257281 with tempfile .TemporaryFile ("r+b" ) as f :
@@ -262,6 +286,16 @@ def test_train_unsupervised(model_service, client):
262286 assert response .json ()["message" ] == "Your training started successfully."
263287 assert "training_id" in response .json ()
264288
289+ # test with provided tracking ID
290+ with tempfile .TemporaryFile ("r+b" ) as f :
291+ f .write (str .encode ("[\" Spinal stenosis\" ]" ))
292+ response = client .post (f"/train_unsupervised?tracking_id={ TRACKING_ID } " , files = [("training_data" , f )])
293+
294+ model_service .train_unsupervised .assert_called ()
295+ assert response .json ()["message" ] == "Your training started successfully."
296+ assert "training_id" in response .json ()
297+ assert response .json ().get ("training_id" ) == TRACKING_ID
298+
265299
266300def test_train_unsupervised_with_hf_hub_dataset (model_service , client ):
267301 model_card = ModelCard .parse_obj ({
@@ -278,6 +312,14 @@ def test_train_unsupervised_with_hf_hub_dataset(model_service, client):
278312 assert response .json ()["message" ] == "Your training started successfully."
279313 assert "training_id" in response .json ()
280314
315+ # test with provided tracking ID
316+ response = client .post (f"/train_unsupervised_with_hf_hub_dataset?hf_dataset_repo_id=imdb&tracking_id={ TRACKING_ID } " )
317+
318+ model_service .train_unsupervised .assert_called ()
319+ assert response .json ()["message" ] == "Your training started successfully."
320+ assert "training_id" in response .json ()
321+ assert response .json ().get ("training_id" ) == TRACKING_ID
322+
281323
282324def test_train_metacat (model_service , client ):
283325 with open (TRAINER_EXPORT_PATH , "rb" ) as f :
@@ -288,6 +330,16 @@ def test_train_metacat(model_service, client):
288330 assert response .json ()["message" ] == "Your training started successfully."
289331 assert "training_id" in response .json ()
290332
333+ # test with provided tracking ID
334+ with open (TRAINER_EXPORT_PATH , "rb" ) as f :
335+ response = client .post (f"/train_metacat?tracking_id={ TRACKING_ID } " , files = [("trainer_export" , f )])
336+
337+ model_service .train_metacat .assert_called ()
338+ assert response .status_code == 202
339+ assert response .json ()["message" ] == "Your training started successfully."
340+ assert "training_id" in response .json ()
341+ assert response .json ().get ("training_id" ) == TRACKING_ID
342+
291343
292344def test_evaluate_with_trainer_export (client ):
293345 with open (TRAINER_EXPORT_PATH , "rb" ) as f :
@@ -297,6 +349,15 @@ def test_evaluate_with_trainer_export(client):
297349 assert response .json ()["message" ] == "Your evaluation started successfully."
298350 assert "evaluation_id" in response .json ()
299351
352+ # test with provided tracking ID
353+ with open (TRAINER_EXPORT_PATH , "rb" ) as f :
354+ response = client .post (f"/evaluate?tracking_id={ TRACKING_ID } " , files = [("trainer_export" , f )])
355+
356+ assert response .status_code == 202
357+ assert response .json ()["message" ] == "Your evaluation started successfully."
358+ assert "evaluation_id" in response .json ()
359+ assert response .json ().get ("evaluation_id" ) == TRACKING_ID
360+
300361
301362def test_sanity_check_with_trainer_export (client ):
302363 with open (TRAINER_EXPORT_PATH , "rb" ) as f :
@@ -306,6 +367,15 @@ def test_sanity_check_with_trainer_export(client):
306367 assert response .headers ["Content-Type" ] == "text/csv; charset=utf-8"
307368 assert response .text .split ("\n " )[0 ] == "concept,name,precision,recall,f1"
308369
370+ # test with provided tracking ID
371+ with open (TRAINER_EXPORT_PATH , "rb" ) as f :
372+ response = client .post (f"/sanity-check?tracking_id={ TRACKING_ID } " , files = [("trainer_export" , f )])
373+
374+ assert response .status_code == 200
375+ assert response .headers ["Content-Type" ] == "text/csv; charset=utf-8"
376+ assert response .text .split ("\n " )[0 ] == "concept,name,precision,recall,f1"
377+ assert TRACKING_ID in response .headers ["Content-Disposition" ]
378+
309379
310380def test_inter_annotator_agreement_scores_per_concept (client ):
311381 with open (TRAINER_EXPORT_PATH , "rb" ) as f1 :
@@ -319,6 +389,19 @@ def test_inter_annotator_agreement_scores_per_concept(client):
319389 assert response .headers ["Content-Type" ] == "text/csv; charset=utf-8"
320390 assert response .text .split ("\n " )[0 ] == "concept,iaa_percentage,cohens_kappa,iaa_percentage_meta,cohens_kappa_meta"
321391
392+ # test with provided tracking ID
393+ with open (TRAINER_EXPORT_PATH , "rb" ) as f1 :
394+ with open (ANOTHER_TRAINER_EXPORT_PATH , "rb" ) as f2 :
395+ response = client .post (f"/iaa-scores?annotator_a_project_id=14&annotator_b_project_id=15&scope=per_concept&tracking_id={ TRACKING_ID } " , files = [
396+ ("trainer_export" , f1 ),
397+ ("trainer_export" , f2 ),
398+ ])
399+
400+ assert response .status_code == 200
401+ assert response .headers ["Content-Type" ] == "text/csv; charset=utf-8"
402+ assert response .text .split ("\n " )[0 ] == "concept,iaa_percentage,cohens_kappa,iaa_percentage_meta,cohens_kappa_meta"
403+ assert TRACKING_ID in response .headers ["Content-Disposition" ]
404+
322405
323406@pytest .mark .parametrize ("pid_a,pid_b,error_message" , [(0 , 2 , "Cannot find the project with ID: 0" ), (1 , 3 , "Cannot find the project with ID: 3" )])
324407def test_project_not_found_on_getting_iaa_scores (pid_a , pid_b , error_message , client ):
@@ -381,6 +464,19 @@ def test_concat_trainer_exports(client):
381464 assert response .headers ["Content-Type" ] == "application/json; charset=utf-8"
382465 assert len (response .text ) == 36918
383466
467+ # test with provided tracking ID
468+ with open (TRAINER_EXPORT_PATH , "rb" ) as f1 :
469+ with open (ANOTHER_TRAINER_EXPORT_PATH , "rb" ) as f2 :
470+ response = client .post (f"/concat_trainer_exports?tracking_id={ TRACKING_ID } " , files = [
471+ ("trainer_export" , f1 ),
472+ ("trainer_export" , f2 ),
473+ ])
474+
475+ assert response .status_code == 200
476+ assert response .headers ["Content-Type" ] == "application/json; charset=utf-8"
477+ assert len (response .text ) == 36918
478+ assert TRACKING_ID in response .headers ["Content-Disposition" ]
479+
384480
385481def test_get_annotation_stats (client ):
386482 with open (TRAINER_EXPORT_PATH , "rb" ) as f1 :
@@ -394,6 +490,19 @@ def test_get_annotation_stats(client):
394490 assert response .headers ["Content-Type" ] == "text/csv; charset=utf-8"
395491 assert response .text .split ("\n " )[0 ] == "concept,anno_count,anno_unique_counts,anno_ignorance_counts"
396492
493+ # test with provided tracking ID
494+ with open (TRAINER_EXPORT_PATH , "rb" ) as f1 :
495+ with open (ANOTHER_TRAINER_EXPORT_PATH , "rb" ) as f2 :
496+ response = client .post (f"/annotation-stats?tracking_id={ TRACKING_ID } " , files = [
497+ ("trainer_export" , f1 ),
498+ ("trainer_export" , f2 ),
499+ ])
500+
501+ assert response .status_code == 200
502+ assert response .headers ["Content-Type" ] == "text/csv; charset=utf-8"
503+ assert response .text .split ("\n " )[0 ] == "concept,anno_count,anno_unique_counts,anno_ignorance_counts"
504+ assert TRACKING_ID in response .headers ["Content-Disposition" ]
505+
397506
398507def test_extract_entities_from_text_list_file_as_json_file (model_service , client ):
399508 annotations_list = [
@@ -435,3 +544,27 @@ def test_extract_entities_from_text_list_file_as_json_file(model_service, client
435544 },
436545 }]
437546 }] * 15
547+
548+ # test with provided tracking ID
549+ with open (MULTI_TEXTS_FILE_PATH , "rb" ) as f :
550+ response = client .post (f"/process_bulk_file?tracking_id={ TRACKING_ID } " , files = [("multi_text_file" , f )])
551+
552+ assert isinstance (response , httpx .Response )
553+ assert json .loads (response .content ) == [{
554+ "text" : "Description: Intracerebral hemorrhage (very acute clinical changes occurred immediately).\n CC: Left hand numbness on presentation; then developed lethargy later that day.\n HX: On the day of presentation, this 72 y/o RHM suddenly developed generalized weakness and lightheadedness, and could not rise from a chair. Four hours later he experienced sudden left hand numbness lasting two hours. There were no other associated symptoms except for the generalized weakness and lightheadedness. He denied vertigo.\n He had been experiencing falling spells without associated LOC up to several times a month for the past year.\n MEDS: procardia SR, Lasix, Ecotrin, KCL, Digoxin, Colace, Coumadin.\n PMH: 1)8/92 evaluation for presyncope (Echocardiogram showed: AV fibrosis/calcification, AV stenosis/insufficiency, MV stenosis with annular calcification and regurgitation, moderate TR, Decreased LV systolic function, severe LAE. MRI brain: focal areas of increased T2 signal in the left cerebellum and in the brainstem probably representing microvascular ischemic disease. IVG (MUGA scan)revealed: global hypokinesis of the LV and biventricular dysfunction, RV ejection Fx 45% and LV ejection Fx 39%. He was subsequently placed on coumadin severe valvular heart disease), 2)HTN, 3)Rheumatic fever and heart disease, 4)COPD, 5)ETOH abuse, 6)colonic polyps, 7)CAD, 8)CHF, 9)Appendectomy, 10)Junctional tachycardia." ,
555+ "annotations" : [{
556+ "label_name" : "Spinal stenosis" ,
557+ "label_id" : "76107001" ,
558+ "start" : 0 ,
559+ "end" : 15 ,
560+ "accuracy" : 1.0 ,
561+ "meta_anns" : {
562+ "Status" : {
563+ "value" : "Affirmed" ,
564+ "confidence" : 0.9999833106994629 ,
565+ "name" : "Status"
566+ }
567+ },
568+ }]
569+ }] * 15
570+ assert TRACKING_ID in response .headers ["Content-Disposition" ]
0 commit comments