Merge "Add functional tests for blacklists"
This commit is contained in:
commit
dca1ccba74
@ -222,8 +222,43 @@ class TLDCommands(object):
|
||||
return self.parsed_cmd(cmd, FieldValueModel, *args, **kwargs)
|
||||
|
||||
|
||||
class BlacklistCommands(object):
|
||||
|
||||
def zone_blacklist_list(self, *args, **kwargs):
|
||||
cmd = 'zone blacklist list'
|
||||
return self.parsed_cmd(cmd, ListModel, *args, **kwargs)
|
||||
|
||||
def zone_blacklist_create(self, pattern, description=None, *args,
|
||||
**kwargs):
|
||||
options_str = build_option_string({
|
||||
'--pattern': pattern,
|
||||
'--description': description,
|
||||
})
|
||||
cmd = 'zone blacklist create {0}'.format(options_str)
|
||||
return self.parsed_cmd(cmd, FieldValueModel, *args, **kwargs)
|
||||
|
||||
def zone_blacklist_set(self, id, pattern=None, description=None,
|
||||
no_description=False, *args, **kwargs):
|
||||
options_str = build_option_string({
|
||||
'--pattern': pattern,
|
||||
'--description': description,
|
||||
})
|
||||
flags_str = build_flags_string({'--no_description': no_description})
|
||||
cmd = 'zone blacklist set {0} {1} {2}'.format(id, options_str,
|
||||
flags_str)
|
||||
return self.parsed_cmd(cmd, FieldValueModel, *args, **kwargs)
|
||||
|
||||
def zone_blacklist_show(self, id, *args, **kwargs):
|
||||
cmd = 'zone blacklist show {0}'.format(id)
|
||||
return self.parsed_cmd(cmd, FieldValueModel, *args, **kwargs)
|
||||
|
||||
def zone_blacklist_delete(self, id, *args, **kwargs):
|
||||
cmd = 'zone blacklist delete {0}'.format(id)
|
||||
return self.parsed_cmd(cmd, FieldValueModel, *args, **kwargs)
|
||||
|
||||
|
||||
class DesignateCLI(base.CLIClient, ZoneCommands, ZoneTransferCommands,
|
||||
RecordsetCommands, TLDCommands):
|
||||
RecordsetCommands, TLDCommands, BlacklistCommands):
|
||||
|
||||
# instantiate this once to minimize requests to keystone
|
||||
_CLIENTS = None
|
||||
|
@ -31,3 +31,7 @@ def random_zone_name(name='testdomain', tld='com'):
|
||||
|
||||
def random_a_recordset_name(zone_name, recordset_name='testrecord'):
|
||||
return "{0}{1}.{2}".format(recordset_name, random_digits(), zone_name)
|
||||
|
||||
|
||||
def random_blacklist(name='testblacklist'):
|
||||
return '{0}{1}'.format(name, random_digits())
|
||||
|
@ -115,3 +115,23 @@ class TLDFixture(BaseFixture):
|
||||
client.tld_delete(tld_id)
|
||||
except CommandFailed:
|
||||
pass
|
||||
|
||||
|
||||
class BlacklistFixture(BaseFixture):
|
||||
"""See DesignateCLI.zone_blacklist_create for __init__ args"""
|
||||
|
||||
def __init__(self, user='admin', *args, **kwargs):
|
||||
super(BlacklistFixture, self).__init__(user=user, *args, **kwargs)
|
||||
|
||||
def _setUp(self):
|
||||
super(BlacklistFixture, self)._setUp()
|
||||
self.blacklist = self.client.zone_blacklist_create(*self.args,
|
||||
**self.kwargs)
|
||||
self.addCleanup(self.cleanup_blacklist, self.client, self.blacklist.id)
|
||||
|
||||
@classmethod
|
||||
def cleanup_blacklist(cls, client, blacklist_id):
|
||||
try:
|
||||
client.zone_blacklist_delete(blacklist_id)
|
||||
except CommandFailed:
|
||||
pass
|
||||
|
98
designateclient/functionaltests/v2/test_blacklist.py
Normal file
98
designateclient/functionaltests/v2/test_blacklist.py
Normal file
@ -0,0 +1,98 @@
|
||||
"""
|
||||
Copyright 2015 Rackspace
|
||||
|
||||
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 tempest_lib.exceptions import CommandFailed
|
||||
|
||||
from designateclient.functionaltests.base import BaseDesignateTest
|
||||
from designateclient.functionaltests.datagen import random_blacklist
|
||||
from designateclient.functionaltests.v2.fixtures import BlacklistFixture
|
||||
|
||||
|
||||
class TestBlacklist(BaseDesignateTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestBlacklist, self).setUp()
|
||||
pattern = random_blacklist()
|
||||
self.blacklist = self.useFixture(BlacklistFixture(
|
||||
pattern=pattern,
|
||||
description='A random blacklist',
|
||||
)).blacklist
|
||||
|
||||
self.assertEqual(self.blacklist.pattern, pattern)
|
||||
self.assertEqual(self.blacklist.description, 'A random blacklist')
|
||||
|
||||
def test_zone_blacklist_list(self):
|
||||
blacklists = self.clients.as_user('admin').zone_blacklist_list()
|
||||
self.assertGreater(len(blacklists), 0)
|
||||
|
||||
def test_zone_blacklist_create_and_show(self):
|
||||
client = self.clients.as_user('admin')
|
||||
blacklist = client.zone_blacklist_show(self.blacklist.id)
|
||||
|
||||
self.assertEqual(self.blacklist.created_at, blacklist.created_at)
|
||||
self.assertEqual(self.blacklist.description, blacklist.description)
|
||||
self.assertEqual(self.blacklist.id, blacklist.id)
|
||||
self.assertEqual(self.blacklist.pattern, blacklist.pattern)
|
||||
self.assertEqual(self.blacklist.updated_at, blacklist.updated_at)
|
||||
|
||||
def test_zone_blacklist_delete(self):
|
||||
client = self.clients.as_user('admin')
|
||||
client.zone_blacklist_delete(self.blacklist.id)
|
||||
self.assertRaises(CommandFailed, client.zone_blacklist_show,
|
||||
self.blacklist.id)
|
||||
|
||||
def test_zone_blacklist_set(self):
|
||||
client = self.clients.as_user('admin')
|
||||
updated_pattern = random_blacklist('updatedblacklist')
|
||||
blacklist = client.zone_blacklist_set(
|
||||
id=self.blacklist.id,
|
||||
pattern=updated_pattern,
|
||||
description='An updated blacklist',
|
||||
)
|
||||
|
||||
self.assertEqual(blacklist.created_at, self.blacklist.created_at)
|
||||
self.assertEqual(blacklist.description, 'An updated blacklist')
|
||||
self.assertEqual(blacklist.id, self.blacklist.id)
|
||||
self.assertEqual(blacklist.pattern, updated_pattern)
|
||||
self.assertNotEqual(blacklist.updated_at, self.blacklist.updated_at)
|
||||
|
||||
def test_zone_blacklist_set_no_description(self):
|
||||
client = self.clients.as_user('admin')
|
||||
blacklist = client.zone_blacklist_set(
|
||||
id=self.blacklist.id,
|
||||
no_description=True,
|
||||
)
|
||||
self.assertEqual(blacklist.description, 'None')
|
||||
|
||||
def test_cannot_set_description_with_no_description_flag(self):
|
||||
client = self.clients.as_user('admin')
|
||||
self.assertRaises(CommandFailed, client.zone_blacklist_set,
|
||||
self.blacklist.id,
|
||||
pattern=random_blacklist(),
|
||||
description='new description',
|
||||
no_description=True)
|
||||
|
||||
|
||||
class TestBlacklistNegative(BaseDesignateTest):
|
||||
|
||||
def test_invalid_blacklist_command(self):
|
||||
client = self.clients.as_user('admin')
|
||||
cmd = 'zone blacklist notacommand'
|
||||
self.assertRaises(CommandFailed, client.openstack, cmd)
|
||||
|
||||
def test_blacklist_create_invalid_flag(self):
|
||||
client = self.clients.as_user('admin')
|
||||
cmd = 'zone blacklist create --pattern helloworld --notaflag invalid'
|
||||
self.assertRaises(CommandFailed, client.openstack, cmd)
|
Loading…
x
Reference in New Issue
Block a user