mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
131 test modules sat next to the code they test; instances alone had 51 of them beside views.py and utils.py. They move into a tests/ package per app, and the JavaScript checks into webvirtcloud/tests/js. Each non-empty tests.py becomes tests/test_views.py; the empty generated stubs are removed. Imports of the app's own modules become absolute, paths built from __file__ go one level up, the live helper is instances.tests.livetest, and coverage omits */tests/*. The suite discovers the same 960 tests as before.
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import os
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent.parent
|
|
SOCKETIOD = ROOT / "console" / "socketiod"
|
|
|
|
|
|
class SocketiodDisabledTestCase(unittest.TestCase):
|
|
"""socketiod must refuse to start unless explicitly enabled."""
|
|
|
|
def test_socketiod_exits_when_serial_console_disabled(self):
|
|
# The settings module lives in a temporary directory, so the test does
|
|
# not write into the source tree (read-only checkouts, --parallel).
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
(Path(tmp) / "socketiod_disabled_settings.py").write_text(
|
|
"from webvirtcloud.settings import * # noqa\n"
|
|
"SERIAL_CONSOLE_ENABLED = False\n"
|
|
"SOCKETIO_HOST = '127.0.0.1'\n"
|
|
"SOCKETIO_PORT = 0\n"
|
|
)
|
|
env = dict(
|
|
os.environ,
|
|
DJANGO_SETTINGS_MODULE="socketiod_disabled_settings",
|
|
PYTHONPATH=os.pathsep.join([tmp, str(ROOT)]),
|
|
)
|
|
try:
|
|
result = subprocess.run(
|
|
[sys.executable, str(SOCKETIOD)],
|
|
cwd=ROOT,
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=20,
|
|
)
|
|
except subprocess.TimeoutExpired:
|
|
self.fail("socketiod kept running although SERIAL_CONSOLE_ENABLED=False")
|
|
self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
|
|
self.assertIn("SERIAL_CONSOLE_ENABLED", result.stderr)
|