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_gabi(self, gabbi_declaration):
# initialise the gabbi handlers
for handler in RESPONSE_HANDLERS:
handler(case.HTTPTestCase)
# take only the host name and port from the live server
_, host = self.live_server_url.split('://')
# use gabbi to create the test suite from our declaration
suite = test_suite_from_yaml(
unittest.defaultTestLoader,
self.id(),
gabbi_declaration,
'.',
host,
None,
None,
None,
)
def load_tests(loader, tests, pattern):
"""Provide a TestSuite to the discovery process."""
test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)
conf = config.CONF.heat_plugin
if conf.auth_url is None:
# It's not configured, let's not load tests
return
manager = clients.ClientManager(conf)
endpoint = manager.identity_client.get_endpoint_url(
'orchestration', conf.region)
host = urlparse.urlparse(endpoint).hostname
os.environ['OS_TOKEN'] = manager.identity_client.auth_token
os.environ['PREFIX'] = test.rand_name('api')
return driver.build_tests(test_dir, loader, host=host,
url=endpoint, test_loader_name=__name__)
def load_tests(loader, tests, pattern):
"""Provide a TestSuite to the discovery process."""
# Set and environment variable for one of the tests.
os.environ['GABBI_TEST_URL'] = 'takingnames'
prefix = os.environ.get('GABBI_PREFIX')
test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)
return driver.build_tests(test_dir, loader, host=None,
intercept=simple_wsgi.SimpleWsgi,
prefix=prefix,
fixture_module=sys.modules[__name__],
response_handlers=[TestResponseHandler])
def load_tests(loader, tests, pattern):
"""Provide a TestSuite to the discovery process."""
test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)
return driver.build_tests(test_dir, loader, host='google.com', port=443)
from gabbi import simple_wsgi
TESTS_DIR = 'gabbits_intercept'
class TestFixtureOne(fixture.GabbiFixture):
"""Drive the fixture testing weakly."""
pass
class TestFixtureTwo(fixture.GabbiFixture):
"""Drive the fixture testing weakly."""
pass
class TestResponseHandler(handlers.ResponseHandler):
"""A sample response handler just to test."""
test_key_suffix = 'test'
test_key_value = []
def preprocess(self, test):
"""Add some data if the data is a string."""
try:
test.output = test.output + '\nAnother line'
except TypeError:
pass
def action(self, test, expected, value=None):
expected = expected.replace('COW', '', 1)
test.assertIn(expected, test.output)
def test_gabbits():
test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)
# Pass "require_ssl=True" as an argument to force all tests
# to use SSL in requests.
test_generator = driver.py_test_generator(
test_dir, intercept=wsgiapp.app,
fixture_module=fixtures)
for test in test_generator:
yield test
from gabbi import driver
from gabbi import fixture
from gabbi import handlers
from gabbi import simple_wsgi
TESTS_DIR = 'gabbits_intercept'
class TestFixtureOne(fixture.GabbiFixture):
"""Drive the fixture testing weakly."""
pass
class TestFixtureTwo(fixture.GabbiFixture):
"""Drive the fixture testing weakly."""
pass
class TestResponseHandler(handlers.ResponseHandler):
"""A sample response handler just to test."""
test_key_suffix = 'test'
test_key_value = []
def preprocess(self, test):
"""Add some data if the data is a string."""
try:
test.output = test.output + '\nAnother line'
except TypeError:
pass
def preprocess(self, test):
"""Add some data if the data is a string."""
try:
test.output = test.output + '\nAnother line'
except TypeError:
pass
def action(self, test, expected, value=None):
expected = expected.replace('COW', '', 1)
test.assertIn(expected, test.output)
# Incorporate the SkipAllFixture into this namespace so it can be used
# by tests (cf. skipall.yaml).
SkipAllFixture = fixture.SkipAllFixture
def load_tests(loader, tests, pattern):
"""Provide a TestSuite to the discovery process."""
# Set and environment variable for one of the tests.
os.environ['GABBI_TEST_URL'] = 'takingnames'
prefix = os.environ.get('GABBI_PREFIX')
test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)
return driver.build_tests(test_dir, loader, host=None,
intercept=simple_wsgi.SimpleWsgi,
prefix=prefix,
fixture_module=sys.modules[__name__],
response_handlers=[TestResponseHandler])
"""
import os
import sys
from gabbi import driver
from gabbi import fixture
from gabbi import handlers
from gabbi import simple_wsgi
TESTS_DIR = 'gabbits_intercept'
class TestFixtureOne(fixture.GabbiFixture):
"""Drive the fixture testing weakly."""
pass
class TestFixtureTwo(fixture.GabbiFixture):
"""Drive the fixture testing weakly."""
pass
class TestResponseHandler(handlers.ResponseHandler):
"""A sample response handler just to test."""
test_key_suffix = 'test'
test_key_value = []
def preprocess(self, test):
# use gabbi to create the test suite from our declaration
suite = test_suite_from_yaml(
unittest.defaultTestLoader,
self.id(),
gabbi_declaration,
'.',
host,
None,
None,
None,
)
# run the test (we store the the output into a custom stream so that hypothesis can display only the simple
# case test result on failure rather than every failing case)
s = StringIO()
result = ConciseTestRunner(stream=s, verbosity=0).run(suite)
# if we weren't successfull we need to fail the test case with the error string from gabbi
if not result.wasSuccessful():
self.fail(s.getvalue())