Skip to content
Snippets Groups Projects
Commit d9ff51f5 authored by Bryan BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

update python tests, raise 404 when initTable does not exist

parent 68b2b25a
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,10 @@ async def read_index():
@app.post("/api/phenotypes", response_model=List[Phenotype])
def phenotypes_list(project_name: ProjectNameModel):
"""List phenotypes"""
return get_available_phenotypes(os.path.join(config["DATA_DIR"], project_name.initTableName))
try:
return get_available_phenotypes(os.path.join(config["DATA_DIR"], project_name.initTableName))
except FileNotFoundError as e: # initTable does not exists
raise HTTPException(status_code=404, detail=str(e))
@app.get("/api/initmeta")
def inittable_meta():
......
......@@ -30,6 +30,10 @@ class JassWebClientTestCase(JassTestCase):
self.test_dir = tempfile.mkdtemp()
config["DATA_DIR"] = self.test_dir
shutil.copy(self.get_file_path_fn("initTable.hdf5"), self.test_dir)
try:
shutil.copy(self.get_file_path_fn("initTableTest1.hdf5"), self.test_dir)
except FileNotFoundError:
pass
from jass.server import app
self.testing_client = TestClient(app)
......
......@@ -13,22 +13,48 @@ from . import JassWebClientTestCase
class TestDefaultController(JassWebClientTestCase):
"""DefaultController integration test stubs"""
test_folder = "data_test1"
test_folder = "data_real"
def test_phenotypes_get(self):
def test_phenotypes_post(self):
"""
Test case retrieving available phenotypes
"""
response = self.testing_client.get("/api/phenotypes")
response = self.testing_client.post("/api/phenotypes", json={})
self.assert200(response, "Response body is : " + response.content.decode("utf-8"))
response = self.testing_client.post(
"/api/phenotypes",
json={"initTableName": "initTable.hdf5"},
)
self.assert200(response, "Response body is : " + response.content.decode("utf-8"))
json_response_main = json.loads(response.content.decode("utf-8"))
phenotypes_main = set(p["id"] for p in json_response_main)
response = self.testing_client.post(
"/api/phenotypes",
json={"initTableName": "initTableTest1.hdf5"},
)
self.assert200(response, "Response body is : " + response.content.decode("utf-8"))
json_response_t1 = json.loads(response.content.decode("utf-8"))
phenotypes_t1 = set(p["id"] for p in json_response_t1)
self.assertNotEqual(json_response_t1, json_response_main)
self.assertNotEqual(phenotypes_main, phenotypes_t1)
self.assertEqual(phenotypes_main.intersection(phenotypes_t1), set())
response = self.testing_client.post(
"/api/phenotypes",
json={"initTableName": "initTableMissing.hdf5"},
)
self.assertEqual(response.status_code, 404, response.content.decode("utf-8"))
def test_create_project(self):
"""
Test case for creating a project
"""
response = self.testing_client.post(
"/api/projects",
json={"phenotypeID": ["z_DISNEY_POCAHONT"]},
json={"phenotypeID": ["z_MAGIC_FAST-GLUCOSE"]},
)
self.assert200(response, "Response body is : " + response.content.decode("utf-8"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment