How to use the gabbi.case function in gabbi

To help you get started, we’ve selected a few gabbi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wildfish / gabbi-hypothesis-demo / app / test_case.py View on Github external
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,
        )
github cdent / gabbi / gabbi / suitemaker.py View on Github external
'malformed test chunk "%s": %s' % (test_dict, exc))

        test_name = self._set_test_name(test)
        self._set_test_method_and_url(test, test_name)
        self._validate_keys(test, test_name)

        http_class = httpclient.get_http(verbose=test['verbose'],
                                         caption=test['name'],
                                         cert_validate=test['cert_validate'])
        if prior_test:
            history = prior_test.history
        else:
            history = {}

        test_method_name = 'test_request'
        test_method = getattr(case.HTTPTestCase, test_method_name)

        @case.testcase.skipIf(self.host == '', 'No host configured')
        @functools.wraps(test_method)
        def do_test(*args, **kwargs):
            return test_method(*args, **kwargs)

        # Use metaclasses to build a class of the necessary type
        # and name with relevant arguments.
        klass = TestBuilder(test_name, (case.HTTPTestCase,),
                            {'test_data': test,
                             'test_directory': self.test_directory,
                             'fixtures': self.fixture_classes,
                             'inner_fixtures': self.inner_fixtures,
                             'http': http_class,
                             'host': self.host,
                             'intercept': self.intercept,
github cdent / gabbi / gabbi / suitemaker.py View on Github external
        @case.testcase.skipIf(self.host == '', 'No host configured')
        @functools.wraps(test_method)
        def do_test(*args, **kwargs):
            return test_method(*args, **kwargs)
github cdent / gabbi / gabbi / suitemaker.py View on Github external
try:
        test_data = suite_dict['tests']
    except KeyError:
        raise GabbiFormatError('malformed test file, "tests" key required')
    except TypeError:
        # `suite_dict` appears not to be a dictionary; we cannot infer
        # any details or suggestions on how to fix it, thus discarding
        # the original exception in favor of a generic error
        raise GabbiFormatError('malformed test file, invalid format')

    handlers = handlers or []
    response_handlers = []
    content_handlers = []

    # Merge global with per-suite defaults
    default_test_dict = copy.deepcopy(case.HTTPTestCase.base_test)
    seen_keys = set()
    for handler in handlers:
        default_test_dict.update(handler.test_base)
        if handler.response_handler:
            if handler.test_key_suffix not in seen_keys:
                response_handlers.append(handler.response_handler)
                seen_keys.add(handler.test_key_suffix)
        if handler.content_handler:
            content_handlers.append(handler.content_handler)

    local_defaults = _validate_defaults(suite_dict.get('defaults', {}))
    test_update(default_test_dict, local_defaults)

    # Establish any fixture classes used in this file.
    fixtures = suite_dict.get('fixtures', None)
    fixture_classes = []