예제 #1
0
    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,
        )

        # 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())
예제 #2
0
파일: runner.py 프로젝트: TheMatrix97/gabbi
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):
    """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}

    loader = unittest.defaultTestLoader
    test_suite = suitemaker.test_suite_from_dict(
        loader, name, data, data_dir, host, port, None, None, prefix=prefix,
        handlers=handler_objects, test_loader_name='gabbi-runner')

    # The default runner stream is stderr.
    stream = sys.stderr
    if quiet:
        # We want to swallow the output that the runner is
        # producing.
        stream = open(os.devnull, 'w')
    result = ConciseTestRunner(
        stream=stream, verbosity=2, failfast=failfast).run(test_suite)
    return result.wasSuccessful()
예제 #3
0
def run_suite(handle,
              handler_objects,
              host,
              port,
              prefix,
              force_ssl=False,
              failfast=False,
              data_dir='.',
              verbosity=False,
              name='input',
              safe_yaml=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}

    loader = unittest.defaultTestLoader
    test_suite = suitemaker.test_suite_from_dict(
        loader,
        name,
        data,
        data_dir,
        host,
        port,
        None,
        None,
        prefix=prefix,
        handlers=handler_objects,
        test_loader_name='gabbi-runner')

    result = ConciseTestRunner(verbosity=2, failfast=failfast).run(test_suite)
    return result.wasSuccessful()
예제 #4
0
    def run_gabbi(self, gabbi_declaration):

        # Take only the host name and port from the live server:
        _, authority = self.live_server_url.split('://')
        host, port = authority.split(':')

        # Use Gabbi to create the test suite from our declaration:
        suite = test_suite_from_dict(
            loader=defaultTestLoader,
            test_base_name=self.id(),
            suite_dict=gabbi_declaration,
            test_directory='.',
            host=host,
            port=port,
            fixture_module=None,
            intercept=None,
            handlers=[
                handler()
                for handler in RESPONSE_HANDLERS
            ],
        )

        # 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 successful we need to fail the test case with the error
        # string from Gabbi:
        if not result.wasSuccessful():
            self.fail(
                s.getvalue(),
            )
예제 #5
0
파일: runner.py 프로젝트: cdent/gabbi
def run_suite(handle, handler_objects, host, port, prefix, force_ssl=False,
              failfast=False, data_dir='.', verbosity=False, name='input',
              safe_yaml=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}

    loader = unittest.defaultTestLoader
    test_suite = suitemaker.test_suite_from_dict(
        loader, name, data, data_dir, host, port, None, None, prefix=prefix,
        handlers=handler_objects, test_loader_name='gabbi-runner')

    result = ConciseTestRunner(
        verbosity=2, failfast=failfast).run(test_suite)
    return result.wasSuccessful()
예제 #6
0
def run():
    """Run simple tests from STDIN.

    This command provides a way to run a set of tests encoded in YAML that
    is provided on STDIN. No fixtures are supported, so this is primarily
    designed for use with real running services.

    Host and port information may be provided in two different ways:

    * In the URL value of the tests.
    * In a `host` or `host:port` argument on the command line.

    An example run might looks like this::

        gabbi-run example.com:9999 < mytest.yaml

    It is also possible to provide a URL prefix which can be useful if the
    target application might be mounted in different locations. An example:

        gabbi-run example.com:9999 /mountpoint < mytest.yaml

    Use `-x` to abort after the first error or failure:

        gabbi-run -x example.com:9999 /mountpoint < mytest.yaml

    Output is formatted as unittest summary information.
    """
    args = sys.argv[1:]

    try:
        args.remove("-x")
        failfast = True
    except ValueError:
        failfast = False

    try:
        hostport = args[0]
        if ':' in hostport:
            host, port = hostport.split(':')
        else:
            host = hostport
            port = None
    except IndexError:
        host, port = 'stub', None

    try:
        prefix = args[1]
    except IndexError:
        prefix = None

    loader = unittest.defaultTestLoader

    # Initialize the extensions for response handling.
    for handler in driver.RESPONSE_HANDLERS:
        handler(case.HTTPTestCase)

    data = yaml.safe_load(sys.stdin.read())
    suite = driver.test_suite_from_yaml(loader, 'input', data, '.',
                                        host, port, None, None,
                                        prefix=prefix)
    result = ConciseTestRunner(verbosity=2, failfast=failfast).run(suite)
    sys.exit(not result.wasSuccessful())
예제 #7
0
def run():
    """Run simple tests from STDIN.

    This command provides a way to run a set of tests encoded in YAML that
    is provided on STDIN. No fixtures are supported, so this is primarily
    designed for use with real running services.

    Host and port information may be provided in three different ways:

    * In the URL value of the tests.
    * In a `host` or `host:port` argument on the command line.
    * In a URL on the command line.

    An example run might looks like this::

        gabbi-run example.com:9999 < mytest.yaml

    or::

        gabbi-run http://example.com:999 < mytest.yaml

    It is also possible to provide a URL prefix which can be useful if the
    target application might be mounted in different locations. An example::

        gabbi-run example.com:9999 /mountpoint < mytest.yaml

    or::

        gabbi-run http://example.com:9999/mountpoint < mytest.yaml

    Use `-x` or `--failfast` to abort after the first error or failure:

        gabbi-run -x example.com:9999 /mountpoint < mytest.yaml

    Output is formatted as unittest summary information.
    """

    parser = argparse.ArgumentParser(description="Run gabbi tests from STDIN")
    parser.add_argument(
        "target",
        nargs="?",
        default="stub",
        help="A fully qualified URL (with optional path as prefix) "
        "to the primary target or a host and port, : separated",
    )
    parser.add_argument(
        "prefix",
        nargs="?",
        default=None,
        help="Path prefix where target app is mounted. Only used when " "target is of the form host[:port]",
    )
    parser.add_argument("-x", "--failfast", action="store_true", help="Exit on first failure")
    parser.add_argument(
        "-r",
        "--response-handler",
        nargs="?",
        default=None,
        dest="response_handlers",
        action="append",
        help="Custom response handler. Should be an import path of the " "form package.module or package.module:class.",
    )
    args = parser.parse_args()

    split_url = urlparse.urlsplit(args.target)
    if split_url.scheme:
        target = split_url.netloc
        prefix = split_url.path
    else:
        target = args.target
        prefix = args.prefix

    if ":" in target:
        host, port = target.split(":")
    else:
        host = target
        port = None

    # Initialize response handlers.
    custom_response_handlers = []
    for import_path in args.response_handlers or []:
        for handler in load_response_handlers(import_path):
            custom_response_handlers.append(handler)
    for handler in driver.RESPONSE_HANDLERS + custom_response_handlers:
        handler(case.HTTPTestCase)

    data = yaml.safe_load(sys.stdin.read())
    loader = unittest.defaultTestLoader
    suite = driver.test_suite_from_dict(loader, "input", data, ".", host, port, None, None, prefix=prefix)
    result = ConciseTestRunner(verbosity=2, failfast=args.failfast).run(suite)
    sys.exit(not result.wasSuccessful())
예제 #8
0
def run():
    """Run simple tests from STDIN.

    This command provides a way to run a set of tests encoded in YAML that
    is provided on STDIN. No fixtures are supported, so this is primarily
    designed for use with real running services.

    Host and port information may be provided in three different ways:

    * In the URL value of the tests.
    * In a `host` or `host:port` argument on the command line.
    * In a URL on the command line.

    An example run might looks like this::

        gabbi-run example.com:9999 < mytest.yaml

    or::

        gabbi-run http://example.com:999 < mytest.yaml

    It is also possible to provide a URL prefix which can be useful if the
    target application might be mounted in different locations. An example::

        gabbi-run example.com:9999 /mountpoint < mytest.yaml

    or::

        gabbi-run http://example.com:9999/mountpoint < mytest.yaml

    Use `-x` or `--failfast` to abort after the first error or failure:

        gabbi-run -x example.com:9999 /mountpoint < mytest.yaml

    Output is formatted as unittest summary information.
    """

    parser = argparse.ArgumentParser(description='Run gabbi tests from STDIN')
    parser.add_argument(
        'target',
        nargs='?',
        default='stub',
        help='A fully qualified URL (with optional path as prefix) '
        'to the primary target or a host and port, : separated')
    parser.add_argument(
        'prefix',
        nargs='?',
        default=None,
        help='Path prefix where target app is mounted. Only used when '
        'target is of the form host[:port]')
    parser.add_argument('-x',
                        '--failfast',
                        action='store_true',
                        help='Exit on first failure')
    parser.add_argument(
        '-r',
        '--response-handler',
        nargs='?',
        default=None,
        dest='response_handlers',
        action='append',
        help='Custom response handler. Should be an import path of the '
        'form package.module or package.module:class.')
    args = parser.parse_args()

    split_url = urlparse.urlsplit(args.target)
    if split_url.scheme:
        target = split_url.netloc
        prefix = split_url.path
    else:
        target = args.target
        prefix = args.prefix

    if ':' in target:
        host, port = target.split(':')
    else:
        host = target
        port = None

    # Initialize response handlers.
    custom_response_handlers = []
    for import_path in (args.response_handlers or []):
        for handler in load_response_handlers(import_path):
            custom_response_handlers.append(handler)
    for handler in driver.RESPONSE_HANDLERS + custom_response_handlers:
        handler(case.HTTPTestCase)

    data = yaml.safe_load(sys.stdin.read())
    loader = unittest.defaultTestLoader
    suite = driver.test_suite_from_dict(loader,
                                        'input',
                                        data,
                                        '.',
                                        host,
                                        port,
                                        None,
                                        None,
                                        prefix=prefix)
    result = ConciseTestRunner(verbosity=2, failfast=args.failfast).run(suite)
    sys.exit(not result.wasSuccessful())
예제 #9
0
파일: runner.py 프로젝트: moreati/gabbi
def run():
    """Run simple tests from STDIN.

    This command provides a way to run a set of tests encoded in YAML that
    is provided on STDIN. No fixtures are supported, so this is primarily
    designed for use with real running services.

    Host and port information may be provided in three different ways:

    * In the URL value of the tests.
    * In a `host` or `host:port` argument on the command line.
    * In a URL on the command line.

    An example run might looks like this::

        gabbi-run example.com:9999 < mytest.yaml

    or::

        gabbi-run http://example.com:999 < mytest.yaml

    It is also possible to provide a URL prefix which can be useful if the
    target application might be mounted in different locations. An example::

        gabbi-run example.com:9999 /mountpoint < mytest.yaml

    or::

        gabbi-run http://example.com:9999/mountpoint < mytest.yaml

    Use `-x` or `--failfast` to abort after the first error or failure:

        gabbi-run -x example.com:9999 /mountpoint < mytest.yaml

    Output is formatted as unittest summary information.
    """

    parser = argparse.ArgumentParser(description='Run gabbi tests from STDIN')
    parser.add_argument(
        'target',
        nargs='?', default='stub',
        help='A fully qualified URL (with optional path as prefix) '
             'to the primary target or a host and port, : separated'
    )
    parser.add_argument(
        'prefix',
        nargs='?', default=None,
        help='Path prefix where target app is mounted. Only used when '
             'target is of the form host[:port]'
    )
    parser.add_argument(
        '-x', '--failfast',
        help='Exit on first failure',
        action='store_true'
    )

    args = parser.parse_args()

    split_url = urlparse.urlsplit(args.target)
    if split_url.scheme:
        target = split_url.netloc
        prefix = split_url.path
    else:
        target = args.target
        prefix = args.prefix

    if ':' in target:
        host, port = target.split(':')
    else:
        host = target
        port = None

    loader = unittest.defaultTestLoader

    # Initialize the extensions for response handling.
    for handler in driver.RESPONSE_HANDLERS:
        handler(case.HTTPTestCase)

    data = yaml.safe_load(sys.stdin.read())
    suite = driver.test_suite_from_yaml(loader, 'input', data, '.',
                                        host, port, None, None,
                                        prefix=prefix)
    result = ConciseTestRunner(verbosity=2, failfast=args.failfast).run(suite)
    sys.exit(not result.wasSuccessful())