Skip to content

Commit

Permalink
/template get and copy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vedina committed Feb 25, 2024
1 parent 2f40de2 commit d4c4b87
Show file tree
Hide file tree
Showing 2 changed files with 280 additions and 4 deletions.
239 changes: 238 additions & 1 deletion tests/resources/templates/dose_response.json
Original file line number Diff line number Diff line change
@@ -1 +1,238 @@
{"newtemplate":"create_new","PROTOCOL_TOP_CATEGORY":"TOX","pageNo":0,"user_role":["role_lab"],"templates":"c5dd3ac9-9340-44b0-9be8-6724c5e34c99","METHOD":"Dose response ","EXPERIMENT":"Generic dose response template","conditions":[{"conditon_name":"concentration","condition_unit":"ug/ml","condition_type":"c_concentration "},{"conditon_name":"time","condition_unit":"h","condition_type":"c_time "},{"conditon_name":"Replicate","condition_type":"c_replicate_tech "},{"conditon_name":"Experiment","condition_type":"c_replicate_bio "}],"PROTOCOL_CATEGORY_CODE":"ENM_0000068_SECTION","raw_data":true,"RESULTS":"raw data ( absorbance) \ncell viability (%)","raw_data_report":[{"raw_conditions":["concentration","time","Experiment","Replicate"],"raw_endpoint":"Absorbance","raw_unit":"A.U.","raw_type":"value_num"}],"question3":[{"results_conditions":["concentration","time","Experiment"],"result_name":"Cell viability","result_unit":"%","result_type":"value_num"}],"METADATA_PARAMETERS":[{"param_name":"Serum concentration in culture medium"},{"param_name":"Detailed cell type/line specification","param_group":"CELL LINE DETAILS","param_type":"value_text "},{"param_name":"Cell line short-name","param_group":"CELL LINE DETAILS","param_type":"value_text "},{"param_name":"Supplier","param_group":"CELL LINE DETAILS","param_type":"value_text "},{"param_name":"Passage no","param_group":"CELL LINE DETAILS","param_type":"value_num"},{"param_name":"Plate details as applic.","param_group":"CULTURE CONDITIONS","param_type":"value_text "},{"param_name":"Make / type","param_group":"CULTURE CONDITIONS","param_type":"value_text "},{"param_name":"Number of cells per well","param_group":"CULTURE CONDITIONS","param_type":"value_num"},{"param_name":"Total volume per well","param_group":"CULTURE CONDITIONS","param_type":"value_num"},{"param_name":"Medium (Supplier/Lot No.)","param_group":"MEDIUM","param_type":"value_text "},{"param_name":"Serum (inc. supplier/Lot No.)","param_group":"CULTURE CONDITIONS","param_type":"value_text "},{"param_name":"Serum concentration in treatment medium","param_group":"CULTURE CONDITIONS","param_type":"value_num"},{"param_name":"Was serum heat inactivated? If app.","param_group":"CULTURE CONDITIONS","param_type":"value_text "},{"param_name":"Submerged, ALI, or semi-ALI","param_group":"CULTURE CONDITIONS","param_type":"value_text "},{"param_name":"Exposure method","param_group":"ENVIRONMENT","param_type":"value_text "}],"METADATA_SAMPLE_INFO":[{"param_sample_name":"ID","param_sample_group":"ID"},{"param_sample_name":"Name","param_sample_group":"NAME"},{"param_sample_name":"CAS No","param_sample_group":"CASRN"},{"param_sample_name":"Nanomaterial Supplier","param_sample_group":"SUPPLIER"},{"param_sample_name":"Material State","param_sample_group":"OTHER_METADATA"},{"param_sample_name":"Batch","param_sample_group":"BATCH"},{"param_sample_name":"Vial","param_sample_group":"BATCH"}],"METADATA_SAMPLE_PREP":[{"param_sampleprep_name":"Date of preparation (YYYY-MM-DD)","param_sampleprep_group":"OTHER_METADATA","param_type":"value_text "},{"param_sampleprep_name":"Endotoxin confirmed as absent?","param_sampleprep_group":"OTHER_METADATA","param_type":"value_text "},{"param_sampleprep_name":"Effective concentration range used lowest-to-highest, inc units","param_sampleprep_group":"OTHER_METADATA","param_type":"value_text "},{"param_sampleprep_name":"Specify standard dispersion protocol used","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":"Dispersion agent","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":" Additives used? If yes, specify which & conc. used:","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":"Dispersed in cell culture medium","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":"Aids used to disperse","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":"Sonication-Bath","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":"Sonication-tip","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":"Vortexing","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":"Stirring","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":"Specify time-duration","param_sampleprep_group":"DISPERSION","param_type":"value_text "},{"param_sampleprep_name":"Energy (for sonication)","param_sampleprep_group":"DISPERSION","param_type":"value_text "}],"template_author":"xqa"}
{
"newtemplate": "create_new",
"PROTOCOL_TOP_CATEGORY": "TOX",
"pageNo": 0,
"user_role": [
"role_lab"
],
"templates": "c5dd3ac9-9340-44b0-9be8-6724c5e34c99",
"METHOD": "Dose response ",
"EXPERIMENT": "Generic dose response template",
"conditions": [
{
"conditon_name": "concentration",
"condition_unit": "ug/ml",
"condition_type": "c_concentration "
},
{
"conditon_name": "time",
"condition_unit": "h",
"condition_type": "c_time "
},
{
"conditon_name": "Replicate",
"condition_type": "c_replicate_tech "
},
{
"conditon_name": "Experiment",
"condition_type": "c_replicate_bio "
}
],
"PROTOCOL_CATEGORY_CODE": "ENM_0000068_SECTION",
"raw_data": true,
"RESULTS": "raw data ( absorbance) \ncell viability (%)",
"raw_data_report": [
{
"raw_conditions": [
"concentration",
"time",
"Experiment",
"Replicate"
],
"raw_endpoint": "Absorbance",
"raw_unit": "A.U.",
"raw_type": "value_num"
}
],
"question3": [
{
"results_conditions": [
"concentration",
"time",
"Experiment"
],
"result_name": "Cell viability",
"result_unit": "%",
"result_type": "value_num"
}
],
"METADATA_PARAMETERS": [
{
"param_name": "Serum concentration in culture medium"
},
{
"param_name": "Detailed cell type/line specification",
"param_group": "CELL LINE DETAILS",
"param_type": "value_text "
},
{
"param_name": "Cell line short-name",
"param_group": "CELL LINE DETAILS",
"param_type": "value_text "
},
{
"param_name": "Supplier",
"param_group": "CELL LINE DETAILS",
"param_type": "value_text "
},
{
"param_name": "Passage no",
"param_group": "CELL LINE DETAILS",
"param_type": "value_num"
},
{
"param_name": "Plate details as applic.",
"param_group": "CULTURE CONDITIONS",
"param_type": "value_text "
},
{
"param_name": "Make / type",
"param_group": "CULTURE CONDITIONS",
"param_type": "value_text "
},
{
"param_name": "Number of cells per well",
"param_group": "CULTURE CONDITIONS",
"param_type": "value_num"
},
{
"param_name": "Total volume per well",
"param_group": "CULTURE CONDITIONS",
"param_type": "value_num"
},
{
"param_name": "Medium (Supplier/Lot No.)",
"param_group": "MEDIUM",
"param_type": "value_text "
},
{
"param_name": "Serum (inc. supplier/Lot No.)",
"param_group": "CULTURE CONDITIONS",
"param_type": "value_text "
},
{
"param_name": "Serum concentration in treatment medium",
"param_group": "CULTURE CONDITIONS",
"param_type": "value_num"
},
{
"param_name": "Was serum heat inactivated? If app.",
"param_group": "CULTURE CONDITIONS",
"param_type": "value_text "
},
{
"param_name": "Submerged, ALI, or semi-ALI",
"param_group": "CULTURE CONDITIONS",
"param_type": "value_text "
},
{
"param_name": "Exposure method",
"param_group": "ENVIRONMENT",
"param_type": "value_text "
}
],
"METADATA_SAMPLE_INFO": [
{
"param_sample_name": "ID",
"param_sample_group": "ID"
},
{
"param_sample_name": "Name",
"param_sample_group": "NAME"
},
{
"param_sample_name": "CAS No",
"param_sample_group": "CASRN"
},
{
"param_sample_name": "Nanomaterial Supplier",
"param_sample_group": "SUPPLIER"
},
{
"param_sample_name": "Material State",
"param_sample_group": "OTHER_METADATA"
},
{
"param_sample_name": "Batch",
"param_sample_group": "BATCH"
},
{
"param_sample_name": "Vial",
"param_sample_group": "BATCH"
}
],
"METADATA_SAMPLE_PREP": [
{
"param_sampleprep_name": "Date of preparation (YYYY-MM-DD)",
"param_sampleprep_group": "OTHER_METADATA",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Endotoxin confirmed as absent?",
"param_sampleprep_group": "OTHER_METADATA",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Effective concentration range used lowest-to-highest, inc units",
"param_sampleprep_group": "OTHER_METADATA",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Specify standard dispersion protocol used",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Dispersion agent",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
},
{
"param_sampleprep_name": " Additives used? If yes, specify which & conc. used:",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Dispersed in cell culture medium",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Aids used to disperse",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Sonication-Bath",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Sonication-tip",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Vortexing",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Stirring",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Specify time-duration",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
},
{
"param_sampleprep_name": "Energy (for sonication)",
"param_sampleprep_group": "DISPERSION",
"param_type": "value_text "
}
],
"template_author": "xqa",
"template_name": "dose response demo"
}
45 changes: 42 additions & 3 deletions tests/test_api_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from importlib import resources
import yaml
import os.path
import shutil

