How to use the gabbi.exception.GabbiFormatError 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 cdent / gabbi / gabbi / case.py View on Github external
def _replace_headers_template(self, test_name, headers):
        replaced_headers = {}

        try:
            for name in headers:
                replaced_name = self.replace_template(name)
                replaced_headers[replaced_name] = self.replace_template(
                    headers[name]
                )
        except TypeError as exc:
            raise exception.GabbiFormatError(
                'malformed headers in test %s: %s' % (test_name, exc))

        return replaced_headers
github cdent / gabbi / gabbi / suitemaker.py View on Github external
:param fixtures: An optional list of fixture classes that this suite
                     can use.
    :param defaults: An optional dictionary of default values to be used
                     in each test.
    :param tests: A list of individual tests, themselves each being a
                  dictionary. See :data:`gabbi.case.BASE_TEST`.
    """
    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)
github cdent / gabbi / gabbi / handlers / base.py View on Github external
def __call__(self, test):
        if test.test_data[self._key]:
            self.preprocess(test)
            if not isinstance(
                    test.test_data[self._key], type(self.test_key_value)):
                raise GabbiFormatError(
                    "%s in '%s' has incorrect type, must be %s"
                    % (self._key, test.test_data['name'],
                       type(self.test_key_value)))
            for item in test.test_data[self._key]:
                try:
                    value = test.test_data[self._key][item]
                except (TypeError, KeyError):
                    value = None
                self.action(test, item, value=value)
github cdent / gabbi / gabbi / suitemaker.py View on Github external
def _validate_keys(self, test, test_name):
        """Check for invalid keys.

        If there are any, raise a GabbiFormatError.
        """
        test_keys = set(test.keys())
        if test_keys != self.default_keys:
            raise GabbiFormatError(
                'Invalid test keys used in test %s: %s'
                % (test_name,
                   ', '.join(list(test_keys - self.default_keys))))
github cdent / gabbi / gabbi / suitemaker.py View on Github external
method_key = None
        for key, val in test.items():
            if _is_method_shortcut(key):
                if method_key:
                    raise GabbiFormatError(
                        'duplicate method/URL directive in "%s"' %
                        test_name)

                test['method'] = key
                test['url'] = val
                method_key = key
        if method_key:
            del test[method_key]

        if not test['url']:
            raise GabbiFormatError('Test url missing in test %s.'
                                   % test_name)
github cdent / gabbi / gabbi / suitemaker.py View on Github external
def _validate_defaults(defaults):
    """Ensure default test settings are acceptable.

    Raises GabbiFormatError for invalid settings.
    """
    if any(_is_method_shortcut(key) for key in defaults):
        raise GabbiFormatError('"METHOD: url" pairs not allowed in defaults')
    return defaults