<s> import tower_cli <EOL> from tower_cli . api import client <EOL> from tower_cli . utils import exceptions as exc <EOL> from tests . compat import unittest , mock <EOL> from tower_cli . conf import settings <EOL> import json <EOL> import click <EOL> class LaunchTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . res = tower_cli . get_resource ( '<STR_LIT>' ) <EOL> def test_basic_launch ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT:/>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:POST>' ) <EOL> result = self . res . launch ( inventory = "<STR_LIT>" , machine_credential = <NUM_LIT:2> ) <EOL> self . assertEqual ( result , { '<STR_LIT>' : True , '<STR_LIT:id>' : <NUM_LIT> } ) <EOL> def test_launch_with_become ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT:/>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:POST>' ) <EOL> self . res . launch ( inventory = "<STR_LIT>" , machine_credential = <NUM_LIT:2> , <EOL> become = True ) <EOL> self . assertDictContainsSubset ( <EOL> { '<STR_LIT>' : True } , <EOL> json . loads ( t . requests [ <NUM_LIT:1> ] . body ) <EOL> ) <EOL> def test_basic_launch_with_echo ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT:/>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : True , '<STR_LIT:id>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , } , method = '<STR_LIT:POST>' <EOL> ) <EOL> result = self . res . launch ( inventory = "<STR_LIT>" , machine_credential = <NUM_LIT:2> ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] , True ) <EOL> self . assertEqual ( result [ '<STR_LIT:id>' ] , <NUM_LIT> ) <EOL> f = self . res . as_command ( ) . _echo_method ( self . res . launch ) <EOL> with mock . patch . object ( click , '<STR_LIT>' ) : <EOL> with settings . runtime_values ( format = '<STR_LIT>' ) : <EOL> f ( inventory = "<STR_LIT>" , machine_credential = <NUM_LIT:2> ) <EOL> def test_launch_with_param ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT:/>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:POST>' ) <EOL> result = self . res . launch ( inventory = "<STR_LIT>" , machine_credential = <NUM_LIT:2> , <EOL> module_args = "<STR_LIT>" ) <EOL> self . assertEqual ( result , { '<STR_LIT>' : True , '<STR_LIT:id>' : <NUM_LIT> } ) <EOL> def test_version_failure ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT:/>' , { } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:POST>' ) <EOL> with self . assertRaises ( exc . TowerCLIError ) : <EOL> self . res . launch ( inventory = <NUM_LIT:1> , machine_credential = <NUM_LIT:2> , <EOL> module_args = "<STR_LIT>" ) <EOL> def test_basic_launch_monitor_option ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT:/>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , method = '<STR_LIT:GET>' ) <EOL> t . register_json ( '<STR_LIT>' , { '<STR_LIT:id>' : <NUM_LIT> } , method = '<STR_LIT:POST>' ) <EOL> with mock . patch . object ( type ( self . res ) , '<STR_LIT>' ) as monitor : <EOL> self . res . launch ( inventory = <NUM_LIT:1> , machine_credential = <NUM_LIT:2> , <EOL> module_args = "<STR_LIT>" , monitor = True ) <EOL> monitor . assert_called_once_with ( <NUM_LIT> , timeout = None ) <EOL> class StatusTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . res = tower_cli . get_resource ( '<STR_LIT>' ) <EOL> def test_normal ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> } ) <EOL> result = self . res . status ( <NUM_LIT> ) <EOL> self . assertEqual ( result , { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:1> ) <EOL> def test_detailed ( self ) : <EOL> with client . test_mode as t : <EOL> t . register_json ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> } ) <EOL> result = self . res . status ( <NUM_LIT> , detail = True ) <EOL> self . assertEqual ( result , { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertEqual ( len ( t . requests ) , <NUM_LIT:1> ) <EOL> class CancelTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . res = tower_cli . get_resource ( '<STR_LIT>' ) <EOL> def test_standard_cancelation ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register ( '<STR_LIT>' , '<STR_LIT>' , method = '<STR_LIT:POST>' ) <EOL> result = self . res . cancel ( <NUM_LIT> ) <EOL> self . assertTrue ( <EOL> t . requests [ <NUM_LIT:0> ] . url . endswith ( '<STR_LIT>' ) <EOL> ) <EOL> self . assertTrue ( result [ '<STR_LIT>' ] ) <EOL> def test_cancelation_completed_with_error ( self ) : <EOL> """<STR_LIT>""" <EOL> with client . test_mode as t : <EOL> t . register ( '<STR_LIT>' , '<STR_LIT>' , <EOL> method = '<STR_LIT:POST>' , status_code = <NUM_LIT> ) <EOL> with self . assertRaises ( exc . TowerCLIError ) : <EOL> self . res . cancel ( <NUM_LIT> , fail_if_not_running = True ) </s>
