Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_suite(handle, handler_objects, host, port, prefix, force_ssl=False,
failfast=False, data_dir='.', verbosity=False, name='input',
safe_yaml=True, quiet=False, cert_validate=True):
"""Run the tests from the YAML in handle."""
data = utils.load_yaml(handle, safe=safe_yaml)
if force_ssl:
if 'defaults' in data:
data['defaults']['ssl'] = True
else:
data['defaults'] = {'ssl': True}
if verbosity:
if 'defaults' in data:
data['defaults']['verbose'] = verbosity
else:
data['defaults'] = {'verbose': verbosity}
if not cert_validate:
if 'defaults' in data:
data['defaults']['cert_validate'] = False
else:
data['defaults'] = {'cert_validate': False}
response_handlers = response_handlers or []
content_handlers = content_handlers or []
handler_objects = []
for handler in (content_handlers + response_handlers +
handlers.RESPONSE_HANDLERS):
handler_objects.append(handler())
top_suite = suite.TestSuite()
for test_file in glob.iglob('%s/*.yaml' % path):
if '_' in os.path.basename(test_file):
warnings.warn(exception.GabbiSyntaxWarning(
"'_' in test filename %s. This can break suite grouping."
% test_file))
if intercept:
host = str(uuid.uuid4())
suite_dict = utils.load_yaml(yaml_file=test_file,
safe=safe_yaml)
test_base_name = os.path.splitext(os.path.basename(test_file))[0]
if all_test_base_name:
test_base_name = '%s_%s' % (all_test_base_name, test_base_name)
if require_ssl:
if 'defaults' in suite_dict:
suite_dict['defaults']['ssl'] = True
else:
suite_dict['defaults'] = {'ssl': True}
if any((verbose == opt for opt in [True, 'all', 'headers', 'body'])):
if 'defaults' in suite_dict:
suite_dict['defaults']['verbose'] = verbose
else:
suite_dict['defaults'] = {'verbose': verbose}
prefix = parsed_url.path.rstrip('/') # turn it into a prefix
if parsed_url.scheme == 'https':
port = 443
require_ssl = True
else:
port = 80
require_ssl = False
host = parsed_url.hostname
if parsed_url.port:
port = parsed_url.port
os.environ["GNOCCHI_SERVICE_TOKEN"] = token
os.environ["GNOCCHI_AUTHORIZATION"] = "not used"
with open(os.path.join(TEST_DIR, filename)) as f:
suite_dict = utils.load_yaml(f)
suite_dict.setdefault('defaults', {})['ssl'] = require_ssl
test_suite = suitemaker.test_suite_from_dict(
loader=unittest.defaultTestLoader,
test_base_name="gabbi",
suite_dict=suite_dict,
test_directory=TEST_DIR,
host=host, port=port,
fixture_module=None,
intercept=None,
prefix=prefix,
handlers=runner.initialize_handlers([]),
test_loader_name="tempest")
# NOTE(sileht): We hide stdout/stderr and reraise the failure
# manually, tempest will print it itself.
with open(os.devnull, 'w') as stream: