Debian Codegraph @

glanceclient/tests/functional/v1/test_readonly_glance.py

raw symbols SCIP
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 re
14
15 from tempest.lib import exceptions
16
17 from glanceclient.tests.functional import base
18
19
20 class SimpleReadOnlyGlanceClientTest(base.ClientTestBase):
21
22 """Read only functional python-glanceclient tests.
23
24 This only exercises client commands that are read only.
25 """
26
27 def test_list_v1(self):
28 out = self.glance('--os-image-api-version 1 image-list')
29 endpoints = self.parser.listing(out)
30 self.assertTableStruct(endpoints, [
31 'ID', 'Name', 'Disk Format', 'Container Format',
32 'Size', 'Status'])
33
34 def test_fake_action(self):
35 self.assertRaises(exceptions.CommandFailed,
36 self.glance,
37 'this-does-not-exist')
38
39 def test_member_list_v1(self):
40 tenant_name = '--tenant-id %s' % self.creds['project_name']
41 out = self.glance('--os-image-api-version 1 member-list',
42 params=tenant_name)
43 endpoints = self.parser.listing(out)
44 self.assertTableStruct(endpoints,
45 ['Image ID', 'Member ID', 'Can Share'])
46
47 def test_help(self):
48 help_text = self.glance('--os-image-api-version 1 help')
49 lines = help_text.split('\n')
50 self.assertFirstLineStartsWith(lines, 'usage: glance')
51
52 commands = []
53 cmds_start = lines.index('Positional arguments:')
54 try:
55 # Starting in Python 3.10, argparse displays options in the
56 # "Options:" section...
57 cmds_end = lines.index('Options:')
58 except ValueError:
59 # ... but before Python 3.10, options were displayed in the
60 # "Optional arguments:" section.
61 cmds_end = lines.index('Optional arguments:')
62 command_pattern = re.compile(r'^ {4}([a-z0-9\-\_]+)')
63 for line in lines[cmds_start:cmds_end]:
64 match = command_pattern.match(line)
65 if match:
66 commands.append(match.group(1))
67 commands = set(commands)
68 wanted_commands = {'bash-completion', 'help',
69 'image-create', 'image-delete',
70 'image-download', 'image-list',
71 'image-show', 'image-update',
72 'member-create', 'member-delete',
73 'member-list'}
74 self.assertEqual(commands, wanted_commands)
75
76 def test_version(self):
77 self.glance('', flags='--version')
78
79 def test_debug_list(self):
80 self.glance('--os-image-api-version 1 image-list', flags='--debug')