Merge "Fix unit tests under Django 1.9"

This commit is contained in:
Jenkins 2016-03-29 12:51:24 +00:00 committed by Gerrit Code Review
commit ed6815d2cd
7 changed files with 61 additions and 83 deletions

View File

@ -1,67 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Copyright 2012 Nebula, Inc.
#
# 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 api
from openstack_dashboard.test import helpers as test
from designatedashboard.dashboards.project.dns_domains import forms
class BaseRecordFormCleanTests(test.TestCase):
DOMAIN_NAME = 'foo.com.'
HOSTNAME = 'www'
MSG_FIELD_REQUIRED = 'This field is required'
MSG_INVALID_HOSTNAME = 'Enter a valid hostname. The '\
'hostname should contain letters '\
'and numbers, and be no more than '\
'63 characters.'
MSG_INVALID_HOSTNAME_SHORT = 'Enter a valid hostname'
def setUp(self):
super(BaseRecordFormCleanTests, self).setUp()
# Request object with messages support
self.request = self.factory.get('', {})
# Set-up form instance
kwargs = {}
kwargs['initial'] = {'domain_name': self.DOMAIN_NAME}
self.form = forms.RecordCreate(self.request, **kwargs)
self.form._errors = {}
self.form.cleaned_data = {
'domain_name': self.DOMAIN_NAME,
'name': '',
'data': '',
'txt': '',
'priority': None,
'ttl': None,
}
def assert_no_errors(self):
self.assertEqual(self.form._errors, {})
def assert_error(self, field, msg):
self.assertIn(msg, self.form._errors[field])
def assert_required_error(self, field):
self.assert_error(field, self.MSG_FIELD_REQUIRED)

View File

@ -20,6 +20,11 @@ import os
import fixtures import fixtures
import testtools import testtools
from openstack_dashboard.test import helpers as test
from designatedashboard.dashboards.project.dns_domains import forms
_TRUE_VALUES = ('True', 'true', '1', 'yes') _TRUE_VALUES = ('True', 'true', '1', 'yes')
@ -51,3 +56,45 @@ class TestCase(testtools.TestCase):
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
self.log_fixture = self.useFixture(fixtures.FakeLogger()) self.log_fixture = self.useFixture(fixtures.FakeLogger())
class BaseRecordFormCleanTests(test.TestCase):
DOMAIN_NAME = 'foo.com.'
HOSTNAME = 'www'
MSG_FIELD_REQUIRED = 'This field is required'
MSG_INVALID_HOSTNAME = 'Enter a valid hostname. The '\
'hostname should contain letters '\
'and numbers, and be no more than '\
'63 characters.'
MSG_INVALID_HOSTNAME_SHORT = 'Enter a valid hostname'
def setUp(self):
super(BaseRecordFormCleanTests, self).setUp()
# Request object with messages support
self.request = self.factory.get('', {})
# Set-up form instance
kwargs = {}
kwargs['initial'] = {'domain_name': self.DOMAIN_NAME}
self.form = forms.RecordCreate(self.request, **kwargs)
self.form._errors = {}
self.form.cleaned_data = {
'domain_name': self.DOMAIN_NAME,
'name': '',
'data': '',
'txt': '',
'priority': None,
'ttl': None,
}
def assert_no_errors(self):
self.assertEqual(self.form._errors, {})
def assert_error(self, field, msg):
self.assertIn(msg, self.form._errors[field])
def assert_required_error(self, field):
self.assert_error(field, self.MSG_FIELD_REQUIRED)

View File

