<s> from mock import patch , call <EOL> from nose . tools import istest <EOL> from provy . more . centos import HostNameRole <EOL> from provy . more . centos . utils import hostname <EOL> from tests . unit . tools . helpers import ProvyTestCase <EOL> class HostNameRoleTest ( ProvyTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( HostNameRoleTest , self ) . setUp ( ) <EOL> self . role = HostNameRole ( None , { } ) <EOL> @ istest <EOL> def ensures_a_hostname_is_configured_when_not_existing ( self ) : <EOL> new_hostname = '<STR_LIT>' <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , patch . object ( hostname , '<STR_LIT>' ) as sed : <EOL> self . role . execute . return_value = '<STR_LIT>' <EOL> self . role . read_remote_file . return_value = '''<STR_LIT>''' . format ( new_hostname ) <EOL> result = self . role . ensure_hostname ( new_hostname ) <EOL> self . assertTrue ( result ) <EOL> self . role . read_remote_file . assert_called_once_with ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . role . execute . mock_calls , [ <EOL> call ( '<STR_LIT>' ) , <EOL> call ( '<STR_LIT>' . format ( new_hostname ) , sudo = True , stdout = False ) , <EOL> ] ) <EOL> self . assertFalse ( self . role . ensure_line . called ) <EOL> sed . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , use_sudo = True ) <EOL> @ istest <EOL> def ensures_a_hostname_is_configured_when_another_one_already_exists ( self ) : <EOL> new_hostname = '<STR_LIT>' <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , patch . object ( hostname , '<STR_LIT>' ) as sed : <EOL> self . role . execute . return_value = '<STR_LIT>' <EOL> self . role . read_remote_file . return_value = '''<STR_LIT>''' . format ( new_hostname ) <EOL> result = self . role . ensure_hostname ( new_hostname ) <EOL> self . assertTrue ( result ) <EOL> self . role . read_remote_file . assert_called_once_with ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . role . execute . mock_calls , [ <EOL> call ( '<STR_LIT>' ) , <EOL> call ( '<STR_LIT>' . format ( new_hostname ) , sudo = True , stdout = False ) , <EOL> ] ) <EOL> self . assertFalse ( sed . called ) <EOL> self . role . ensure_line . assert_called_once_with ( '<STR_LIT>' . format ( new_hostname ) , sudo = True , stdout = False ) <EOL> @ istest <EOL> def doesnt_configure_the_hostname_if_same_as_server ( self ) : <EOL> new_hostname = '<STR_LIT>' <EOL> with self . mock_role_methods ( '<STR_LIT>' ) : <EOL> self . role . execute . return_value = new_hostname <EOL> result = self . role . ensure_hostname ( new_hostname ) <EOL> self . assertFalse ( result ) <EOL> self . assertEqual ( self . role . execute . mock_calls , [ <EOL> call ( '<STR_LIT>' ) , <EOL> ] ) </s>
