<s> from mock import call , patch <EOL> from nose . tools import istest <EOL> from provy . more . centos import YumRole , PostgreSQLRole <EOL> from tests . unit . more . base . database import test_postgresql <EOL> class PostgreSQLRoleTestCase ( test_postgresql . PostgreSQLRoleTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( PostgreSQLRoleTestCase , self ) . setUp ( ) <EOL> self . role = PostgreSQLRole ( prov = None , context = { } ) <EOL> class PostgreSQLRoleTest ( PostgreSQLRoleTestCase ) : <EOL> @ istest <EOL> def ensure_initialized ( self ) : <EOL> with self . failed_execution ( '<STR_LIT>' , None ) : <EOL> with self . successful_execution ( '<STR_LIT>' , None ) : <EOL> self . assertTrue ( self . role . _ensure_initialized ( ) ) <EOL> with self . successful_execution ( '<STR_LIT>' , None ) : <EOL> self . assertTrue ( self . role . _ensure_initialized ( ) ) <EOL> @ istest <EOL> def verifies_db_is_initialized ( self ) : <EOL> with self . successful_execution ( '<STR_LIT>' , None ) : <EOL> self . assertTrue ( self . role . _is_db_initialized ( ) ) <EOL> @ istest <EOL> def verifies_db_is_not_initialized ( self ) : <EOL> with self . failed_execution ( '<STR_LIT>' , None ) : <EOL> self . assertFalse ( self . role . _is_db_initialized ( ) ) <EOL> @ istest <EOL> def ensures_postegres_is_running ( self ) : <EOL> with self . execution ( '<STR_LIT>' , '<STR_LIT>' , None ) : <EOL> with self . successful_execution ( '<STR_LIT>' , None ) : <EOL> self . assertTrue ( self . role . _ensure_running ( ) ) <EOL> @ istest <EOL> def ensures_postegres_is_not_running ( self ) : <EOL> with self . execution ( '<STR_LIT>' , '<STR_LIT>' , None ) : <EOL> self . assertTrue ( self . role . _ensure_running ( ) ) <EOL> @ istest <EOL> def ensures_postgres_on_startup ( self ) : <EOL> with self . execution ( '<STR_LIT>' , '<STR_LIT>' , None ) : <EOL> with self . execution ( '<STR_LIT>' , '<STR_LIT>' , None ) : <EOL> with self . execution ( '<STR_LIT>' , '<STR_LIT>' , None ) : <EOL> self . assertTrue ( self . role . _run_on_startup ( ) ) <EOL> @ istest <EOL> def ensures_postgres_not_on_startup ( self ) : <EOL> with self . execution ( '<STR_LIT>' , '<STR_LIT>' , None ) : <EOL> self . assertFalse ( self . role . _run_on_startup ( ) ) <EOL> @ istest <EOL> def change_directory_to_postgres_data_dir ( self ) : <EOL> with patch ( '<STR_LIT>' ) as cd_mock , self . execute_mock ( ) as execute : <EOL> self . role . _execute ( '<STR_LIT>' ) <EOL> self . assertEqual ( cd_mock . call_args , call ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> execute . call_args , call ( '<STR_LIT>' , sudo = True , stdout = True , user = '<STR_LIT>' ) <EOL> ) <EOL> @ istest <EOL> def installs_necessary_packages_to_provision ( self ) : <EOL> with self . using_stub ( YumRole ) as mock_yum , self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> print mock_yum <EOL> self . role . provision ( ) <EOL> install_calls = mock_yum . ensure_package_installed . mock_calls <EOL> self . assertEqual ( <EOL> install_calls , <EOL> [ call ( '<STR_LIT>' ) , call ( '<STR_LIT>' ) ] , <EOL> ) <EOL> self . assertTrue ( self . role . _run_on_startup . called ) <EOL> self . assertTrue ( self . role . _ensure_running . called ) <EOL> self . assertTrue ( self . role . _ensure_initialized . called ) </s>
