Merge branch 'master' into fix-185
This commit is contained in:
commit
7f2c19f5b0
@ -269,8 +269,9 @@ flexibility when doing a ``POST`` or ``PUT``. If the value is not a
|
||||
string (that is, it is a sequence or structure) it is treated as a
|
||||
data structure which is turned into a JSON string. If the value is a
|
||||
string that begins with ``<@`` then the rest of the string is treated
|
||||
as the name of a file to be loaded from the same directory as the YAML
|
||||
file. If the value is an undecorated string, that's the value.
|
||||
as a filepath to be loaded. The path is relative to the test directory
|
||||
and may not traverse up into parent directories. If the value is an
|
||||
undecorated string, that's the value.
|
||||
|
||||
When reading from a file care should be taken to ensure that a
|
||||
reasonable content-type is set for the data as this will control if any
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
import argparse
|
||||
from importlib import import_module
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
@ -88,8 +89,10 @@ def run():
|
||||
else:
|
||||
for input_file in input_files:
|
||||
with open(input_file, 'r') as fh:
|
||||
data_dir = os.path.dirname(input_file)
|
||||
success = run_suite(fh, handler_objects, host, port,
|
||||
prefix, force_ssl, failfast, verbosity)
|
||||
prefix, force_ssl, failfast, data_dir,
|
||||
verbosity)
|
||||
if not failure: # once failed, this is considered immutable
|
||||
failure = not success
|
||||
if failure and failfast:
|
||||
@ -99,7 +102,7 @@ def run():
|
||||
|
||||
|
||||
def run_suite(handle, handler_objects, host, port, prefix, force_ssl=False,
|
||||
failfast=False, verbosity=False):
|
||||
failfast=False, data_dir='.', verbosity=False):
|
||||
"""Run the tests from the YAML in handle."""
|
||||
data = utils.load_yaml(handle)
|
||||
if force_ssl:
|
||||
@ -115,7 +118,7 @@ def run_suite(handle, handler_objects, host, port, prefix, force_ssl=False,
|
||||
|
||||
loader = unittest.defaultTestLoader
|
||||
test_suite = suitemaker.test_suite_from_dict(
|
||||
loader, 'input', data, '.', host, port, None, None, prefix=prefix,
|
||||
loader, 'input', data, data_dir, host, port, None, None, prefix=prefix,
|
||||
handlers=handler_objects)
|
||||
|
||||
result = ConciseTestRunner(
|
||||
|
1
gabbi/tests/gabbits_runner/subdir/sample.json
Normal file
1
gabbi/tests/gabbits_runner/subdir/sample.json
Normal file
@ -0,0 +1 @@
|
||||
{"items": {"house": "blue"}}
|
8
gabbi/tests/gabbits_runner/test_data.yaml
Normal file
8
gabbi/tests/gabbits_runner/test_data.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
tests:
|
||||
|
||||
- name: POST data from file
|
||||
verbose: true
|
||||
POST: /
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data: <@subdir/sample.json
|
@ -22,6 +22,7 @@ from wsgi_intercept.interceptor import Urllib3Interceptor
|
||||
|
||||
from gabbi import exception
|
||||
from gabbi.handlers import base
|
||||
from gabbi.handlers.jsonhandler import JSONHandler
|
||||
from gabbi import runner
|
||||
from gabbi.tests.simple_wsgi import SimpleWsgi
|
||||
|
||||
@ -249,9 +250,33 @@ class RunnerTest(unittest.TestCase):
|
||||
self.assertIn('{\n', output)
|
||||
self.assertIn('}\n', output)
|
||||
|
||||
def test_data_dir_good(self):
|
||||
"""Confirm that data dir is the test file's dir."""
|
||||
sys.argv = ['gabbi-run', 'http://%s:%s/foo' % (self.host, self.port)]
|
||||
|
||||
sys.argv.append('--')
|
||||
sys.argv.append('gabbi/tests/gabbits_runner/test_data.yaml')
|
||||
|
||||
with self.server():
|
||||
try:
|
||||
runner.run()
|
||||
except SystemExit as err:
|
||||
self.assertSuccess(err)
|
||||
|
||||
# Compare the verbose output of tests with pretty printed
|
||||
# data.
|
||||
with open('gabbi/tests/gabbits_runner/subdir/sample.json') as data:
|
||||
data = JSONHandler.loads(data.read())
|
||||
expected_string = JSONHandler.dumps(data, pretty=True)
|
||||
|
||||
sys.stdout.seek(0)
|
||||
output = sys.stdout.read()
|
||||
self.assertIn(expected_string, output)
|
||||
|
||||
def _run_verbosity_arg(self):
|
||||
sys.argv.append('--')
|
||||
sys.argv.append('gabbi/tests/gabbits_runner/verbosity.yaml')
|
||||
|
||||
with self.server():
|
||||
try:
|
||||
runner.run()
|
||||
|
Loading…
x
Reference in New Issue
Block a user