def test_docker_get_data_dir_host(mocker): popen_mock = MockPopen() popen_mock.set_default(stdout=DOCKER_OUTPUT.encode('utf-8')) mocker.patch('subprocess.Popen', new=popen_mock) data_dir_host, err = PostgreSQLAlt.docker_get_data_dir_host('foobar', '/data') assert err is None assert data_dir_host == '/mnt/storage/the_land_where_the_data_lives'
def test_get_s64_license(conn): conn.fetchall_return_value = ( ('full', '2020-01-01', '2030-01-01', 's64-license-test'), ) license_info, err = PostgreSQLAlt.get_s64_license(conn) assert err is None assert license_info == { 'type': 'full', 'start': '2020-01-01', 'expiry': '2030-01-01', 'customer': 's64-license-test' } conn.fetchall_return_value = () license_info, err = PostgreSQLAlt.get_s64_license(conn) assert err is None assert not license_info
def test_get_logging_info(conn): conn.fetchall_return_value = ( ('log_directory', 'foobar'), ('log_destination', 'stderr'), ('data_directory', 'fancy'), ('logging_collector', 'on') ) logging_info, err = PostgreSQLAlt.get_logging_info(conn) assert err is None assert logging_info.log_dir == 'foobar' assert logging_info.data_dir == 'fancy' assert logging_info.collect_logs conn.fetchall_return_value = ( ('log_directory', 'foobar'), ('data_directory', 'fancy'), ('log_destination', 'stderr'), ('logging_collector', 'off') ) logging_info, err = PostgreSQLAlt.get_logging_info(conn) assert err is None assert logging_info.log_dir == 'foobar' assert logging_info.data_dir == 'fancy' assert not logging_info.collect_logs conn.fetchall_return_value = ( ('log_directory', 'foobar'), ('log_destination', 'csvlog'), ('data_directory', 'fancy'), ('logging_collector', 'on') ) logging_info, err = PostgreSQLAlt.get_logging_info(conn) assert err is None assert logging_info.log_dir == 'foobar' assert logging_info.data_dir == 'fancy' assert logging_info.collect_logs conn.fetchall_return_value = ( ('log_destination', 'csvlog'), ('log_directory', 'foobar'), ('logging_collector', 'off'), ('data_directory', 'fancy') ) logging_info, err = PostgreSQLAlt.get_logging_info(conn) assert err is None assert logging_info.log_dir == 'foobar' assert logging_info.data_dir == 'fancy' assert not logging_info.collect_logs conn.fetchall_return_value = ( ('log_destination', 'csvlog,stderr'), ('data_directory', 'fancy'), ('log_directory', 'foobar'), ('logging_collector', 'on') ) logging_info, err = PostgreSQLAlt.get_logging_info(conn) assert err is None assert logging_info.log_dir == 'foobar' assert logging_info.data_dir == 'fancy' assert logging_info.collect_logs conn.fetchall_return_value = ( ('log_destination', 'csvlog,stderr'), ('logging_collector', 'off'), ('data_directory', 'fancy'), ('log_directory', 'foobar') ) logging_info, err = PostgreSQLAlt.get_logging_info(conn) assert err is None assert logging_info.log_dir == 'foobar' assert logging_info.data_dir == 'fancy' assert not logging_info.collect_logs conn.fetchall_return_value = ( ('log_destination', 'syslog'), ('data_directory', 'fancy'), ('logging_collector', 'on'), ('log_directory', 'foobar') ) logging_info, err = PostgreSQLAlt.get_logging_info(conn) assert err is None assert logging_info.log_dir == 'foobar' assert logging_info.data_dir == 'fancy' assert not logging_info.collect_logs conn.fetchall_return_value = ( ('log_directory', 'foobar'), ('log_destination', 'syslog'), ('data_directory', 'fancy'), ('logging_collector', 'off') ) logging_info, err = PostgreSQLAlt.get_logging_info(conn) assert err is None assert logging_info.log_dir == 'foobar' assert logging_info.data_dir == 'fancy' assert not logging_info.collect_logs conn.fetchall_return_value = ( ('data_directory', 'fancy'), ('log_destination', 'syslog,stderr'), ('log_directory', 'foobar'), ('logging_collector', 'on') ) logging_info, err = PostgreSQLAlt.get_logging_info(conn) assert err is None assert logging_info.log_dir == 'foobar' assert logging_info.data_dir == 'fancy' assert logging_info.collect_logs conn.fetchall_return_value = ( ('log_destination', 'syslog,stderr'), ('log_directory', 'foobar'), ('data_directory', 'fancy'), ('logging_collector', 'off') ) logging_info, err = PostgreSQLAlt.get_logging_info(conn) assert err is None assert logging_info.log_dir == 'foobar' assert logging_info.data_dir == 'fancy' assert not logging_info.collect_logs
def test_config_to_string(): config_str = PostgreSQLAlt.config_to_string(TEST_CONFIG) assert config_str == TEST_CONFIG_STR
def test_get_config_err(conn): conn.fetchall_side_effect = DatabaseError('Something went wrong') config, err = PostgreSQLAlt.get_config(conn) assert config is None assert err is not None
def test_get_config_ok(conn): conn.fetchall_return_value = TEST_CONFIG config, err = PostgreSQLAlt.get_config(conn) assert config == TEST_CONFIG assert err is None
def test_connect_err(mocker): mocker.patch('psycopg2.connect', side_effect=DatabaseError('DSN invalid')) conn, err = PostgreSQLAlt.do_connect('some_invalid_dsn') assert conn is None assert err is not None
def test_connect_ok(mocker): mocker.patch('psycopg2.connect') conn, err = PostgreSQLAlt.do_connect('some_valid_dsn') assert conn is not None assert err is None