diff --git a/.vscode/settings.json b/.vscode/settings.json index cbff4d9..ff4a908 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,9 +2,5 @@ "[python]": { "editor.defaultFormatter": "ms-python.autopep8", }, - "python.testing.pytestArgs": [ - "tests" - ], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true + "python.testing.unittestEnabled": true } \ No newline at end of file diff --git a/README.md b/README.md index 9a9ce54..113e09c 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ python3 -m venv .venv source .venv/bin/activate # prepare the environment -pip3 install -e . +pip3 install -e '.[dev]' # run the server from within the virtual environment cd src/ diff --git a/setup.py b/setup.py index 7a91d65..96f7774 100644 --- a/setup.py +++ b/setup.py @@ -38,9 +38,9 @@ def read_version(fname="src/whisper_api/version.py"): include_package_data=True, extras_require={ "dev": [ - "pytest", - "pre-commit", - "autopep8" + "autopep8", + "httpx", + "pre-commit" ] }, ) diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_frontend.py b/test/test_frontend.py new file mode 100644 index 0000000..68e2aac --- /dev/null +++ b/test/test_frontend.py @@ -0,0 +1,43 @@ +import unittest +from fastapi.testclient import TestClient +from whisper_api import app + +""" +Test that the frontend files are served correctly. +""" + +client = TestClient(app) + + +class TestFrontend(unittest.TestCase): + + def test_index_html(self): + """ + Test that the index.html file is served correctly. + """ + response = client.get("/index.html") + assert response.status_code == 200 + assert response.headers["content-type"] == "text/html; charset=utf-8" + + def test_script_js(self): + """ + Test that the script.js file is served correctly. + """ + response = client.get("/script.js") + assert response.status_code == 200 + assert response.headers["content-type"] == "text/javascript; charset=utf-8" + + def test_styles_css(self): + """ + Test that the styles.css file is served correctly. + """ + response = client.get("/styles.css") + assert response.status_code == 200 + assert response.headers["content-type"] == "text/css; charset=utf-8" + + def test_not_found(self): + """ + Test that a 404 error is returned when a file is not found. + """ + response = client.get("/not_found") + assert response.status_code == 404 diff --git a/test/test_import.py b/test/test_import.py new file mode 100644 index 0000000..af17afb --- /dev/null +++ b/test/test_import.py @@ -0,0 +1,11 @@ +import unittest + + +class TestImport(unittest.TestCase): + + def test_import_whisper_api(self): + try: + import whisper_api + assert whisper_api + except ImportError: + unittest.fail("Failed to import whisper_api") diff --git a/tests/test_frontend.py b/tests/test_frontend.py deleted file mode 100644 index e66cd9b..0000000 --- a/tests/test_frontend.py +++ /dev/null @@ -1,45 +0,0 @@ -import pytest -from fastapi.testclient import TestClient -from whisper_api import app - - -""" -Test that the frontend files are served correctly. -""" - -client = TestClient(app) - - -def test_index_html(): - """ - Test that the index.html file is served correctly. - """ - response = client.get("/index.html") - assert response.status_code == 200 - assert response.headers["content-type"] == "text/html; charset=utf-8" - - -def test_script_js(): - """ - Test that the script.js file is served correctly. - """ - response = client.get("/script.js") - assert response.status_code == 200 - assert response.headers["content-type"] == "application/javascript" - - -def test_styles_css(): - """ - Test that the styles.css file is served correctly. - """ - response = client.get("/styles.css") - assert response.status_code == 200 - assert response.headers["content-type"] == "text/css; charset=utf-8" - - -def test_not_found(): - """ - Test that a 404 error is returned when a file is not found. - """ - response = client.get("/not_found") - assert response.status_code == 404 diff --git a/tests/test_import.py b/tests/test_import.py deleted file mode 100644 index a598f99..0000000 --- a/tests/test_import.py +++ /dev/null @@ -1,9 +0,0 @@ -import pytest - - -def test_import_whisper_api(): - try: - import whisper_api - assert whisper_api - except ImportError: - pytest.fail("Failed to import whisper_api")