Add integration tests for adding and deleting records. and add cname test

Also added fixtures for binder_test
This commit is contained in:
Jeffrey Forman 2012-12-04 22:45:01 -05:00
parent bd65e1b239
commit 7fc67cb542
5 changed files with 97 additions and 4 deletions

View File

@ -0,0 +1 @@
[{"pk": 1, "model": "binder.key", "fields": {"data": "wtfrrfiiWT9bbqKL0LlYPA==", "name": "test-key-incorrect", "algorithm": "hmac-md5"}}, {"pk": 2, "model": "binder.key", "fields": {"data": "tooshort", "name": "test-key-tooshort", "algorithm": "hmac-md5"}}, {"pk": 3, "model": "binder.key", "fields": {"data": "kTcmbjZNULvw3qnyZwq5sw==", "name": "test-key", "algorithm": "hmac-md5"}}, {"pk": 4, "model": "binder.key", "fields": {"data": "5TcmbjZ2mLvw3u9yZwq5sw41", "name": "unknown-key", "algorithm": "hmac-md5"}}, {"pk": 2, "model": "binder.bindserver", "fields": {"statistics_port": 1234, "hostname": "testserver1", "default_transfer_key": null}}]

View File

@ -2,3 +2,5 @@ from forms import *
from helpers import *
from models import *
from views import *
from integration import *

View File

@ -2,9 +2,9 @@ from django.test import TestCase
from binder import forms
class FormTests(TestCase):
class Form_Tests(TestCase):
def test_Valid_FormAddRecord(self):
"""Test FOrmAddRecord with valid data, with/without create_reverse."""
"""Test FormAddRecord with valid data, with/without create_reverse."""
form_data = {"dns_server":"server1",
"record_name":"record1",
"record_type":"A",
@ -48,3 +48,17 @@ class FormTests(TestCase):
testform_2.is_valid()
self.assertFalse(testform_2.is_valid())
self.assertEquals(expected_form_errors, testform_2.errors)
def test_Validation_FormDeleteRecord(self):
"""Validate good data in the FormDeleteRecord form."""
delete_dict = { "dns_server" : "foo.net",
"zone_name" : "domain1.local",
"rr_list" : '[u"record1.domain1.local", u"record2.domain1.local"]',
}
testform_1 = forms.FormDeleteRecord(delete_dict)
testform_1.is_valid
self.assertFalse(testform_1.errors)
delete_dict["rr_list"] = '[record1.domain1.local", u"record2.domain1.local"]'
testform_1 = forms.FormDeleteRecord(delete_dict)
testform_1.is_valid
self.assertTrue(testform_1.errors)

View File

@ -0,0 +1,78 @@
from django.test import TestCase
from django.test.client import Client
from binder import helpers, models
class Integration_Tests(TestCase):
fixtures = [ "binder/fixtures/binder_test.json" ]
def setUp(self):
self.client = Client()
self.testserver = models.BindServer.objects.get(hostname="testserver1").hostname
def test_Integration_Add_Record(self):
"""Add forward and reverse record on domain1.local."""
add_dict = { "dns_server" : self.testserver,
"record_name" : "record1",
"record_type" : "A",
"zone_name" : "domain1.local",
"record_data" : "10.254.1.101",
"ttl" : 86400,
"create_reverse" : True}
response = self.client.post("/add_record/result/", add_dict)
self.assertEqual(response.status_code, 200)
# Make sure that we get two responses (fwd/rev) back from the server.
self.assertEqual(len(response.context["response"]), 2)
for current_response in response.context["response"]:
dns_update_output = str(current_response["output"])
self.assertRegexpMatches(dns_update_output, "opcode UPDATE")
self.assertRegexpMatches(dns_update_output, "rcode NOERROR")
def test_Integration_Delete_Record(self):
"""Delete record1.domain1.local"""
delete_dict = { "dns_server" : self.testserver,
"zone_name" : "domain1.local",
"rr_list" : '[u"record1.domain1.local", u"record2.domain1.local"]',
}
response = self.client.post("/delete_record/result/", delete_dict)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["response"]), 2)
for current_response in response.context["response"]:
dns_update_output = str(current_response["output"])
self.assertRegexpMatches(dns_update_output, "opcode UPDATE")
self.assertRegexpMatches(dns_update_output, "rcode NOERROR")
def test_Integration_Add_Cname(self):
""" Add CNAME cnametest1 after adding associated A record record1."""
add_dict = { "dns_server" : self.testserver,
"record_name" : "record1",
"record_type" : "A",
"zone_name" : "domain1.local",
"record_data" : "10.254.1.101",
"ttl" : 86400,
"create_reverse" : False}
response = self.client.post("/add_record/result/", add_dict)
self.assertEqual(response.status_code, 200)
# Make sure that we get two responses (fwd/rev) back from the server.
self.assertEqual(len(response.context["response"]), 1)
for current_response in response.context["response"]:
dns_update_output = str(current_response["output"])
self.assertRegexpMatches(dns_update_output, "opcode UPDATE")
self.assertRegexpMatches(dns_update_output, "rcode NOERROR")
cname_dict = { "dns_server" : self.testserver,
"originating_record" : "record1.domain1.local",
"cname" : "cnametest1",
"zone_name" : "domain1.local",
"ttl" : 86400,
}
response = self.client.post("/add_cname_record/result/", cname_dict)
self.assertEqual(response.status_code, 200)
for current_response in response.context["response"]:
dns_update_output = str(current_response["output"])
self.assertRegexpMatches(dns_update_output, "opcode UPDATE")
self.assertRegexpMatches(dns_update_output, "rcode NOERROR")

View File

@ -38,7 +38,6 @@ class GetTests(TestCase):
html=True)
class PostTests(TestCase):
""" Unit Tests that exercise HTTP POST. """
def setUp(self):
@ -90,4 +89,3 @@ class HelperTests(TestCase):
response = helpers.ip_info("ds.test-ipv6.com")
self.assertEqual([['IPv4 (1)', u'216.218.228.114'], ['IPv6 (1)', u'2001:470:1:18::2']],
response)