<s> import pwd <EOL> import os <EOL> import copy <EOL> import unittest2 <EOL> from st2common . models . system . action import ShellCommandAction <EOL> from st2common . models . system . action import ShellScriptAction <EOL> CURRENT_DIR = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> FIXTURES_DIR = os . path . abspath ( os . path . join ( CURRENT_DIR , '<STR_LIT>' ) ) <EOL> LOGGED_USER_USERNAME = pwd . getpwuid ( os . getuid ( ) ) [ <NUM_LIT:0> ] <EOL> class ShellCommandActionTestCase ( unittest2 . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _base_kwargs = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : None <EOL> } <EOL> def test_user_argument ( self ) : <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = LOGGED_USER_USERNAME <EOL> action = ShellCommandAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> self . assertEqual ( command , '<STR_LIT>' ) <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> action = ShellCommandAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> self . assertEqual ( command , '<STR_LIT>' ) <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> kwargs [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> action = ShellCommandAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> self . assertEqual ( command , '<STR_LIT>' ) <EOL> class ShellScriptActionTestCase ( unittest2 . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _base_kwargs = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : None <EOL> } <EOL> def _get_fixture ( self , name ) : <EOL> path = os . path . join ( FIXTURES_DIR , '<STR_LIT>' , name ) <EOL> with open ( path , '<STR_LIT:r>' ) as fp : <EOL> content = fp . read ( ) . strip ( ) <EOL> return content <EOL> def test_user_argument ( self ) : <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = LOGGED_USER_USERNAME <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> self . assertEqual ( command , '<STR_LIT>' ) <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> self . assertEqual ( command , '<STR_LIT>' ) <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> kwargs [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> self . assertEqual ( command , '<STR_LIT>' ) <EOL> def test_command_construction_with_parameters ( self ) : <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = LOGGED_USER_USERNAME <EOL> kwargs [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> kwargs [ '<STR_LIT>' ] = [ ] <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> self . assertEqual ( command , '<STR_LIT>' ) <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> kwargs [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> kwargs [ '<STR_LIT>' ] = [ ] <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> expected = '<STR_LIT>' <EOL> self . assertEqual ( command , expected ) <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = LOGGED_USER_USERNAME <EOL> kwargs [ '<STR_LIT>' ] = { } <EOL> kwargs [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> self . assertEqual ( command , '<STR_LIT>' ) <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> kwargs [ '<STR_LIT>' ] = { } <EOL> kwargs [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> ex = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( command , ex ) <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = LOGGED_USER_USERNAME <EOL> kwargs [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> kwargs [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> exp = '<STR_LIT>' <EOL> self . assertEqual ( command , exp ) <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> kwargs [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> kwargs [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> expected = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( command , expected ) <EOL> def test_named_parameter_escaping ( self ) : <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> kwargs [ '<STR_LIT:user>' ] = LOGGED_USER_USERNAME <EOL> kwargs [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> expected = self . _get_fixture ( '<STR_LIT>' ) <EOL> self . assertEqual ( command , expected ) <EOL> kwargs = copy . deepcopy ( self . _base_kwargs ) <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> kwargs [ '<STR_LIT:user>' ] = LOGGED_USER_USERNAME <EOL> kwargs [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> action = ShellScriptAction ( ** kwargs ) <EOL> command = action . get_full_command_string ( ) <EOL> expected = self . _get_fixture ( '<STR_LIT>' ) <EOL> self . assertEqual ( command , expected ) </s>
