def run_testcase(self, testcase): env = testcase.get('env', {}) test_env = { 'PGHOST': None, 'PGPORT': None, 'PGUSER': None, 'PGPASSWORD': None, 'PGDATABASE': None } test_env.update(env) dsn = testcase.get('dsn') user = testcase.get('user') port = testcase.get('port') host = testcase.get('host') password = testcase.get('password') passfile = testcase.get('passfile') database = testcase.get('database') server_settings = testcase.get('server_settings') expected = testcase.get('result') expected_error = testcase.get('error') if expected is None and expected_error is None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified') if expected is not None and expected_error is not None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified, got both') with contextlib.ExitStack() as es: es.enter_context(self.subTest(dsn=dsn, env=env)) es.enter_context(self.environ(**test_env)) if expected_error: es.enter_context(self.assertRaisesRegex(*expected_error)) addrs, params = connect_utils._parse_connect_dsn_and_args( dsn=dsn, host=host, port=port, user=user, password=password, passfile=passfile, database=database, ssl=None, connect_timeout=None, server_settings=server_settings) params = { k: v for k, v in params._asdict().items() if v is not None } result = (addrs, params) if expected is not None: self.assertEqual(expected, result)
def run_testcase(self, testcase): env = testcase.get('env', {}) test_env = {'PGHOST': None, 'PGPORT': None, 'PGUSER': None, 'PGPASSWORD': None, 'PGDATABASE': None, 'PGSSLMODE': None} test_env.update(env) dsn = testcase.get('dsn') user = testcase.get('user') port = testcase.get('port') host = testcase.get('host') password = testcase.get('password') passfile = testcase.get('passfile') database = testcase.get('database') ssl = testcase.get('ssl') server_settings = testcase.get('server_settings') expected = testcase.get('result') expected_error = testcase.get('error') if expected is None and expected_error is None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified') if expected is not None and expected_error is not None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified, got both') with contextlib.ExitStack() as es: es.enter_context(self.subTest(dsn=dsn, env=env)) es.enter_context(self.environ(**test_env)) if expected_error: es.enter_context(self.assertRaisesRegex(*expected_error)) addrs, params = connect_utils._parse_connect_dsn_and_args( dsn=dsn, host=host, port=port, user=user, password=password, passfile=passfile, database=database, ssl=ssl, connect_timeout=None, server_settings=server_settings) params = {k: v for k, v in params._asdict().items() if v is not None} result = (addrs, params) if expected is not None: for k, v in expected[1].items(): # If `expected` contains a type, allow that to "match" any # instance of that type tyat `result` may contain. We need # this because different SSLContexts don't compare equal. if isinstance(v, type) and isinstance(result[1].get(k), v): result[1][k] = v self.assertEqual(expected, result, 'Testcase: {}'.format(testcase))
def run_testcase(self, testcase): env = testcase.get('env', {}) test_env = {'PGHOST': None, 'PGPORT': None, 'PGUSER': None, 'PGPASSWORD': None, 'PGDATABASE': None, 'PGSSLMODE': None} test_env.update(env) dsn = testcase.get('dsn') user = testcase.get('user') port = testcase.get('port') host = testcase.get('host') password = testcase.get('password') passfile = testcase.get('passfile') database = testcase.get('database') ssl = testcase.get('ssl') server_settings = testcase.get('server_settings') expected = testcase.get('result') expected_error = testcase.get('error') if expected is None and expected_error is None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified') if expected is not None and expected_error is not None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified, got both') with contextlib.ExitStack() as es: es.enter_context(self.subTest(dsn=dsn, env=env)) es.enter_context(self.environ(**test_env)) if expected_error: es.enter_context(self.assertRaisesRegex(*expected_error)) addrs, params = connect_utils._parse_connect_dsn_and_args( dsn=dsn, host=host, port=port, user=user, password=password, passfile=passfile, database=database, ssl=ssl, connect_timeout=None, server_settings=server_settings) params = {k: v for k, v in params._asdict().items() if v is not None} result = (addrs, params) if expected is not None: for k, v in expected[1].items(): # If `expected` contains a type, allow that to "match" any # instance of that type tyat `result` may contain. We need # this because different SSLContexts don't compare equal. if isinstance(v, type) and isinstance(result[1].get(k), v): result[1][k] = v self.assertEqual(expected, result, 'Testcase: {}'.format(testcase))
def run_testcase(self, testcase): env = testcase.get('env', {}) test_env = { 'PGHOST': None, 'PGPORT': None, 'PGUSER': None, 'PGPASSWORD': None, 'PGDATABASE': None, 'PGSSLMODE': None } test_env.update(env) dsn = testcase.get('dsn') user = testcase.get('user') port = testcase.get('port') host = testcase.get('host') password = testcase.get('password') passfile = testcase.get('passfile') database = testcase.get('database') sslmode = testcase.get('ssl') server_settings = testcase.get('server_settings') expected = testcase.get('result') expected_error = testcase.get('error') if expected is None and expected_error is None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified') if expected is not None and expected_error is not None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified, got both') with contextlib.ExitStack() as es: es.enter_context(self.subTest(dsn=dsn, env=env)) es.enter_context(self.environ(**test_env)) if expected_error: es.enter_context(self.assertRaisesRegex(*expected_error)) addrs, params = connect_utils._parse_connect_dsn_and_args( dsn=dsn, host=host, port=port, user=user, password=password, passfile=passfile, database=database, ssl=sslmode, connect_timeout=None, server_settings=server_settings) params = { k: v for k, v in params._asdict().items() if v is not None or (expected is not None and k in expected[1]) } if isinstance(params.get('ssl'), ssl.SSLContext): params['ssl'] = True result = (addrs, params) if expected is not None: if 'ssl' not in expected[1]: # Avoid the hassle of specifying the default SSL mode # unless explicitly tested for. params.pop('ssl', None) params.pop('ssl_is_advisory', None) self.assertEqual(expected, result, 'Testcase: {}'.format(testcase))