@ -51,7 +51,7 @@ LOGGING = {
'handlers': { 'handlers': {
'null': { 'null': {
'level': 'DEBUG', 'level': 'DEBUG',
'class': 'django.utils.log.NullHandler', 'class': 'logging.NullHandler'
}, },
}, },
'loggers': { 'loggers': {

View File

@ -22,9 +22,7 @@ from __future__ import unicode_literals
from django.core.urlresolvers import reverse # noqa from django.core.urlresolvers import reverse # noqa
# from django import http # from django import http
from mox import IsA # noqa from designatedashboard.tests import base
from designatedashboard import tests
DOMAIN_ID = '123' DOMAIN_ID = '123'
# INDEX_URL = reverse('horizon:project:dns_domains:index') # INDEX_URL = reverse('horizon:project:dns_domains:index')
@ -78,7 +76,7 @@ DOMAIN_ID = '123'
# self.assertEqual(len(res.context['table'].data), len(records)) # self.assertEqual(len(res.context['table'].data), len(records))
class ARecordFormTests(tests.BaseRecordFormCleanTests): class ARecordFormTests(base.BaseRecordFormCleanTests):
IPV4 = '1.1.1.1' IPV4 = '1.1.1.1'
@ -140,7 +138,7 @@ class ARecordFormTests(tests.BaseRecordFormCleanTests):
self.assert_error('data', self.MSG_INVALID_IPV4) self.assert_error('data', self.MSG_INVALID_IPV4)
class AAAARecordFormTests(tests.BaseRecordFormCleanTests): class AAAARecordFormTests(base.BaseRecordFormCleanTests):
IPV6 = '1111:1111:1111:11::1' IPV6 = '1111:1111:1111:11::1'
@ -202,7 +200,7 @@ class AAAARecordFormTests(tests.BaseRecordFormCleanTests):
self.assert_error('data', self.MSG_INVALID_IPV6) self.assert_error('data', self.MSG_INVALID_IPV6)
class CNAMERecordFormTests(tests.BaseRecordFormCleanTests): class CNAMERecordFormTests(base.BaseRecordFormCleanTests):
CNAME = 'bar.foo.com.' CNAME = 'bar.foo.com.'
@ -262,7 +260,7 @@ class CNAMERecordFormTests(tests.BaseRecordFormCleanTests):
self.assert_error('data', self.MSG_INVALID_HOSTNAME_SHORT) self.assert_error('data', self.MSG_INVALID_HOSTNAME_SHORT)
class MXRecordFormTests(tests.BaseRecordFormCleanTests): class MXRecordFormTests(base.BaseRecordFormCleanTests):
MAIL_SERVER = 'mail.foo.com.' MAIL_SERVER = 'mail.foo.com.'
PRIORITY = 10 PRIORITY = 10
@ -297,7 +295,7 @@ class MXRecordFormTests(tests.BaseRecordFormCleanTests):
self.assertEqual(self.DOMAIN_NAME, self.form.cleaned_data['name']) self.assertEqual(self.DOMAIN_NAME, self.form.cleaned_data['name'])
class TXTRecordFormTests(tests.BaseRecordFormCleanTests): class TXTRecordFormTests(base.BaseRecordFormCleanTests):
TEXT = 'Lorem ipsum' TEXT = 'Lorem ipsum'
@ -356,7 +354,7 @@ class TXTRecordFormTests(tests.BaseRecordFormCleanTests):
self.assertEqual(self.TEXT, self.form.cleaned_data['data']) self.assertEqual(self.TEXT, self.form.cleaned_data['data'])
class SRVRecordFormTests(tests.BaseRecordFormCleanTests): class SRVRecordFormTests(base.BaseRecordFormCleanTests):
SRV_NAME = '_foo._tcp.' SRV_NAME = '_foo._tcp.'
SRV_DATA = '1 1 srv.foo.com.' SRV_DATA = '1 1 srv.foo.com.'

View File

@ -12,10 +12,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from designatedashboard import tests from designatedashboard.tests import base
class PTRRecordFormTests(tests.BaseRecordFormCleanTests): class PTRRecordFormTests(base.BaseRecordFormCleanTests):
PTR = "6.0.0.10.in-addr.arpa." PTR = "6.0.0.10.in-addr.arpa."

View File

@ -12,10 +12,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from designatedashboard import tests from designatedashboard.tests import base
class SPFRecordFormTests(tests.BaseRecordFormCleanTests): class SPFRecordFormTests(base.BaseRecordFormCleanTests):
TEXT = 'v=spf1 +all' TEXT = 'v=spf1 +all'

View File

@ -12,10 +12,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from designatedashboard import tests from designatedashboard.tests import base
class SSHFPRecordFormTests(tests.BaseRecordFormCleanTests): class SSHFPRecordFormTests(base.BaseRecordFormCleanTests):
TEXT = '2 1 d1eb0d876ec69d18bcefc4263ae43ec33ae14f4c' TEXT = '2 1 d1eb0d876ec69d18bcefc4263ae43ec33ae14f4c'
MSG_INVALID_RECORD = "Enter a valid SSHFP record" MSG_INVALID_RECORD = "Enter a valid SSHFP record"