From f5c36fe2c904a7560264f476b1a72a050192f95d Mon Sep 17 00:00:00 2001 From: "sonu.kumar" Date: Mon, 10 Aug 2015 12:41:18 +0530 Subject: [PATCH] Added test cases for domain's SPF record This patch adds test cases for domain's SPF record form. This also moves BaseRecordFormCleanTests class to __init__.py file that can be imported to new files. Change-Id: Ibda78deb526a531acff91d7ce9ab3af5d329ec01 --- .../tests/test_spf_record_form.py | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 designatedashboard/tests/test_spf_record_form.py diff --git a/designatedashboard/tests/test_spf_record_form.py b/designatedashboard/tests/test_spf_record_form.py new file mode 100644 index 0000000..ceb293f --- /dev/null +++ b/designatedashboard/tests/test_spf_record_form.py @@ -0,0 +1,70 @@ +# Copyright 2015 NEC Corporation. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from designatedashboard import tests + + +class SPFRecordFormTests(tests.BaseRecordFormCleanTests): + + TEXT = 'v=spf1 +all' + + def setUp(self): + super(SPFRecordFormTests, self).setUp() + self.form.cleaned_data['type'] = 'SPF' + self.form.cleaned_data['name'] = self.HOSTNAME + self.form.cleaned_data['txt'] = self.TEXT + + def test_valid_field_values(self): + self.form.clean() + self.assert_no_errors() + + def test_valid_name_field_wild_card(self): + self.form.cleaned_data['name'] = '*' + self.form.clean() + self.assert_no_errors() + + def test_missing_name_field(self): + self.form.cleaned_data['name'] = '' + self.form.clean() + self.assert_no_errors() + + def test_missing_txt_field(self): + self.form.cleaned_data['txt'] = '' + self.form.clean() + self.assert_no_errors() + + def test_invalid_name_field(self): + self.form.cleaned_data['name'] = 'foo-' + self.form.clean() + self.assert_error('name', self.MSG_INVALID_HOSTNAME) + + def test_invalid_name_field_starting_dash(self): + self.form.cleaned_data['name'] = '-ww.foo.com' + self.form.clean() + self.assert_error('name', self.MSG_INVALID_HOSTNAME) + + def test_invalid_name_field_trailing_dash(self): + self.form.cleaned_data['name'] = 'www.foo.co-' + self.form.clean() + self.assert_error('name', self.MSG_INVALID_HOSTNAME) + + def test_invalid_name_field_bad_wild_card(self): + self.form.cleaned_data['name'] = 'derp.*' + self.form.clean() + self.assert_error('name', self.MSG_INVALID_HOSTNAME) + + def test_outside_of_domain_name_field(self): + self.form.cleaned_data['name'] = 'www.bar.com.' + self.form.clean() + self.assert_error('name', self.MSG_INVALID_HOSTNAME)