def test_get_postmasters_directories_should_exclude_process_when_ppid_in_process_candidates( self, mocked_get_pg_version_from_file, mocked_get_postgres_processes): mocked_get_pg_version_from_file.side_effect = [ connection_params(1056, '9.3', 'db'), connection_params(1057, '9.4', 'test_db') ] first_process = mock.Mock(pid=1056, name='postgres') first_process.ppid.return_value = 1 first_process.cwd.return_value = '/var/lib/postgresql/9.3/main' second_process = mock.Mock(pid=1057, name='postgres') second_process.ppid.return_value = 1056 second_process.cwd.return_value = '/var/lib/postgresql/9.4/main' mocked_get_postgres_processes.return_value = [ first_process, second_process ] result = self.worker.get_postmasters_directories() expected_result = { '/var/lib/postgresql/9.3/main': connection_params(pid=1056, version='9.3', dbname='db'), } self.assertEqual(expected_result, result) mocked_get_postgres_processes.assert_called_with()
def test_get_pg_version_from_file_should_return_params_when_file_ok( self, mocked_logger, mocked_read_file, mocked_os_access): pg_version = self.worker.get_pg_version_from_file( 10, '/var/lib/postgresql/9.3/main') expected_result = connection_params( pid=10, version=9.3, dbname='/var/lib/postgresql/9.3/main') self.assertEqual(expected_result, pg_version)
def test_get_postmasters_directories_should_return_postmaster_when_ppid_not_in_candidates( self, mocked_get_pg_version_from_file, mocked_get_postgres_processes): mocked_get_pg_version_from_file.return_value = connection_params( 1056, '9.3', 'db') process = mock.Mock(pid=1056, name='postgres') process.ppid.return_value = 1 process.cwd.return_value = '/var/lib/postgresql/9.3/main' mocked_get_postgres_processes.return_value = [process] result = self.worker.get_postmasters_directories() expected_result = { '/var/lib/postgresql/9.3/main': connection_params(pid=1056, version='9.3', dbname='db') } self.assertEqual(expected_result, result) mocked_get_postgres_processes.assert_called_with()
def test_validate_autodetected_conn_param_should_raise_invalid_param_when_different_versions(self): conn_parameters = connection_params(pid=2, version=9.3, dbname='/var/lib/postgresql/9.3/main') with self.assertRaises(InvalidConnectionParamError): validate_autodetected_conn_param( '/var/lib/postgresql/9.3/main', 9.5, '/var/run/postgresql', conn_parameters)
def test_validate_autodetected_conn_param_should_raise_invalid_param_when_no_result_work_dir(self): conn_parameters = connection_params(pid=1049, version=9.3, dbname='/var/lib/postgresql/9.3/main') with self.assertRaises(InvalidConnectionParamError): validate_autodetected_conn_param('/var/lib/postgresql/9.3/main', 9.3, '', conn_parameters)