mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 12:16: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:
parent
a4ea23004f
commit
ee6b8d3e10
12 changed files with 67 additions and 74 deletions
|
|
@ -1,7 +1,8 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.messages import get_messages
|
||||
from django.test import RequestFactory, TestCase
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from computes.models import Compute
|
||||
|
|
@ -12,7 +13,8 @@ from vrtManager.util import OperationError
|
|||
|
||||
class SetRootPassTestCase(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)
|
||||
self.compute = Compute.objects.create(
|
||||
name="test_compute_root_pass",
|
||||
hostname="localhost",
|
||||
|
|
@ -73,9 +75,8 @@ class SetRootPassTestCase(TestCase):
|
|||
@patch.object(Instance, "proxy")
|
||||
def test_unreachable_gstfsd_is_an_error_message_not_a_crash(self, mock_proxy, gstfsd):
|
||||
from accounts.models import UserSSHKey
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
admin = get_user_model().objects.get(username="admin")
|
||||
admin = self.admin
|
||||
key = UserSSHKey.objects.create(user=admin, keyname="k", keypublic="ssh-ed25519 AAAA k")
|
||||
mock_proxy.instance.name.return_value = "root-pass-vm"
|
||||
mock_proxy.get_status.return_value = 5
|
||||
|
|
@ -94,11 +95,12 @@ class GuestAgentAccessTestCase(TestCase):
|
|||
from accounts.models import UserSSHKey
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
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)
|
||||
compute = Compute.objects.create(name="agent-compute", hostname="192.0.2.1", type=1)
|
||||
self.instance = Instance.objects.create(compute=compute, name="agent-vm",
|
||||
uuid="11111111-2222-3333-4444-555555555555")
|
||||
admin = get_user_model().objects.get(username="admin")
|
||||
admin = self.admin
|
||||
self.key = UserSSHKey.objects.create(user=admin, keyname="laptop", keypublic="ssh-ed25519 AAAA laptop")
|
||||
patcher = patch.object(Instance, "proxy")
|
||||
self.proxy = patcher.start()
|
||||
|
|
@ -175,7 +177,8 @@ class OsInfoErrorTestCase(TestCase):
|
|||
answer in time is an error answer, not a server error."""
|
||||
|
||||
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)
|
||||
compute = Compute.objects.create(name="osinfo-compute", hostname="192.0.2.1", type=1)
|
||||
self.instance = Instance.objects.create(compute=compute, name="osinfo-vm",
|
||||
uuid="22222222-3333-4444-5555-666666666666")
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from django.contrib.auth import get_user_model
|
|||
from django.contrib.auth.models import Permission
|
||||
from django.http.response import Http404
|
||||
from django.shortcuts import reverse
|
||||
from django.test import RequestFactory, TestCase
|
||||
from django.test import TestCase
|
||||
from vrtManager.create import wvmCreate
|
||||
from vrtManager.util import randomUUID
|
||||
|
||||
|
|
@ -124,7 +124,8 @@ class InstancesTestCase(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)
|
||||
self.rsa_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC6OOdbfv27QVnSC6sKxGaHb6YFc+3gxCkyVR3cTSXE/n5BEGf8aOgBpepULWa1RZfxYHY14PlKULDygdXSdrrR2kNSwoKz/Oo4d+3EE92L7ocl1+djZbptzgWgtw1OseLwbFik+iKlIdqPsH+IUQvX7yV545ZQtAP8Qj1R+uCqkw== test@test"
|
||||
|
||||
def test_index(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue