Add unit tests for add cname form and add record form testing
This commit is contained in:
parent
3a9e9fe614
commit
acd9ec596c
|
@ -32,7 +32,7 @@ class FormAddRecord(forms.Form):
|
||||||
record_name = forms.RegexField(max_length=100, regex="^[a-zA-Z0-9-_]+$", required=False)
|
record_name = forms.RegexField(max_length=100, regex="^[a-zA-Z0-9-_]+$", required=False)
|
||||||
record_type = forms.ChoiceField(choices=local_settings.RECORD_TYPE_CHOICES)
|
record_type = forms.ChoiceField(choices=local_settings.RECORD_TYPE_CHOICES)
|
||||||
zone_name = forms.CharField(max_length=100)
|
zone_name = forms.CharField(max_length=100)
|
||||||
record_data = forms.GenericIPAddressField()
|
record_data = forms.GenericIPAddressField() # TODO: Change to this a non-empty valid-data regex field.
|
||||||
ttl = forms.ChoiceField(choices=local_settings.TTL_CHOICES)
|
ttl = forms.ChoiceField(choices=local_settings.TTL_CHOICES)
|
||||||
create_reverse = forms.BooleanField(required=False)
|
create_reverse = forms.BooleanField(required=False)
|
||||||
key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False)
|
key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False)
|
||||||
|
|
|
@ -29,7 +29,25 @@ class Form_Tests(TestCase):
|
||||||
testform_2 = forms.FormAddRecord(form_data)
|
testform_2 = forms.FormAddRecord(form_data)
|
||||||
self.assertTrue(testform_2.is_valid())
|
self.assertTrue(testform_2.is_valid())
|
||||||
|
|
||||||
def test_Invalid_FormAddRecord(self):
|
|
||||||
|
def test_MissingData_FormAddRecord(self):
|
||||||
|
""" Submit FormAddRecord with missing record_data."""
|
||||||
|
form_data = {"dns_server":"server1",
|
||||||
|
"record_name":"record1",
|
||||||
|
"record_type": "A",
|
||||||
|
"zone_name":"domain.local",
|
||||||
|
"record_data":"",
|
||||||
|
"ttl": 300,
|
||||||
|
"key_name":None,
|
||||||
|
"create_reverse":True}
|
||||||
|
|
||||||
|
expected_form_errors = {"record_data": [u"This field is required."]}
|
||||||
|
testform = forms.FormAddRecord(form_data)
|
||||||
|
testform.is_valid()
|
||||||
|
self.assertFalse(testform.is_valid())
|
||||||
|
self.assertEquals(expected_form_errors, testform.errors)
|
||||||
|
|
||||||
|
def test_InvalidValue_FormAddRecord(self):
|
||||||
""" Pass FormAddRecord invalid values, compare error response dicts."""
|
""" Pass FormAddRecord invalid values, compare error response dicts."""
|
||||||
form_data = {"dns_server":"server1",
|
form_data = {"dns_server":"server1",
|
||||||
"record_name":"record1$$$",
|
"record_name":"record1$$$",
|
||||||
|
@ -62,3 +80,16 @@ class Form_Tests(TestCase):
|
||||||
testform_1 = forms.FormDeleteRecord(delete_dict)
|
testform_1 = forms.FormDeleteRecord(delete_dict)
|
||||||
testform_1.is_valid
|
testform_1.is_valid
|
||||||
self.assertTrue(testform_1.errors)
|
self.assertTrue(testform_1.errors)
|
||||||
|
|
||||||
|
def test_MissingName_AddCnameForm(self):
|
||||||
|
"""Attempt to submit a cname add form missing the cname value."""
|
||||||
|
form_dict = { "dns_server" : "testserver1",
|
||||||
|
"zone_name" : "domain1.local",
|
||||||
|
"originating_record" : "record1.domain1.local",
|
||||||
|
"cname" : "",
|
||||||
|
"ttl" : 300 }
|
||||||
|
expected_form_errors = { "cname" : [u"This field is required."] }
|
||||||
|
testform_1 = forms.FormAddCnameRecord(form_dict)
|
||||||
|
testform_1.is_valid()
|
||||||
|
self.assertTrue(testform_1.errors)
|
||||||
|
self.assertEquals(testform_1.errors, expected_form_errors)
|
||||||
|
|
|
@ -143,6 +143,7 @@ def view_add_cname_result(request):
|
||||||
"originating_record" : request.POST["originating_record"],
|
"originating_record" : request.POST["originating_record"],
|
||||||
"form_data" : request.POST,
|
"form_data" : request.POST,
|
||||||
"form_errors" : form.errors,
|
"form_errors" : form.errors,
|
||||||
|
"ttl_choices" : local_settings.TTL_CHOICES,
|
||||||
"tsig_keys" : models.Key.objects.all() })
|
"tsig_keys" : models.Key.objects.all() })
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue