Skip to content

Commit

Permalink
test delete broken or incomplete jsons
Browse files Browse the repository at this point in the history
return 404 if the file does not exist
  • Loading branch information
vedina committed Mar 28, 2024
1 parent 062214d commit 6bedd4a
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 26 deletions.
4 changes: 3 additions & 1 deletion src/rcapi/api/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ async def get_template(request : Request, response : Response,

if format in format_supported:
json_blueprint ,file_path = template_service.get_template_json(uuid)
if file_path is None:
raise HTTPException(status_code=404, detail="Not found")
last_modified_time = get_last_modified(file_path)
custom_headers = { "Last-Modified": last_modified_time.strftime(DATE_FORMAT) }
if format=="json":
Expand Down Expand Up @@ -243,7 +245,7 @@ async def get_template(request : Request, response : Response,
except Exception as err:
raise HTTPException(status_code=400, detail="The blueprint may not be complete. {}".format(err))
else:
raise HTTPException(status_code=400, detail="Format not supported")
raise HTTPException(status_code=400, detail="Format not supported")


@router.get("/template")
Expand Down
2 changes: 2 additions & 0 deletions src/rcapi/services/template_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def get_template_json(uuid):
if os.path.exists(file_path):
with open(file_path, "r") as file:
json_data = json.load(file)
else:
file_path = None
return json_data ,file_path


Expand Down
236 changes: 236 additions & 0 deletions tests/resources/templates/dose_response_noname.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
{
"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 "
}
]
}
1 change: 1 addition & 0 deletions tests/resources/templates/null.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
Loading

0 comments on commit 6bedd4a

Please sign in to comment.