11
2- import pytest
3- from schematic_api .api import create_app
42import configparser
53import json
4+ import logging
65import os
76import re
7+ import time
88from math import ceil
9- import logging
109from time import perf_counter
11- import pandas as pd # third party library import
12- from schematic .schemas .generator import SchemaGenerator #Local application/library specific imports.
10+
11+ import numpy as np
12+ import pandas as pd # third party library import
13+ import pytest
14+
15+ from schematic .schemas .generator import \
16+ SchemaGenerator # Local application/library specific imports.
17+ from schematic_api .api import create_app
1318
1419logging .basicConfig (level = logging .INFO )
1520logger = logging .getLogger (__name__ )
@@ -32,6 +37,11 @@ def test_manifest_csv(helpers):
3237 test_manifest_path = helpers .get_data_path ("mock_manifests/Valid_Test_Manifest.csv" )
3338 yield test_manifest_path
3439
40+ @pytest .fixture (scope = "class" )
41+ def test_manifest_submit (helpers ):
42+ test_manifest_path = helpers .get_data_path ("mock_manifests/example_biospecimen_test.csv" )
43+ yield test_manifest_path
44+
3545@pytest .fixture (scope = "class" )
3646def test_invalid_manifest (helpers ):
3747 test_invalid_manifest = helpers .get_data_frame ("mock_manifests/Invalid_Test_Manifest.csv" , preserve_raw_input = False )
@@ -656,104 +666,105 @@ def test_dataset_manifest_download(self, client, as_json, syn_token, new_manifes
656666
657667 if as_json :
658668 response_json = json .loads (response_dt )
659- assert response_json == [{'Component' : 'BulkRNA-seqAssay' , 'File Format' : 'CSV/TSV' , 'Filename' : 'Sample_A' , 'Genome Build' : 'GRCm38' , 'Genome FASTA' : None , 'Sample ID' : 2022 , 'entityId' : 'syn28278954' }]
669+ assert response_json [0 ]["Component" ] == "BulkRNA-seqAssay"
670+ assert response_json [0 ]["File Format" ] == "CSV/TSV"
671+ assert response_json [0 ]["Sample ID" ] == 2022
672+ assert response_json [0 ]["entityId" ] == "syn28278954"
660673 else :
661674 # return a file path
662675 response_path = response_dt .decode ('utf-8' )
663676
664677 assert isinstance (response_path , str )
665678 assert response_path .endswith (".csv" )
666679
667- @pytest .mark .parametrize ("json_str" , [None , '[{ "Patient ID": 123, "Sex": "Female", "Year of Birth": "", "Diagnosis": "Healthy", "Component": "Patient", "Cancer Type": "Breast", "Family History": "Breast, Lung", }]' ])
668- @pytest .mark .parametrize ("use_schema_label" , ['true' ,'false' ])
669- @pytest .mark .parametrize ("manifest_record_type" , ['table_and_file' , 'file_only' ])
670- def test_submit_manifest (self , client , syn_token , data_model_jsonld , json_str , test_manifest_csv , use_schema_label , manifest_record_type ):
680+ def test_submit_manifest_table_and_file_replace (self , client , syn_token , data_model_jsonld , test_manifest_submit ):
681+ """Testing submit manifest in a csv format as a table and a file. Only replace the table
682+ """
671683 params = {
672684 "access_token" : syn_token ,
673685 "schema_url" : data_model_jsonld ,
674- "data_type" : "Patient " ,
686+ "data_type" : "Biospecimen " ,
675687 "restrict_rules" : False ,
676- "manifest_record_type" : manifest_record_type ,
677- "asset_view" : "syn44259375 " ,
678- "dataset_id" : "syn44259313 " ,
688+ "manifest_record_type" : "table_and_file" ,
689+ "asset_view" : "syn51514344 " ,
690+ "dataset_id" : "syn51514345 " ,
679691 "table_manipulation" : 'replace' ,
680- "use_schema_label" : use_schema_label
692+ "use_schema_label" : True
681693 }
682694
683- if json_str :
684- params ["json_str" ] = json_str
685- response = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" :'' })
686- assert response .status_code == 200
687- else :
688- headers = {
689- 'Content-Type' : "multipart/form-data" ,
690- 'Accept' : "application/json"
691- }
692- params ["data_type" ] = "MockComponent"
693-
694- # test uploading a csv file
695- response_csv = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" : (open (test_manifest_csv , 'rb' ), "test.csv" )}, headers = headers )
696- assert response_csv .status_code == 200
695+ response_csv = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" : (open (test_manifest_submit , 'rb' ), "test.csv" )})
696+ assert response_csv .status_code == 200
697697
698- @ pytest . mark . parametrize ( "json_str" , [ None , '[{ "Patient ID": 123, "Sex": "Female", "Year of Birth": "", "Diagnosis": "Healthy", "Component": "Patient", "Cancer Type": "Breast", "Family History": "Breast, Lung", }]' ])
699- @ pytest . mark . parametrize ( "manifest_record_type" , [ 'file_and_entities' , 'table_file_and_entities' ])
700- def test_submit_manifest_w_entities ( self , client , syn_token , data_model_jsonld , json_str , test_manifest_csv , manifest_record_type ):
698+ def test_submit_manifest_file_only_replace ( self , client , syn_token , data_model_jsonld , test_manifest_submit ):
699+ """Testing submit manifest in a csv format as a file
700+ """
701701 params = {
702702 "access_token" : syn_token ,
703703 "schema_url" : data_model_jsonld ,
704- "data_type" : "Patient " ,
704+ "data_type" : "Biospecimen " ,
705705 "restrict_rules" : False ,
706- "manifest_record_type" : manifest_record_type ,
707- "asset_view" : "syn44259375 " ,
708- "dataset_id" : "syn44259313 " ,
706+ "manifest_record_type" : "file_only" ,
707+ "asset_view" : "syn51514344 " ,
708+ "dataset_id" : "syn51514345 " ,
709709 "table_manipulation" : 'replace' ,
710710 "use_schema_label" : True
711711 }
712+ response_csv = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" : (open (test_manifest_submit , 'rb' ), "test.csv" )})
713+ assert response_csv .status_code == 200
714+
715+ def test_submit_manifest_json_str_replace (self , client , syn_token , data_model_jsonld ):
716+ """Submit json str as a file
717+ """
718+ json_str = '[{"Sample ID": 123, "Patient ID": 1,"Tissue Status": "Healthy","Component": "Biospecimen"}]'
719+ params = {
720+ "access_token" : syn_token ,
721+ "schema_url" : data_model_jsonld ,
722+ "data_type" : "Biospecimen" ,
723+ "json_str" : json_str ,
724+ "restrict_rules" : False ,
725+ "manifest_record_type" : "file_only" ,
726+ "asset_view" : "syn51514344" ,
727+ "dataset_id" : "syn51514345" ,
728+ "table_manipulation" : 'replace' ,
729+ "use_schema_label" : True
730+ }
731+ params ["json_str" ] = json_str
732+ response = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" :'' })
733+ assert response .status_code == 200
712734
713- if json_str :
714- params ["json_str" ] = json_str
715- response = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" :'' })
716- assert response .status_code == 200
717- else :
718- headers = {
719- 'Content-Type' : "multipart/form-data" ,
720- 'Accept' : "application/json"
721- }
722- params ["data_type" ] = "MockComponent"
735+ def test_submit_manifest_w_file_and_entities (self , client , syn_token , data_model_jsonld , test_manifest_submit ):
736+ params = {
737+ "access_token" : syn_token ,
738+ "schema_url" : data_model_jsonld ,
739+ "data_type" : "Biospecimen" ,
740+ "restrict_rules" : False ,
741+ "manifest_record_type" : "file_and_entities" ,
742+ "asset_view" : "syn51514501" ,
743+ "dataset_id" : "syn51514523" ,
744+ "table_manipulation" : 'replace' ,
745+ "use_schema_label" : True
746+ }
723747
724- # test uploading a csv file
725- response_csv = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" : (open (test_manifest_csv , 'rb' ), "test.csv" )}, headers = headers )
726- assert response_csv .status_code == 200
748+ # test uploading a csv file
749+ response_csv = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" : (open (test_manifest_submit , 'rb' ), "test.csv" )})
750+ assert response_csv .status_code == 200
727751
728-
729- @pytest .mark .parametrize ("json_str" , [None , '[{ "Component": "MockRDB", "MockRDB_id": 5 }]' ])
730- def test_submit_manifest_upsert (self , client , syn_token , data_model_jsonld , json_str , test_upsert_manifest_csv , ):
752+ def test_submit_manifest_table_and_file_upsert (self , client , syn_token , data_model_jsonld , test_upsert_manifest_csv , ):
731753 params = {
732754 "access_token" : syn_token ,
733755 "schema_url" : data_model_jsonld ,
734756 "data_type" : "MockRDB" ,
735757 "restrict_rules" : False ,
736- "manifest_record_type" : "table " ,
737- "asset_view" : "syn44259375 " ,
738- "dataset_id" : "syn44259313 " ,
758+ "manifest_record_type" : "table_and_file " ,
759+ "asset_view" : "syn51514557 " ,
760+ "dataset_id" : "syn51514551 " ,
739761 "table_manipulation" : 'upsert' ,
740- "use_schema_label" : False
762+ "use_schema_label" : False # have to set use_schema_label to false to ensure upsert feature works
741763 }
742764
743- if json_str :
744- params ["json_str" ] = json_str
745- response = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" :'' })
746- assert response .status_code == 200
747- else :
748- headers = {
749- 'Content-Type' : "multipart/form-data" ,
750- 'Accept' : "application/json"
751- }
752- params ["data_type" ] = "MockRDB"
753-
754- # test uploading a csv file
755- response_csv = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" : (open (test_upsert_manifest_csv , 'rb' ), "test.csv" )}, headers = headers )
756- assert response_csv .status_code == 200
765+ # test uploading a csv file
766+ response_csv = client .post ('http://localhost:3001/v1/model/submit' , query_string = params , data = {"file_name" : (open (test_upsert_manifest_csv , 'rb' ), "test.csv" )},)
767+ assert response_csv .status_code == 200
757768
758769@pytest .mark .schematic_api
759770class TestSchemaVisualization :
0 commit comments