Merge branch 'Dunedan-404-for-not-existing-servers'

This commit is contained in:
jeffrey forman 2015-04-04 22:08:22 -04:00
commit acd55f34aa
5 changed files with 27 additions and 75 deletions

View File

@ -45,49 +45,6 @@
</tr> </tr>
</table> </table>
<!-- <form class="form-horizontal" action="/delete_record/result/" method="POST"> -->
<!-- {% csrf_token %} -->
<!-- <legend>Delete Record(s)</legend> -->
<!-- <div class="form-group"> -->
<!-- <label class="control-label col-md-2">DNS Server</label> -->
<!-- <div class="controls col-md-10"> -->
<!-- <input type="text" class="form-control" name="dns_server" value="{{ dns_server.hostname }}" readonly /> -->
<!-- </div> -->
<!-- </div> -->
<!-- <div class="form-group"> -->
<!-- <label class="control-label col-md-2">Zone Name</label> -->
<!-- <div class="controls col-md-10"> -->
<!-- <input type="text" class="form-control" name="zone_name" value="{{ zone_name }}" readonly /> -->
<!-- </div> -->
<!-- </div> -->
<!-- <div class="form-group"> -->
<!-- <label class="control-label col-md-2">Record List</label> -->
<!-- <div class="controls col-md-10"> -->
<!-- <select multiple class="form-control" name="rr_list"> -->
<!-- {% for current_rr in rr_list %} -->
<!-- <option selected value="{{current_rr}}" selected>{{current_rr}}</option> -->
<!-- {% endfor %} -->
<!-- </select> -->
<!-- </div> -->
<!-- </div> -->
<!-- <div class="form-group"> -->
<!-- <label class="control-label col-md-2">TSIG Key</label> -->
<!-- <div class="controls col-md-10"> -->
<!-- <select class="form-control" name="key_name"> -->
<!-- {% for key in tsig_keys %} -->
<!-- <option value="{{key.id}}"{% if key == dns_server.default_transfer_key %} selected="selected"{% endif %}>{{key}}</option> -->
<!-- {% empty %} -->
<!-- <option selected="selected" value=""/> -->
<!-- {% endfor %} -->
<!-- </select> -->
<!-- </div> -->
<!-- </div> -->
<!-- <button type="submit" class="btn">Yes, really delete.</button> -->
<input type="text" class="form-control hidden" name="dns_server" value="{{ dns_server.hostname }}"/> <input type="text" class="form-control hidden" name="dns_server" value="{{ dns_server.hostname }}"/>
<input type="text" class="form-control hidden" name="zone_name" value="{{ zone_name }}"/> <input type="text" class="form-control hidden" name="zone_name" value="{{ zone_name }}"/>
<input type="text" class="form-control hidden" name="rr_list" value="{{ rr_list }}"/> <input type="text" class="form-control hidden" name="rr_list" value="{{ rr_list }}"/>

View File

@ -7,7 +7,6 @@ class HelperTests(TestCase):
response = helpers.ip_info("foobar.doesnotexist.local") response = helpers.ip_info("foobar.doesnotexist.local")
self.assertEqual([['Error', u'Unable to resolve foobar.doesnotexist.local: [Errno -2] Name or service not known']], self.assertEqual([['Error', u'Unable to resolve foobar.doesnotexist.local: [Errno -2] Name or service not known']],
response) response)
response = helpers.ip_info("time1.google.com") response = helpers.ip_info("localhost")
self.assertEqual([['IPv4 (1)', u'216.239.32.15'], ['IPv6 (1)', u'2001:4860:4802:32::f']], self.assertEqual([['IPv4 (1)', u'127.0.0.1']],
response) sorted(response))

View File

@ -15,7 +15,7 @@ class Model_BindServer_Tests(TestCase):
def test_BindServerMissingStatisticsPort(self): def test_BindServerMissingStatisticsPort(self):
"""Attempt to add a BindServer without a statistics port.""" """Attempt to add a BindServer without a statistics port."""
bindserver_1 = models.BindServer(hostname="badtest1") bindserver_1 = models.BindServer(hostname="badtest1")
with self.assertRaisesMessage(IntegrityError, "NOT NULL constraint failed: binder_bindserver.statistics_port"): with self.assertRaises(IntegrityError):
bindserver_1.save() bindserver_1.save()
def test_BindServerNonIntStatisticsPort(self): def test_BindServerNonIntStatisticsPort(self):

View File

