<s> import sys <EOL> from argparse import Namespace <EOL> from awscli . customizations . codedeploy . install import Install <EOL> from awscli . customizations . codedeploy . systems import Ubuntu , Windows , RHEL , System <EOL> from awscli . testutils import unittest <EOL> from mock import MagicMock , patch , mock_open <EOL> from socket import timeout <EOL> class TestInstall ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . region = '<STR_LIT>' <EOL> self . config_file = '<STR_LIT>' <EOL> self . installer = '<STR_LIT>' <EOL> self . bucket = '<STR_LIT>' . format ( self . region ) <EOL> self . key = '<STR_LIT>' . format ( self . installer ) <EOL> self . agent_installer = '<STR_LIT>' . format ( self . bucket , self . key ) <EOL> self . system_patcher = patch ( '<STR_LIT>' ) <EOL> self . system = self . system_patcher . start ( ) <EOL> self . system . return_value = '<STR_LIT>' <EOL> self . linux_distribution_patcher = patch ( '<STR_LIT>' ) <EOL> self . linux_distribution = self . linux_distribution_patcher . start ( ) <EOL> self . linux_distribution . return_value = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . urlopen_patcher = patch ( <EOL> '<STR_LIT>' <EOL> ) <EOL> self . urlopen = self . urlopen_patcher . start ( ) <EOL> self . urlopen . side_effect = timeout ( '<STR_LIT>' ) <EOL> self . geteuid_patcher = patch ( '<STR_LIT>' , create = True ) <EOL> self . geteuid = self . geteuid_patcher . start ( ) <EOL> self . geteuid . return_value = <NUM_LIT:0> <EOL> self . isfile_patcher = patch ( '<STR_LIT>' ) <EOL> self . isfile = self . isfile_patcher . start ( ) <EOL> self . isfile . return_value = False <EOL> self . makedirs_patcher = patch ( '<STR_LIT>' ) <EOL> self . makedirs = self . makedirs_patcher . start ( ) <EOL> self . copyfile_patcher = patch ( '<STR_LIT>' ) <EOL> self . copyfile = self . copyfile_patcher . start ( ) <EOL> self . open_patcher = patch ( <EOL> '<STR_LIT>' , <EOL> mock_open ( ) , create = True <EOL> ) <EOL> self . open = self . open_patcher . start ( ) <EOL> self . args = Namespace ( ) <EOL> self . args . override_config = False <EOL> self . args . config_file = self . config_file <EOL> self . args . agent_installer = None <EOL> self . globals = Namespace ( ) <EOL> self . globals . region = self . region <EOL> self . body = '<STR_LIT>' <EOL> self . reader = MagicMock ( ) <EOL> self . reader . read . return_value = self . body <EOL> self . s3 = MagicMock ( ) <EOL> self . s3 . get_object . return_value = { '<STR_LIT>' : self . reader } <EOL> self . session = MagicMock ( ) <EOL> self . session . create_client . return_value = self . s3 <EOL> self . install = Install ( self . session ) <EOL> def tearDown ( self ) : <EOL> self . system_patcher . stop ( ) <EOL> self . linux_distribution_patcher . stop ( ) <EOL> self . urlopen_patcher . stop ( ) <EOL> self . geteuid_patcher . stop ( ) <EOL> self . isfile_patcher . stop ( ) <EOL> self . makedirs_patcher . stop ( ) <EOL> self . copyfile_patcher . stop ( ) <EOL> self . open_patcher . stop ( ) <EOL> def test_install_throws_on_invalid_region ( self ) : <EOL> self . globals . region = None <EOL> self . session . get_config_variable . return_value = None <EOL> with self . assertRaisesRegexp ( RuntimeError , '<STR_LIT>' ) : <EOL> self . install . _run_main ( self . args , self . globals ) <EOL> def test_install_throws_on_unsupported_system ( self ) : <EOL> self . system . return_value = '<STR_LIT>' <EOL> with self . assertRaisesRegexp ( <EOL> RuntimeError , System . UNSUPPORTED_SYSTEM_MSG ) : <EOL> self . install . _run_main ( self . args , self . globals ) <EOL> def test_install_throws_on_ec2_instance ( self ) : <EOL> self . urlopen . side_effect = None <EOL> with self . assertRaisesRegexp ( <EOL> RuntimeError , '<STR_LIT>' ) : <EOL> self . install . _run_main ( self . args , self . globals ) <EOL> self . assertIn ( '<STR_LIT>' , self . args ) <EOL> self . assertTrue ( isinstance ( self . args . system , Ubuntu ) ) <EOL> def test_install_throws_on_non_administrator ( self ) : <EOL> self . geteuid . return_value = <NUM_LIT:1> <EOL> with self . assertRaisesRegexp ( <EOL> RuntimeError , '<STR_LIT>' ) : <EOL> self . install . _run_main ( self . args , self . globals ) <EOL> def test_install_throws_on_no_override_config ( self ) : <EOL> self . isfile . return_value = True <EOL> self . args . override_config = False <EOL> with self . assertRaisesRegexp ( <EOL> RuntimeError , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) : <EOL> self . install . _run_main ( self . args , self . globals ) <EOL> def test_install_throws_on_invalid_agent_installer ( self ) : <EOL> self . args . agent_installer = '<STR_LIT>' <EOL> with self . assertRaisesRegexp ( <EOL> ValueError , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) : <EOL> self . install . _run_main ( self . args , self . globals ) <EOL> @ patch . object ( Ubuntu , '<STR_LIT>' ) <EOL> def test_install_with_agent_installer ( self , install ) : <EOL> self . args . agent_installer = self . agent_installer <EOL> self . install . _run_main ( self . args , self . globals ) <EOL> self . assertIn ( '<STR_LIT>' , self . args ) <EOL> self . assertEqual ( self . bucket , self . args . bucket ) <EOL> self . assertIn ( '<STR_LIT:key>' , self . args ) <EOL> self . assertEqual ( self . key , self . args . key ) <EOL> self . assertIn ( '<STR_LIT>' , self . args ) <EOL> self . assertEqual ( self . installer , self . args . installer ) <EOL> install . assert_called_with ( self . args ) <EOL> @ patch . object ( Ubuntu , '<STR_LIT>' ) <EOL> def test_install_for_ubuntu ( self , install ) : <EOL> self . system . return_value = '<STR_LIT>' <EOL> self . linux_distribution . return_value = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . install . _run_main ( self . args , self . globals ) <EOL> self . assertIn ( '<STR_LIT>' , self . args ) <EOL> self . assertEquals ( self . bucket , self . args . bucket ) <EOL> self . assertIn ( '<STR_LIT:key>' , self . args ) <EOL> self . assertEquals ( '<STR_LIT>' , self . args . key ) <EOL> self . assertIn ( '<STR_LIT>' , self . args ) <EOL> self . assertEquals ( '<STR_LIT>' , self . args . installer ) <EOL> self . makedirs . assert_called_with ( '<STR_LIT>' ) <EOL> self . copyfile . assset_called_with ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> install . assert_called_with ( self . args ) <EOL> @ patch . object ( Windows , '<STR_LIT>' ) <EOL> @ patch . object ( Windows , '<STR_LIT>' ) <EOL> def test_install_for_windows ( self , validate_administrator , install ) : <EOL> self . system . return_value = '<STR_LIT>' <EOL> self . install . _run_main ( self . args , self . globals ) <EOL> self . assertIn ( '<STR_LIT>' , self . args ) <EOL> self . assertEquals ( self . bucket , self . args . bucket ) <EOL> self . assertIn ( '<STR_LIT:key>' , self . args ) <EOL> self . assertEquals ( '<STR_LIT>' , self . args . key ) <EOL> self . assertIn ( '<STR_LIT>' , self . args ) <EOL> self . assertEquals ( '<STR_LIT>' , self . args . installer ) <EOL> self . makedirs . assert_called_with ( r'<STR_LIT>' ) <EOL> self . copyfile . assset_called_with ( <EOL> '<STR_LIT>' , <EOL> r'<STR_LIT>' <EOL> ) <EOL> validate_administrator . assert_called_with ( ) <EOL> install . assert_called_with ( self . args ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
