Skip to content

Commit

Permalink
fix: ensure static dir exists and clean up after the test
Browse files Browse the repository at this point in the history
  • Loading branch information
builder555 committed Nov 5, 2024
1 parent 98ebf87 commit 0fb44f9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions server/api/test_server.py
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

0 comments on commit 0fb44f9

Please sign in to comment.