Skip to content

Commit 29f29e4

Browse files
committed
Use format options for functional tests
Use the format options for functional tests so we can have more assertEquals and less assertIn. Change-Id: I34e6c76b42964f7b596ea35e6b0354a242611cb4
1 parent d39b9c9 commit 29f29e4

3 files changed

Lines changed: 72 additions & 2 deletions

File tree

‎.testr.conf‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
66

77
test_id_option=--load-list $IDFILE
88
test_list_option=--list
9+
group_regex=([^\.]+\.)+

‎functional/common/test.py‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828

2929
def execute(cmd, fail_ok=False, merge_stderr=False):
3030
"""Executes specified command for the given action."""
31-
cmd = shlex.split(cmd.encode('utf-8'))
31+
cmdlist = shlex.split(cmd.encode('utf-8'))
3232
result = ''
3333
result_err = ''
3434
stdout = subprocess.PIPE
3535
stderr = subprocess.STDOUT if merge_stderr else subprocess.PIPE
36-
proc = subprocess.Popen(cmd, stdout=stdout, stderr=stderr)
36+
proc = subprocess.Popen(cmdlist, stdout=stdout, stderr=stderr)
3737
result, result_err = proc.communicate()
3838
if not fail_ok and proc.returncode != 0:
3939
raise exceptions.CommandFailed(proc.returncode, cmd, result,
@@ -50,6 +50,33 @@ def openstack(cls, cmd, fail_ok=False):
5050
"""Executes openstackclient command for the given action."""
5151
return execute('openstack ' + cmd, fail_ok=fail_ok)
5252

53+
@classmethod
54+
def get_show_opts(cls, fields=[]):
55+
return ' -f value ' + ' '.join(['-c ' + it for it in fields])
56+
57+
@classmethod
58+
def get_list_opts(cls, headers=[]):
59+
opts = ' -f csv --quote none '
60+
opts = opts + ' '.join(['-c ' + it for it in headers])
61+
return opts
62+
63+
@classmethod
64+
def assertOutput(cls, expected, actual):
65+
if expected != actual:
66+
raise Exception(expected + ' != ' + actual)
67+
68+
@classmethod
69+
def assertInOutput(cls, expected, actual):
70+
if expected not in actual:
71+
raise Exception(expected + ' not in ' + actual)
72+
73+
@classmethod
74+
def cleanup_tmpfile(cls, filename):
75+
try:
76+
os.remove(filename)
77+
except OSError:
78+
pass
79+
5380
def assert_table_structure(self, items, field_names):
5481
"""Verify that all items have keys listed in field_names."""
5582
for item in items:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import uuid
14+
15+
from functional.common import test
16+
17+
18+
class ContainerTests(test.TestCase):
19+
"""Functional tests for object containers. """
20+
NAME = uuid.uuid4().hex
21+
22+
@classmethod
23+
def setUpClass(cls):
24+
opts = cls.get_list_opts(['container'])
25+
raw_output = cls.openstack('container create ' + cls.NAME + opts)
26+
expected = 'container\n' + cls.NAME + '\n'
27+
cls.assertOutput(expected, raw_output)
28+
29+
@classmethod
30+
def tearDownClass(cls):
31+
raw_output = cls.openstack('container delete ' + cls.NAME)
32+
cls.assertOutput('', raw_output)
33+
34+
def test_container_list(self):
35+
opts = self.get_list_opts(['Name'])
36+
raw_output = self.openstack('container list' + opts)
37+
self.assertIn(self.NAME, raw_output)
38+
39+
def test_container_show(self):
40+
opts = self.get_show_opts(['container'])
41+
raw_output = self.openstack('container show ' + self.NAME + opts)
42+
self.assertEqual(self.NAME + "\n", raw_output)

0 commit comments

Comments
 (0)