summaryrefslogtreecommitdiff
path: root/glanceclient/tests
diff options
context:
space:
mode:
authorCyril Roelandt <cyril@redhat.com>2022-09-20 18:05:33 +0200
committerCyril Roelandt <cyril@redhat.com>2022-09-26 23:54:06 +0200
commit74fa43665719ddc830999fa15bb052a87d69dd14 (patch)
treee46021b5db3a919b166ff653bf9cbcb52158b151 /glanceclient/tests
parent9e8fcdb92ed41594fe458b0976e9e29387849262 (diff)
downloadpython-glanceclient-74fa43665719ddc830999fa15bb052a87d69dd14.tar.gz
schema_args: Do not generate option for read-only properties
The schema_args decorator generates command line options based on the properties defined in a schema. This commit makes sure read-only properties are skipped during this process, since trying to modify their value would result in a Glance error. Closes-Bug: #1561828 Change-Id: I7ccc628a23c9ebdaeedcb9e6d43559f497ce9555
Diffstat (limited to 'glanceclient/tests')
-rw-r--r--glanceclient/tests/unit/test_utils.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/glanceclient/tests/unit/test_utils.py b/glanceclient/tests/unit/test_utils.py
index 46cefbf..db08a1c 100644
--- a/glanceclient/tests/unit/test_utils.py
+++ b/glanceclient/tests/unit/test_utils.py
@@ -191,12 +191,17 @@ class TestUtils(testtools.TestCase):
def schema_getter(_type='string', enum=False):
prop = {
'type': ['null', _type],
- 'readOnly': True,
'description': 'Test schema',
}
+ prop_readonly = {
+ 'type': ['null', _type],
+ 'readOnly': True,
+ 'description': 'Test schema read-only',
+ }
if enum:
prop['enum'] = [None, 'opt-1', 'opt-2']
+ prop_readonly['enum'] = [None, 'opt-ro-1', 'opt-ro-2']
def actual_getter():
return {
@@ -205,6 +210,7 @@ class TestUtils(testtools.TestCase):
'name': 'test_schema',
'properties': {
'test': prop,
+ 'readonly-test': prop_readonly,
}
}
@@ -214,6 +220,7 @@ class TestUtils(testtools.TestCase):
pass
decorated = utils.schema_args(schema_getter())(dummy_func)
+ self.assertEqual(len(decorated.__dict__['arguments']), 1)
arg, opts = decorated.__dict__['arguments'][0]
self.assertIn('--test', arg)
self.assertEqual(encodeutils.safe_decode, opts['type'])