Commit first round of unit tests (14), all pass!
This commit is contained in:
parent
bb40ef2d6a
commit
a3f0a643a1
|
@ -1,3 +1,4 @@
|
|||
from forms import *
|
||||
from helpers import *
|
||||
from models import *
|
||||
from views import *
|
||||
from helpers import *
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
from django.test import TestCase
|
||||
|
||||
from binder import forms
|
||||
|
||||
class FormTests(TestCase):
|
||||
def test_Valid_FormAddRecord(self):
|
||||
"""Test FOrmAddRecord with valid data, with/without create_reverse."""
|
||||
form_data = {"dns_server":"server1",
|
||||
"record_name":"record1",
|
||||
"record_type":"A",
|
||||
"zone_name":"domain.local",
|
||||
"record_data":"10.254.254.254",
|
||||
"ttl":3600,
|
||||
"key_name": None,
|
||||
"create_reverse" : False}
|
||||
|
||||
testform_1 = forms.FormAddRecord(form_data)
|
||||
self.assertTrue(testform_1.is_valid())
|
||||
|
||||
form_data = {"dns_server":"server1",
|
||||
"record_name":"record1",
|
||||
"record_type":"A",
|
||||
"zone_name":"domain.local",
|
||||
"record_data":"10.254.254.254",
|
||||
"ttl":3600,
|
||||
"key_name":None,
|
||||
"create_reverse":True}
|
||||
|
||||
testform_2 = forms.FormAddRecord(form_data)
|
||||
self.assertTrue(testform_2.is_valid())
|
||||
|
||||
def test_InValid_FormAddRecord(self):
|
||||
""" Pass FormAddRecord invalid values, compare error response dicts."""
|
||||
form_data = {"dns_server":"server1",
|
||||
"record_name":"record1$$$",
|
||||
"record_type":123,
|
||||
"zone_name":"domain.local",
|
||||
"record_data":"A.B.C.D",
|
||||
"ttl":"A",
|
||||
"key_name":None,
|
||||
"create_reverse":True}
|
||||
|
||||
expected_form_errors = {"record_data": [u"Enter a valid IPv4 or IPv6 address."],
|
||||
"record_name": [u"Enter a valid value."],
|
||||
"ttl": [u"Enter a whole number."]}
|
||||
testform_2 = forms.FormAddRecord(form_data)
|
||||
testform_2.is_valid()
|
||||
self.assertFalse(testform_2.is_valid())
|
||||
self.assertEquals(expected_form_errors, testform_2.errors)
|
|
@ -1,13 +1,14 @@
|
|||
from django.test import TestCase
|
||||
from django.db import IntegrityError
|
||||
|
||||
from binder import models
|
||||
|
||||
class ModelTests(TestCase):
|
||||
def test_EmptyBindServerModel(self):
|
||||
class Model_BindServer_Tests(TestCase):
|
||||
def test_BindServerModel(self):
|
||||
"""Test that adding a well-formed BindServer works."""
|
||||
self.assertEqual(models.BindServer.objects.count(), 0)
|
||||
bindserver_1 = models.BindServer(hostname="test1",
|
||||
statistics_port=1234)
|
||||
statistics_port=1234)
|
||||
bindserver_1.save()
|
||||
self.assertEqual(models.BindServer.objects.count(), 1)
|
||||
|
||||
|
@ -23,3 +24,18 @@ class ModelTests(TestCase):
|
|||
statistics_port="bar1")
|
||||
with self.assertRaisesMessage(ValueError, "invalid literal for int() with base 10: 'bar1'"):
|
||||
bindserver_1.save()
|
||||
|
||||
|
||||
class Model_Key_Tests(TestCase):
|
||||
def test_KeyModel(self):
|
||||
""" Test that adding a well-formed Key works."""
|
||||
self.assertEqual(models.Key.objects.count(), 0)
|
||||
key_1 = models.Key(name="testkey1",
|
||||
data="abc123",
|
||||
algorithm="MD5")
|
||||
key_1.save()
|
||||
self.assertEqual(models.Key.objects.count(), 1)
|
||||
|
||||
def test_NonExistantKey(self):
|
||||
with self.assertRaisesMessage(models.Key.DoesNotExist, "Key matching query does not exist"):
|
||||
this_key = models.Key.objects.get(name="does_not_exist")
|
||||
|
|
|
@ -18,7 +18,7 @@ class GetTests(TestCase):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_GetResultRedirects(self):
|
||||
""" Expected Output: Redirect to / """
|
||||
""" GETing a /result/ URL should always redirect to /. """
|
||||
response = self.client.get("/add_record/result/", follow=True)
|
||||
self.assertRedirects(response, "/")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
@ -30,7 +30,7 @@ class GetTests(TestCase):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_GetInvalidServer(self):
|
||||
""" Attempt to get a zone list for a server not in the database."""
|
||||
""" Get a zone list for a server not in the database."""
|
||||
response = self.client.get("/info/unconfigured.server.net/")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, ('<div class="alert alert-error">Errors were encountered: <br>'
|
||||
|
|
Loading…
Reference in New Issue