TEST_JSON_PATH = Path(__file__).parent / "resources/templates/dose_response.json"
TEMPLATE_UUID = "3c22a1f0-a933-4855-848d-05fcc26ceb7a"

client = TestClient(app)
#warnings.warn("test")
Expand All @@ -30,9 +33,21 @@ def clean_template_dir(config_dict):
print(TEMPLATE_DIR)
remove_files_in_folder(TEMPLATE_DIR)
# Perform setup operations here, if any
yield # This is where the test runs
print("\nCleaning up resources after the test")
#yield # This is where the test runs
#print("\nCleaning up resources after the test")
#remove_files_in_folder(TEMPLATE_DIR)
# Perform cleanup operations here, if any

@pytest.fixture
def setup_template_dir(config_dict):
print("\nSetting up resources before the test")
TEMPLATE_DIR = os.path.join(config_dict["upload_dir"],"TEMPLATES")
remove_files_in_folder(TEMPLATE_DIR)
shutil.copy(TEST_JSON_PATH, os.path.join(TEMPLATE_DIR,"{}.json".format(TEMPLATE_UUID)))
# Perform setup operations here, if any
yield # This is where the test runs
#print("\nCleaning up resources after the test")
#remove_files_in_folder(TEMPLATE_DIR)
# Perform cleanup operations here, if any

def remove_files_in_folder(folder_path):
Expand Down Expand Up @@ -72,4 +87,28 @@ def test_upload_and_retrieve_json(clean_template_dir):
# Step 3: Compare uploaded and retrieved JSON
with open(TEST_JSON_PATH, "r") as file:
expected_json = json.load(file)
assert retrieved_json == expected_json
assert retrieved_json == expected_json

def test_retrieve_json(setup_template_dir):
# Step 1: get predefined JSON
response_retrieve = client.get("/template/{}".format(TEMPLATE_UUID))
assert response_retrieve.status_code == 200, response_retrieve.status_code
retrieved_json = response_retrieve.json()
# Step 1: Compare predefined and retrieved JSON
with open(TEST_JSON_PATH, "r") as file:
expected_json = json.load(file)
assert retrieved_json == expected_json

def test_makecopy(setup_template_dir):
# Step 1: make copy JSON
response_copy = client.post("/template/{}/copy".format(TEMPLATE_UUID))
result_uuid = get_task_result(response_copy)
# Step 2: Retrieve JSON using the result_uuid
response_retrieve = client.get(f"/template/{result_uuid}")
assert response_retrieve.status_code == 200, response_retrieve.status_code
retrieved_json = response_retrieve.json()
# Step 3: Compare uploaded and retrieved JSON
with open(TEST_JSON_PATH, "r") as file:
expected_json = json.load(file)
expected_json["origin_uuid"] = TEMPLATE_UUID
assert retrieved_json == expected_json , retrieved_json

0 comments on commit d4c4b87

Please sign in to comment.