@ -34,16 +34,16 @@ class GetTests(TestCase):
""" Get a zone list for a server not in the database.""" """ Get a zone list for a server not in the database."""
server_name = "unconfigured.server.net" server_name = "unconfigured.server.net"
response = self.client.get(reverse("server_zone_list", args=(server_name, ))) response = self.client.get(reverse("server_zone_list", args=(server_name, )))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 404)
self.assertContains(response, ('<div class="alert alert-error">Errors were encountered: <br>'
'There is no configured server by that name: unconfigured.server.net </div>'),
html=True)
class PostTests(TestCase): class PostTests(TestCase):
""" Unit Tests that exercise HTTP POST. """ """ Unit Tests that exercise HTTP POST. """
def setUp(self): def setUp(self):
self.client = Client() self.client = Client()
models.BindServer(hostname="testserver.test.net",
statistics_port=1234).save()
def test_DeleteRecordInitial_Empty(self): def test_DeleteRecordInitial_Empty(self):
""" Ensure the initial deletion form works as expected with no RR list. """ """ Ensure the initial deletion form works as expected with no RR list. """
@ -52,13 +52,13 @@ class PostTests(TestCase):
"rr_list" : [] }) "rr_list" : [] })
self.assertContains(response, self.assertContains(response,
'<input type="hidden" name="zone_name" value="testzone1.test.net">', '<input type="text" class="form-control hidden" name="zone_name" value="testzone1.test.net"/>',
html=True) html=True)
self.assertContains(response, self.assertContains(response,
'<input type="hidden" name="rr_list" value="[]">', '<input type="text" class="form-control hidden" name="rr_list" value="[]"/>',
html=True) html=True)
self.assertContains(response, self.assertContains(response,
'<input type="hidden" name="dns_server" value="testserver.test.net" />', '<input type="text" class="form-control hidden" name="dns_server" value="testserver.test.net"/>',
html=True) html=True)
@ -68,13 +68,11 @@ class PostTests(TestCase):
"zone_name" : "testzone1.test.net", "zone_name" : "testzone1.test.net",
"rr_list" : ["testrecord1.testzone1.test.net", "rr_list" : ["testrecord1.testzone1.test.net",
"testrecord2.testzone1.test.net"] }) "testrecord2.testzone1.test.net"] })
self.assertContains(response, self.assertContains(response,
'<input type="hidden" name="zone_name" value="testzone1.test.net">', '<input type="text" class="form-control hidden" name="zone_name" value="testzone1.test.net"/>', html=True)
self.assertContains(response,
'<input type="text" class="form-control hidden" name="rr_list" value="[u&#39;testrecord1.testzone1.test.net&#39;, u&#39;testrecord2.testzone1.test.net&#39;]"/>',
html=True) html=True)
self.assertContains(response, self.assertContains(response,
'<input type="hidden" name="rr_list" value="[u\'testrecord1.testzone1.test.net\', u\'testrecord2.testzone1.test.net\']">', '<input type="text" class="form-control hidden" name="dns_server" value="testserver.test.net"/>',
html=True)
self.assertContains(response,
'<input type="hidden" name="dns_server" value="testserver.test.net" />',
html=True) html=True)

View File

@ -1,7 +1,7 @@
### Binder VIews ### Binder VIews
# 3rd Party # 3rd Party
from django.shortcuts import redirect, render from django.shortcuts import get_object_or_404, redirect, render
# App Imports # App Imports
from binder import exceptions, forms, helpers, models from binder import exceptions, forms, helpers, models
@ -27,15 +27,13 @@ def view_server_zones(request, dns_server):
""" Display the list of DNS zones a particular DNS host provides. """ """ Display the list of DNS zones a particular DNS host provides. """
errors = "" errors = ""
zone_array = {} zone_array = {}
this_server = get_object_or_404(models.BindServer, hostname=dns_server)
try: try:
this_server = models.BindServer.objects.get(hostname=dns_server) zone_array = this_server.list_zones()
except models.BindServer.DoesNotExist, err: except exceptions.ZoneException, err:
errors = "There is no configured server by that name: %s" % dns_server errors = "Unable to list server zones. Error: %s" % err
else:
try:
zone_array = this_server.list_zones()
except exceptions.ZoneException, err:
errors = "Unable to list server zones. Error: %s" % err
return render(request, "bcommon/list_server_zones.html", return render(request, "bcommon/list_server_zones.html",
{ "errors" : errors, { "errors" : errors,
@ -47,7 +45,9 @@ def view_zone_records(request, dns_server, zone_name):
""" Display the list of records for a particular zone. """ """ Display the list of records for a particular zone. """
errors = "" errors = ""
zone_array = {} zone_array = {}
this_server = models.BindServer.objects.get(hostname=dns_server)
this_server = get_object_or_404(models.BindServer, hostname=dns_server)
try: try:
zone_array = this_server.list_zone_records(zone_name) zone_array = this_server.list_zone_records(zone_name)
except exceptions.TransferException, err: except exceptions.TransferException, err:
@ -55,8 +55,6 @@ def view_zone_records(request, dns_server, zone_name):
{ "errors" : err, { "errors" : err,
"zone_name" : zone_name, "zone_name" : zone_name,
"dns_server" : this_server}) "dns_server" : this_server})
except models.BindServer.DoesNotExist:
errors = "Requesting a zone listing for a Bind server that is not configured: %s" % dns_server
return render(request, "bcommon/list_zone.html", return render(request, "bcommon/list_zone.html",
{ "zone_array" : zone_array, { "zone_array" : zone_array,
@ -67,7 +65,7 @@ def view_zone_records(request, dns_server, zone_name):
def view_add_record(request, dns_server, zone_name): def view_add_record(request, dns_server, zone_name):
""" View to provide form to add a DNS record. """ """ View to provide form to add a DNS record. """
this_server = models.BindServer.objects.get(hostname=dns_server) this_server = get_object_or_404(models.BindServer, hostname=dns_server)
return render(request, "bcommon/add_record_form.html", return render(request, "bcommon/add_record_form.html",
{ "dns_server" : this_server, { "dns_server" : this_server,
@ -128,7 +126,7 @@ def view_add_record_result(request):
def view_add_cname_record(request, dns_server, zone_name, record_name): def view_add_cname_record(request, dns_server, zone_name, record_name):
""" Process given input to add a CNAME pointer.""" """ Process given input to add a CNAME pointer."""
this_server = models.BindServer.objects.get(hostname=dns_server) this_server = get_object_or_404(models.BindServer, hostname=dns_server)
return render(request, "bcommon/add_cname_record_form.html", return render(request, "bcommon/add_cname_record_form.html",
{ "dns_server" : this_server, { "dns_server" : this_server,