<s> from nose . tools import istest <EOL> from provy . more . debian import AptitudeRole , NginxRole <EOL> from tests . unit . tools . helpers import ProvyTestCase <EOL> class NginxRoleTest ( ProvyTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( NginxRoleTest , self ) . setUp ( ) <EOL> self . role = NginxRole ( prov = None , context = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> @ istest <EOL> def installs_necessary_packages_to_provision ( self ) : <EOL> with self . using_stub ( AptitudeRole ) as aptitude : <EOL> self . role . provision ( ) <EOL> aptitude . ensure_up_to_date . assert_called_once_with ( ) <EOL> aptitude . ensure_package_installed . assert_called_once_with ( '<STR_LIT>' ) <EOL> @ istest <EOL> def doesnt_restart_if_not_necessary_upon_cleanup ( self ) : <EOL> with self . mock_role_method ( '<STR_LIT>' ) : <EOL> self . role . cleanup ( ) <EOL> self . assertFalse ( self . role . restart . called ) <EOL> @ istest <EOL> def restart_if_necessary_upon_cleanup ( self ) : <EOL> self . role . context [ '<STR_LIT>' ] = True <EOL> with self . mock_role_method ( '<STR_LIT>' ) : <EOL> self . role . cleanup ( ) <EOL> self . assertTrue ( self . role . restart . called ) <EOL> @ istest <EOL> def updates_configuration_and_restarts ( self ) : <EOL> conf_template = '<STR_LIT>' <EOL> nginx_conf_path = '<STR_LIT>' <EOL> options = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . role . update_file . return_value = True <EOL> self . role . ensure_conf ( conf_template , options , nginx_conf_path ) <EOL> self . role . update_file . assert_called_once_with ( conf_template , nginx_conf_path , options = options , sudo = True ) <EOL> self . role . ensure_restart . assert_called_once_with ( ) <EOL> @ istest <EOL> def doesnt_restart_if_configuration_wasnt_updated ( self ) : <EOL> conf_template = '<STR_LIT>' <EOL> nginx_conf_path = '<STR_LIT>' <EOL> options = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . role . update_file . return_value = False <EOL> self . role . ensure_conf ( conf_template , options , nginx_conf_path ) <EOL> self . assertFalse ( self . role . ensure_restart . called ) <EOL> @ istest <EOL> def ensures_site_is_disabled_and_restarted ( self ) : <EOL> site = '<STR_LIT>' <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . role . remove_file . return_value = True <EOL> self . role . ensure_site_disabled ( site ) <EOL> self . role . remove_file . assert_called_once_with ( '<STR_LIT>' , sudo = True ) <EOL> self . role . ensure_restart . assert_called_once_with ( ) <EOL> @ istest <EOL> def doesnt_restart_if_site_wasnt_disabled ( self ) : <EOL> site = '<STR_LIT>' <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . role . remove_file . return_value = False <EOL> self . role . ensure_site_disabled ( site ) <EOL> self . assertFalse ( self . role . ensure_restart . called ) <EOL> @ istest <EOL> def ensures_site_is_enabled_and_restarted ( self ) : <EOL> site = '<STR_LIT>' <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . role . remote_symlink . return_value = True <EOL> self . role . ensure_site_enabled ( site ) <EOL> self . role . remote_symlink . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , sudo = True ) <EOL> self . role . ensure_restart . assert_called_once_with ( ) <EOL> @ istest <EOL> def doesnt_restart_if_site_wasnt_enabled ( self ) : <EOL> site = '<STR_LIT>' <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . role . remote_symlink . return_value = False <EOL> self . role . ensure_site_enabled ( site ) <EOL> self . assertFalse ( self . role . ensure_restart . called ) <EOL> @ istest <EOL> def ensures_site_is_created_and_restarted ( self ) : <EOL> site = '<STR_LIT>' <EOL> template = '<STR_LIT>' <EOL> options = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . role . update_file . return_value = True <EOL> self . role . create_site ( site , template , options = options ) <EOL> self . role . update_file . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , options = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , sudo = True ) <EOL> self . role . ensure_restart . assert_called_once_with ( ) <EOL> @ istest <EOL> def doesnt_restart_if_site_wasnt_created ( self ) : <EOL> site = '<STR_LIT>' <EOL> template = '<STR_LIT>' <EOL> options = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . role . update_file . return_value = False <EOL> self . role . create_site ( site , template , options = options ) <EOL> self . role . update_file . assert_called_once_with ( '<STR_LIT>' , '<STR_LIT>' , options = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , sudo = True ) <EOL> self . assertFalse ( self . role . ensure_restart . called ) <EOL> @ istest <EOL> def ensures_nginx_is_restarted ( self ) : <EOL> self . role . context [ '<STR_LIT>' ] = False <EOL> self . role . ensure_restart ( ) <EOL> self . assertTrue ( self . role . context [ '<STR_LIT>' ] ) <EOL> @ istest <EOL> def restarts_nginx ( self ) : <EOL> with self . execute_mock ( ) : <EOL> self . role . restart ( ) <EOL> self . role . execute . assert_called_once_with ( '<STR_LIT>' , sudo = True ) </s>
