-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure static dir exists and clean up after the test
- Loading branch information
1 parent
98ebf87
commit 0fb44f9
Showing
1 changed file
with
11 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
import os | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
os.environ["NO_DEVICE"] = "1" | ||
|
||
import pytest | ||
if not os.path.exists("static"): | ||
os.makedirs("static") | ||
|
||
from api.ws import app | ||
from fastapi.testclient import TestClient | ||
|
||
client = TestClient(app) | ||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def ensure_static_files_exist(): | ||
if not os.path.exists("static"): | ||
os.makedirs("static") | ||
if not os.path.exists("static/index.html"): | ||
with open("static/index.html", "w") as f: | ||
f.write("<html></html>") | ||
yield | ||
os.remove("static/index.html") | ||
os.rmdir("static") | ||
|
||
|
||
def test_serves_html_on_root(): | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
assert "<html>" in response.text | ||
assert "<html>" in response.text |