From 50101e486f83ec8f7407d387e03fd684e5b834d4 Mon Sep 17 00:00:00 2001 From: Lars Falk-Petersen Date: Wed, 3 Jan 2024 12:57:20 +0100 Subject: [PATCH] Add web test for / --- app/app.py | 3 +-- app/test_app.py | 21 +++++++++++++++++++++ app/test_initialize.py | 11 ++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 app/test_app.py diff --git a/app/app.py b/app/app.py index 3fb9572..2baa423 100644 --- a/app/app.py +++ b/app/app.py @@ -5,6 +5,7 @@ from typing import AsyncGenerator import uvicorn from fastapi import FastAPI +from routes.routes import routes app = FastAPI(openapi_url="/openapi.json", docs_url="/api") @@ -25,8 +26,6 @@ async def lifespan() -> AsyncGenerator[None, None]: yield -from routes.routes import routes - app.include_router(routes) diff --git a/app/test_app.py b/app/test_app.py new file mode 100644 index 0000000..128318f --- /dev/null +++ b/app/test_app.py @@ -0,0 +1,21 @@ +import unittest +import os +from datetime import datetime +import uvicorn +from fastapi import FastAPI +from fastapi.testclient import TestClient + +from app import app + +client = TestClient(app) + + +class TestApp(unittest.TestCase): + def test_read_main(self): + response = client.get("/") + self.assertEqual(response.status_code, 200) + self.assertIn("EDR isobaric from Grib", response.text) + + +if __name__ == "__main__": + unittest.main() diff --git a/app/test_initialize.py b/app/test_initialize.py index 62cb132..4684d7e 100644 --- a/app/test_initialize.py +++ b/app/test_initialize.py @@ -1,7 +1,9 @@ import unittest import os from datetime import datetime -from initialize import build_gribfile_name +from initialize import build_gribfile_name, download_gribfile + +datafile = "" class TestInitialize(unittest.TestCase): @@ -18,6 +20,13 @@ def test_build_gribfile_name2(self): actual = build_gribfile_name(data_path, datetime(2023, 1, 1, 13)) self.assertEqual(expected, actual) + def test_download_gribfile(self): + global datafile + datafile = download_gribfile(data_path="/tmp") + print(datafile) + self.assertTrue(os.path.isfile(datafile)) + os.remove(datafile) + if __name__ == "__main__": unittest.main()