mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 08:26:03 +00:00
test: no seeded admin password, settings changed only for a test, no local libvirt by default
- create_admin had a branch for `"test" in sys.argv` that gave the admin the password "admin"; 17 places signed in with it, and failed silently with ADMIN_PASSWORD set in the environment. The tests now make their own superuser and force_login it, and the shipped code has no test branch: the test runner gives migrate a password (also when ADMIN_PASSWORD is set but empty), so no data/admin_password is written into the checkout. - AccountsTestCase builds its rows in setUpTestData instead of setUpClass and deleting them by hand. - accounts tests set OTP_ENABLED with override_settings instead of assigning settings (one assignment was never undone, so later tests in the process ran with OTP on), and undo their app_settings change. The OTP login class reloads the URLs again only after the setting is off. - computes/tests/test_views.py reached the machine's own libvirt (localhost over the socket) when TEST_LIBVIRT_HOST was unset; its live tests now run only with TEST_LIBVIRT_HOST, like the other live tests, as the README says.
This commit is contained in:
parent
a4ea23004f
commit
ee6b8d3e10
12 changed files with 67 additions and 74 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import contextlib
|
||||
import os
|
||||
import secrets
|
||||
|
||||
from django.db import connections
|
||||
from django.test.runner import DiscoverRunner
|
||||
|
|
@ -28,9 +29,13 @@ class TestRunner(DiscoverRunner):
|
|||
return self.test_suite([suite, *serial])
|
||||
|
||||
def setup_databases(self, **kwargs):
|
||||
# migrate creates the admin user (accounts.apps.create_admin): with a
|
||||
# password given it writes no data/admin_password into the checkout
|
||||
if not os.environ.get("ADMIN_PASSWORD"): # an empty one counts as none
|
||||
os.environ["ADMIN_PASSWORD"] = secrets.token_urlsafe(16)
|
||||
# Django clones a SQLite test database by copying its main file, but
|
||||
# migrate's writes are still in the WAL file (operations/apps.py):
|
||||
# create the database alone, write the WAL back, then clone.
|
||||
# migrate's writes are still in the WAL file (the init_command's
|
||||
# journal mode): create the database alone, write the WAL back, then clone.
|
||||
parallel, self.parallel = self.parallel, 0
|
||||
test_files = [c.settings_dict["TEST"]["NAME"] for c in connections.all() if c.vendor == "sqlite"]
|
||||
for name in filter(None, test_files) if not self.keepdb else ():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue