Resource value modification enhanced in the fuel2

Now it is possible to set whole resource value through fuel2
using --value and --type without --key.

Partial-Bug: #1644814
Change-Id: Iea3c949c86e1376cfdfafbc86f7e3e3a4f5e1516
(cherry picked from commit 9f3302d26d)
This commit is contained in:
Alexander Kislitsky 2016-12-09 11:28:16 +03:00
parent 75ac77ead6
commit c548853225
2 changed files with 31 additions and 10 deletions

View File

@ -129,14 +129,7 @@ class Set(ResourcesCommand):
return parser
def verify_arguments(self, parsed_args):
if parsed_args.key is None: # no key
if parsed_args.value is not None or parsed_args.type is not None:
raise Exception("--value and --type arguments make sense only "
"with --key argument.")
if parsed_args.format is None:
raise Exception("Please specify format of data passed to stdin"
" to replace whole resource data.")
elif parsed_args.value is not None: # have key and value
if parsed_args.value is not None: # have value
if parsed_args.format is not None:
raise Exception("You shouldn't specify --format if you pass "
"value in command line, specify --type "
@ -148,7 +141,7 @@ class Set(ResourcesCommand):
raise Exception("Please specify type of value passed in "
"--value argument to properly represent it"
" in the storage.")
elif parsed_args.type != 'null': # have key but no value
elif parsed_args.type != 'null': # have no value
if parsed_args.type is not None:
raise Exception("--type specifies type for value provided in "
"--value but there is not --value argument")

View File

@ -115,7 +115,7 @@ class TestGet(testscenarios.WithScenarios, _BaseCLITest):
self.assertEqual(self.expected_result, self.cli.stdout.getvalue())
class TestSet(testscenarios.WithScenarios, _BaseCLITest):
class TestSetWithStdin(testscenarios.WithScenarios, _BaseCLITest):
scenarios = [
(s[0],
dict(zip(('args', 'expected_body', 'stdin'), s[1])))
@ -147,6 +147,34 @@ class TestSet(testscenarios.WithScenarios, _BaseCLITest):
self.assertEqual(self.expected_body, req_history[-1].json())
class TestSet(testscenarios.WithScenarios, _BaseCLITest):
scenarios = [
(s[0],
dict(zip(('args', 'expected_body'), s[1])))
for s in [
('json', ('--type json --value "aaa"', 'aaa')),
('yaml', ('--type yaml --value "aaa"', 'aaa'))
]
]
args = None
expected_body = None
url_last_part = 'values'
cmd = 'set'
def test_set(self):
url = self.BASE_URL + '/environments/1/lvl1/value1/resources/1/' + \
self.url_last_part
self.req_mock.put(url)
args = [self.cmd] + ("--env 1 --level lvl1=value1 --resource 1 " +
self.args).split()
self.cli.run(args)
req_history = self.req_mock.request_history
self.assertEqual('PUT', req_history[-1].method)
self.assertEqual(self.expected_body, req_history[-1].json())
class TestSetKeys(testscenarios.WithScenarios, _BaseCLITest):
scenarios = [
(s[0],