Skip to content

Commit

Permalink
Fix call_command arg type detection
Browse files Browse the repository at this point in the history
  • Loading branch information
hiisi13 committed Apr 15, 2014
1 parent f3ed08d commit e41527d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 9 additions & 1 deletion south_central/management/commands/appmigration.py
Expand Up @@ -38,10 +38,18 @@ def error(self, message, code=1):


def join_args(args):
args = ['"{0}"'.format(arg) if isinstance(arg, str) else str(arg) for arg in args]
args = ['"{0}"'.format(arg) if not isnumber(arg) else str(arg) for arg in args]
return ", ".join(args)


def isnumber(s):
try:
float(s)
return True
except ValueError:
return False


MIGRATION_TEMPLATE = """# -*- coding: utf-8 -*-
Expand Down
1 change: 0 additions & 1 deletion south_central/management/commands/migrateapp.py
Expand Up @@ -14,7 +14,6 @@ def migration_module(basename, module_name):

def import_migration_module(migrations_module, migration):
module = migration_module(migrations_module, migration)
print(module)
return __import__(module, {}, {}, ['Migration'])


Expand Down
6 changes: 3 additions & 3 deletions tests/test_appmigration.py
Expand Up @@ -41,15 +41,15 @@ def test_create_call_command_with_str_arg_migration(self):

def test_create_call_command_with_int_arg_migration(self):
call_command('appmigration', self.test_app_name, self.test_migration_name,
'cmd_name', 1)
'cmd_name', '1')
self.assert_migration_contents('call_command("cmd_name", 1)')

def test_create_call_command_with_float_arg_migration(self):
call_command('appmigration', self.test_app_name, self.test_migration_name,
'cmd_name', 1.01)
'cmd_name', '1.01')
self.assert_migration_contents('call_command("cmd_name", 1.01)')

def test_create_call_command_with_multiple_args_migration(self):
call_command('appmigration', self.test_app_name, self.test_migration_name,
'cmd_name', 'cmd_arg', 1, 1.01)
'cmd_name', 'cmd_arg', '1', '1.01')
self.assert_migration_contents('call_command("cmd_name", "cmd_arg", 1, 1.01)')

0 comments on commit e41527d

Please sign in to comment.