mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +00:00
fix(virtsecrets): the create dialog offers only the usage types it can create
The usage list of the create-secret dialog came from the map that names the usage types of existing secrets, so it offered none and tls too; the form takes ceph, volume and iscsi only, and picking none or tls always failed with "Select a valid choice". The dialog now lists the form's own choices.
This commit is contained in:
parent
8c1d7d33bb
commit
084f2e8b60
3 changed files with 21 additions and 4 deletions
|
|
@ -37,8 +37,8 @@
|
|||
<label for="secret_usage_type" class="col-sm-3 col-form-label">{% trans "Usage" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<select id="secret_usage_type" name="usage_type" class="form-control">
|
||||
{% for key, usage_type in secret_usage_types.items %}
|
||||
<option value="{{ usage_type }}">{{ usage_type }}</option>
|
||||
{% for value, label in usage_choices %}
|
||||
<option value="{{ value }}">{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,12 @@ volume path, an iSCSI IQN or a Ceph name, and characters XML gives a meaning."""
|
|||
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
from lxml import etree
|
||||
from computes.models import Compute
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import SimpleTestCase, TestCase
|
||||
from django.urls import reverse
|
||||
from lxml import etree, html
|
||||
from virtsecrets.forms import AddSecret
|
||||
from vrtManager.virtsecrets import wvmSecrets
|
||||
|
||||
|
||||
|
|
@ -46,3 +50,14 @@ class SecretValueTests(SimpleTestCase):
|
|||
with self.subTest(value=value), self.assertRaises(ValueError):
|
||||
conn.set_secret_value("uuid", value)
|
||||
secret.setValue.assert_not_called()
|
||||
|
||||
|
||||
class CreateSecretDialogTests(TestCase):
|
||||
def test_the_dialog_offers_the_usage_types_the_form_takes(self):
|
||||
compute = Compute.objects.create(name="secret-usage", hostname="localhost", login="", password="", type=4)
|
||||
self.client.force_login(get_user_model().objects.create_superuser("usage", "usage@example.com", "pw"))
|
||||
with patch("virtsecrets.views.wvmSecrets") as conn:
|
||||
conn.return_value.get_secrets.return_value = []
|
||||
response = self.client.get(reverse("virtsecrets", args=[compute.id]))
|
||||
offered = html.fromstring(response.content).xpath("//select[@id='secret_usage_type']/option/@value")
|
||||
self.assertEqual(offered, [value for value, _ in AddSecret.base_fields["usage_type"].choices])
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ def secrets(request, compute_id):
|
|||
VIR_SECRET_USAGE_TYPE_ISCSI: "iscsi",
|
||||
VIR_SECRET_USAGE_TYPE_TLS: "tls",
|
||||
}
|
||||
# the create dialog offers the usage types the form takes
|
||||
usage_choices = AddSecret.base_fields["usage_type"].choices
|
||||
|
||||
try:
|
||||
conn = wvmSecrets(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue