Return a better error message(security_groups)

When creating a security group, whose name contains
other chars than numbers and letters, a non supportive error
message is thrown.

Fixes bug 1085888

Change-Id: I58ab57be29c0935dbfd10831fbaf97d09f654781
This commit is contained in:
Matthias Runge
2012-12-03 12:30:39 +01:00
parent 155e3ae7c3
commit 146eef477b
2 changed files with 18 additions and 0 deletions

View File

@@ -34,6 +34,10 @@ from openstack_dashboard import api
class CreateGroup(forms.SelfHandlingForm):
name = forms.CharField(label=_("Name"),
error_messages={
'required': _('This field is required.'),
'invalid': _("The string may only contain"
" ASCII characters and numbers.")},
validators=[validators.validate_slug])
description = forms.CharField(label=_("Description"))

View File

@@ -81,6 +81,20 @@ class SecurityGroupsViewTests(test.TestCase):
self.assertMessageCount(error=1)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_create_security_groups_post_wrong_name(self):
sec_group = self.security_groups.first()
self.mox.StubOutWithMock(api, 'security_group_create')
fail_name = sec_group.name + ' invalid'
self.mox.ReplayAll()
formData = {'method': 'CreateGroup',
'name': fail_name,
'description': sec_group.description}
res = self.client.post(SG_CREATE_URL, formData)
self.assertTemplateUsed(res,
'project/access_and_security/security_groups/create.html')
self.assertContains(res, "ASCII")
def test_edit_rules_get(self):
sec_group = self.security_groups.first()
sec_group_list = self.security_groups.list()