Fix IntArgument + tests and apply to snf-astakos
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 28 Aug 2013 12:07:14 +0000 (15:07 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Wed, 28 Aug 2013 12:07:14 +0000 (15:07 +0300)
kamaki/cli/argument/__init__.py
kamaki/cli/argument/test.py
kamaki/cli/commands/snf-astakos.py

index c383b4b..6cd8197 100644 (file)
@@ -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',
index f3ead74..f77f13a 100644 (file)
@@ -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
index 413cc20..bff2534 100644 (file)
@@ -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()