Initial setup for command line tests

Created a cli structure for testing command line client.

Part of this involved refactoring the base.py so that it could be
shared between client and command line tests.

Added basic help subcommand tests to show the flow between
behaviors and tests.

Change-Id: Ia3af13e90b3689c0c2ca5447ead0fb7fc33de086
This commit is contained in:
Steve Heyman 2015-04-10 18:55:15 -05:00
parent 302c4f19cd
commit 8083923114
10 changed files with 147 additions and 67 deletions

View File

@ -15,6 +15,7 @@ limitations under the License.
"""
import os
from oslo.config import cfg
from tempest import config
@ -33,3 +34,12 @@ if os.path.exists(conf_file):
CONF.set_config_path(conf_file)
CONF.register_group(cfg.OptGroup('keymanager'))
CONF.register_opt(cfg.StrOpt('url'), group='keymanager')
CONF.register_opt(cfg.StrOpt('username'), group='keymanager')
CONF.register_opt(cfg.StrOpt('password'), group='keymanager')
CONF.register_opt(cfg.StrOpt('project_name'), group='keymanager')
CONF.register_opt(cfg.StrOpt('project_id'), group='keymanager')
CONF.register_opt(cfg.IntOpt('max_payload_size', default=10000),
group='keymanager')
CONF.register_opt(cfg.StrOpt('project_domain_name'), group='keymanager')

51
functionaltests/base.py Normal file
View File

@ -0,0 +1,51 @@
"""
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.
"""
import logging
import os
import oslotest.base as oslotest
from barbicanclient import client
from keystoneclient.auth import identity
from keystoneclient import session
from tempest import config
CONF = config.CONF
class BaseTestCase(oslotest.BaseTestCase):
max_payload_size = CONF.keymanager.max_payload_size
max_sized_payload = u'a' * max_payload_size
oversized_payload = 'a' * (max_payload_size + 1)
max_field_size = 255
max_sized_field = 'a' * max_field_size
oversized_field = 'a' * (max_field_size + 1)
@classmethod
def setUpClass(cls):
cls.LOG = logging.getLogger(cls._get_full_case_name())
super(BaseTestCase, cls).setUpClass()
def tearDown(self):
super(BaseTestCase, self).tearDown()
self.LOG.info('Finished: %s\n', self._testMethodName)
@classmethod
def _get_full_case_name(cls):
name = '{module}:{case_name}'.format(
module=cls.__module__,
case_name=cls.__name__
)
return name

View File

View File

@ -0,0 +1,46 @@
"""
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.
"""
import exceptions as exc
from functionaltests.base import BaseTestCase
from barbicanclient import barbican
class CmdLineTestCase(BaseTestCase):
def setUp(self):
self.LOG.info('Starting: %s', self._testMethodName)
super(CmdLineTestCase, self).setUp()
self.cmdline_client = barbican.Barbican()
def issue_barbican_command(self, argv):
""" Issue the barbican command and return its output.
:param argv: dict of keyword arguments to pass to the command. This
does NOT include "barbican" - that's not needed.
:return: list of strings returned by the command, one list element
per line of output. This means the caller doesn't have to worry about
parsing newlines, etc. If there is a problem then this method
will return None
"""
result = None
try:
self.cmdline_client.run(argv)
except exc.SystemExit:
result = self.cmdline_client.stdout.getvalue()
return result

View File

View File

View File

@ -0,0 +1,38 @@
# Copyright (c) 2015 Rackspace, 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 functionaltests.cli.base import CmdLineTestCase
from functionaltests import utils
from testtools import testcase
@utils.parameterized_test_case
class HelpTestCase(CmdLineTestCase):
def setUp(self):
super(HelpTestCase, self).setUp()
def tearDown(self):
super(HelpTestCase, self).tearDown()
@utils.parameterized_dataset({
'dash_h': [['-h']],
'doubledash_help': [['--help']]
})
@testcase.attr('positive')
def test_help(self, argv):
result = self.issue_barbican_command(argv)
self.assertIsNotNone(result, "{0} returned None".format(argv))
self.assertGreater(len(result), 0, "{0} invalid length".format(argv))

View File

@ -1,36 +0,0 @@
"""
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.
"""
import os
from oslo.config import cfg
from tempest import config
CONF = config.CONF
# Use local tempest conf if one is available.
# This usually means we're running tests outside of devstack
if os.path.exists('./etc/functional_tests.conf'):
CONF.set_config_path('./etc/functional_tests.conf')
CONF.register_group(cfg.OptGroup('keymanager'))
CONF.register_opt(cfg.StrOpt('url'), group='keymanager')
CONF.register_opt(cfg.StrOpt('username'), group='keymanager')
CONF.register_opt(cfg.StrOpt('password'), group='keymanager')
CONF.register_opt(cfg.StrOpt('project_name'), group='keymanager')
CONF.register_opt(cfg.StrOpt('project_id'), group='keymanager')
CONF.register_opt(cfg.IntOpt('max_payload_size', default=10000),
group='keymanager')
CONF.register_opt(cfg.StrOpt('project_domain_name'), group='keymanager')

View File

@ -14,9 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import logging
import os
import oslotest.base as oslotest
from functionaltests.base import BaseTestCase
from barbicanclient import client
from keystoneclient.auth import identity
from keystoneclient import session
@ -24,24 +23,8 @@ from tempest import config
CONF = config.CONF
# Use local tempest conf if one is available.
# This usually means we're running tests outside of devstack
if os.path.exists('./etc/functional_tests.conf'):
CONF.set_config_path('./etc/functional_tests.conf')
class TestCase(oslotest.BaseTestCase):
max_payload_size = CONF.keymanager.max_payload_size
max_sized_payload = u'a' * max_payload_size
oversized_payload = 'a' * (max_payload_size + 1)
max_field_size = 255
max_sized_field = 'a' * max_field_size
oversized_field = 'a' * (max_field_size + 1)
@classmethod
def setUpClass(cls):
cls.LOG = logging.getLogger(cls._get_full_case_name())
super(TestCase, cls).setUpClass()
class TestCase(BaseTestCase):
def setUp(self):
self.LOG.info('Starting: %s', self._testMethodName)
@ -67,15 +50,3 @@ class TestCase(oslotest.BaseTestCase):
endpoint=CONF.keymanager.url,
project_id=CONF.keymanager.project_id,
session=self.sess)
def tearDown(self):
super(TestCase, self).tearDown()
self.LOG.info('Finished: %s\n', self._testMethodName)
@classmethod
def _get_full_case_name(cls):
name = '{module}:{case_name}'.format(
module=cls.__module__,
case_name=cls.__name__
)
return name