1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-09 11:46:49 +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:
catborise 2026-11-06 11:17:59 +03:00
parent a4ea23004f
commit ee6b8d3e10
12 changed files with 67 additions and 74 deletions

View file

@ -1,8 +1,9 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission, User
from django.core.exceptions import ObjectDoesNotExist
from django.db import connection
from django.shortcuts import reverse
from django.test import RequestFactory, TestCase
from django.test import TestCase
from django.test.utils import CaptureQueriesContext
from lxml import html
@ -12,7 +13,8 @@ from logs.models import Logs
class AdminTestCase(TestCase):
def setUp(self):
self.client.login(request=RequestFactory().get("/"), username="admin", password="admin")
self.admin = get_user_model().objects.create_superuser("tests-admin", "admin@example.com", "pw")
self.client.force_login(self.admin)
Logs.objects.all().delete() # the login's row
def test_group_list(self):
@ -63,7 +65,7 @@ class AdminTestCase(TestCase):
page = html.fromstring(self.client.get(reverse("admin:group_update", args=[group.id])).content)
boxes = page.xpath("//div[contains(@class, 'searchable')]/label")
names = [box.text_content().split()[0] for box in boxes]
self.assertEqual(names, ["zed", "admin", "amy", "bob"])
self.assertEqual(names, ["zed", "admin", "amy", "bob", "tests-admin"])
self.assertIn("Amy Adams", boxes[2].get("data-search"))
self.assertEqual(page.xpath("//input[@id='filter']/@data-forget"), [""])
self.assertEqual(page.xpath("//form[@id='create-update']//button[@type='submit']/text()"), ["Save changes"])