1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 19:26:48 +00:00
webvirtcloud/computes/tests/test_compute_password.py
catborise c55f52f025 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.
2026-10-12 15:17:30 +03:00

28 lines
1.2 KiB
Python

"""The compute form never shows the stored password: a password left empty
on an edit keeps it, a new one replaces it."""
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse
from computes.models import Compute
class ComputePasswordTests(TestCase):
def setUp(self):
self.client.force_login(get_user_model().objects.create_superuser("cp-admin", "cp@example.com", "pw"))
def edit(self, compute, password):
data = {"name": compute.name, "hostname": compute.hostname, "login": "admin", "password": password,
"type": compute.type, "details": ""}
self.client.post(reverse("compute_update", args=[compute.id]), data)
compute.refresh_from_db()
return compute.password
def test_an_empty_password_keeps_the_stored_one(self):
for conn_type in (1, 3): # TCP, TLS
with self.subTest(type=conn_type):
compute = Compute.objects.create(name=f"cp{conn_type}", hostname="10.0.0.7", login="admin",
password="secret", type=conn_type)
self.assertEqual(self.edit(compute, ""), "secret")
self.assertEqual(self.edit(compute, "other"), "other")