diff --git a/jass/server.py b/jass/server.py index 27f6094e14211000263b5a43bca1803c534eca5d..da2feb991562e09620773198a381ec58e6def6a2 100644 --- a/jass/server.py +++ b/jass/server.py @@ -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(): diff --git a/jass/test/__init__.py b/jass/test/__init__.py index 25cecd228521526e63f108c1b71fb40649abfcaf..7f6ab04bc94ab97ebf0e1746bbab91735d233504 100644 --- a/jass/test/__init__.py +++ b/jass/test/__init__.py @@ -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) diff --git a/jass/test/test_server.py b/jass/test/test_server.py index 4bf6b023063b356a51b0ae240ee1e82a36c0f5f1..6d5eec95cb9733ddb3430aeaffab96bd98c170e4 100644 --- a/jass/test/test_server.py +++ b/jass/test/test_server.py @@ -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"))