Merge dev to main: Security improvements and comprehensive test infrastructure #39
@@ -223,4 +223,14 @@ app.include_router(opc_projects.router, prefix="/api/opc",
|
||||
app.add_api_websocket_route("/ws/terminal", terminal.ws_endpoint)
|
||||
app.add_api_websocket_route("/ws/opc", opc_ws.websocket_endpoint)
|
||||
|
||||
app.mount("/", StaticFiles(directory="/app/static", html=True), name="static")
|
||||
# Mount static files (skip if directory doesn't exist, e.g., in test environments)
|
||||
import os
|
||||
if os.path.isdir("/app/static"):
|
||||
app.mount("/", StaticFiles(directory="/app/static", html=True), name="static")
|
||||
else:
|
||||
# In test environment, create a minimal fallback
|
||||
import tempfile
|
||||
_test_static = tempfile.mkdtemp()
|
||||
with open(os.path.join(_test_static, "index.html"), "w") as f:
|
||||
f.write("<html><body>Test Environment</body></html>")
|
||||
app.mount("/", StaticFiles(directory=_test_static, html=True), name="static")
|
||||
|
||||
@@ -143,20 +143,10 @@ def mock_httpx_client():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_app(mock_config, temp_auth_file, temp_rbac_file, mock_docker_client, tmp_path):
|
||||
def test_app(mock_config, temp_auth_file, temp_rbac_file, mock_docker_client):
|
||||
"""Create FastAPI test client with mocked dependencies."""
|
||||
# Create dummy static directory for tests
|
||||
static_dir = tmp_path / "static"
|
||||
static_dir.mkdir()
|
||||
(static_dir / "index.html").write_text("<html><body>Test</body></html>")
|
||||
|
||||
# Patch Docker client and static directory before importing main
|
||||
with patch("docker.DockerClient", return_value=mock_docker_client), \
|
||||
patch("main.StaticFiles") as mock_static:
|
||||
# Make StaticFiles work with our test directory
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
mock_static.return_value = StaticFiles(directory=str(static_dir), html=True)
|
||||
|
||||
# Patch Docker client before importing main
|
||||
with patch("docker.DockerClient", return_value=mock_docker_client):
|
||||
from main import app
|
||||
client = TestClient(app)
|
||||
yield client
|
||||
|
||||
Reference in New Issue
Block a user