Commit 4a25486d authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Fix IntArgument + tests and apply to snf-astakos

parent b8698ae4
......@@ -213,9 +213,14 @@ class IntArgument(ValueArgument):
@value.setter
def value(self, newvalue):
if newvalue == self.default:
self._value = newvalue
return
try:
self._value = self.default if (
newvalue == self.default) else int(newvalue)
if int(newvalue) == float(newvalue):
self._value = int(newvalue)
else:
raise ValueError('Raise int argument error')
except ValueError:
raiseCLIError(CLISyntaxError(
'IntArgument Error',
......
......@@ -228,14 +228,16 @@ class IntArgument(TestCase):
def test_value(self):
ia = argument.IntArgument(parsed_name='--ia')
self.assertEqual(ia.value, None)
for v in (1, 0, -1, 923455555555555555555555555555555):
for v in (1, 0, -1):
ia.value = v
self.assertEqual(ia.value, v)
for v in ('1', '-1', 2.8):
for v in ('1', '-1'):
ia.value = v
self.assertEqual(ia.value, int(v))
for v, err in (
('invalid', errors.CLIError),
(2.8, errors.CLIError),
(923455555555555555555555555555555, errors.CLIError),
(None, TypeError), (False, TypeError), ([1, 2, 3], TypeError)):
try:
ia.value = v
......
......@@ -43,7 +43,7 @@ from kamaki.cli.commands import (
_command_init, errors, _optional_json, addLogSettings)
from kamaki.cli.command_tree import CommandTree
from kamaki.cli.utils import print_dict, format_size
from kamaki.cli.argument import FlagArgument, ValueArgument
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument
from kamaki.cli.argument import CommaSeparatedListArgument
from kamaki.cli.logger import get_logger
......@@ -655,7 +655,7 @@ class project_application_list(_astakos_init, _optional_json):
"""List all applications (old and new)"""
arguments = dict(
project=ValueArgument('Filter by project id', '--with-project-id')
project=IntArgument('Filter by project id', '--with-project-id')
)
@errors.generic.all
......@@ -732,16 +732,13 @@ class project_membership_list(_astakos_init, _optional_json):
"""List all memberships"""
arguments = dict(
project=ValueArgument('Filter by project id', '--with-project-id')
project=IntArgument('Filter by project id', '--with-project-id')
)
@errors.generic.all
@astakoserror
def _run(self):
project = self['project']
if project is not None:
project = int(project)
self._print(self.client.get_memberships(self.token, project))
self._print(self.client.get_memberships(self.token, self['project']))
def main(self):
super(self.__class__, self)._run()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment