mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 04:06:47 +00:00
test: each app keeps its tests in a tests package
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.
This commit is contained in:
parent
0906838193
commit
c55f52f025
154 changed files with 27 additions and 39 deletions
40
webvirtcloud/tests/test_logging.py
Normal file
40
webvirtcloud/tests/test_logging.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
"""The app log is bounded (rotates) and written to a deterministic absolute
|
||||
path, not the process working directory."""
|
||||
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class LoggingConfigTestCase(TestCase):
|
||||
def test_default_handler_rotates(self):
|
||||
handler = settings.LOGGING["handlers"]["default"]
|
||||
self.assertEqual(handler["class"], "logging.handlers.RotatingFileHandler")
|
||||
self.assertGreater(handler["maxBytes"], 0)
|
||||
self.assertGreater(handler["backupCount"], 0)
|
||||
|
||||
def test_log_path_is_absolute_and_not_cwd(self):
|
||||
handler = settings.LOGGING["handlers"]["default"]
|
||||
self.assertTrue(os.path.isabs(handler["filename"]), handler["filename"])
|
||||
|
||||
def test_missing_log_directory_is_created_on_settings_import(self):
|
||||
# A clean checkout / CI / Docker build may not have the log's parent dir;
|
||||
# importing settings (logging config) must create it, not crash.
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
tmp = tempfile.mkdtemp()
|
||||
log = os.path.join(tmp, "nested", "wvc.log")
|
||||
env = {
|
||||
**os.environ,
|
||||
"WEBVIRTCLOUD_LOG_FILE": log,
|
||||
"DJANGO_SETTINGS_MODULE": "webvirtcloud.settings",
|
||||
}
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", "import django; django.setup()"],
|
||||
env=env, capture_output=True, text=True,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertTrue(os.path.isdir(os.path.dirname(log)), log)
|
||||
Loading…
Add table
Add a link
Reference in a new issue