How to use the tavern.util.exceptions.BadSchemaError function in tavern

To help you get started, we’ve selected a few tavern 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 taverntesting / tavern / tavern / testutils / pytesthook / item.py View on Github external
try:
            fixture_values = self._load_fixture_values()
            self.global_cfg["variables"].update(fixture_values)

            call_hook(
                self.global_cfg,
                "pytest_tavern_beta_before_every_test_run",
                test_dict=self.spec,
                variables=self.global_cfg["variables"],
            )

            verify_tests(self.spec)

            run_test(self.path, self.spec, self.global_cfg)
        except exceptions.BadSchemaError:
            if xfail == "verify":
                logger.info("xfailing test while verifying schema")
            else:
                raise
        except exceptions.TavernException:
            if xfail == "run":
                logger.info("xfailing test when running")
            else:
                raise
        else:
            if xfail:
                logger.error("Expected test to fail")
                raise exceptions.TestFailError(
                    "Expected test to fail at {} stage".format(xfail)
                )
github taverntesting / tavern / tests / unit / test_utilities.py View on Github external
def test_get_nonexistent_function(self):
        """No name in module
        """

        spec = {"function": "os:aaueurhg"}

        with pytest.raises(exceptions.BadSchemaError):
            validate_extensions(spec, None, None)
github taverntesting / tavern / tavern / testutils / helpers.py View on Github external
def validate_pykwalify(response, schema):
    """Make sure the response matches a given schema

    Args:
        response (Response): reqeusts.Response object
        schema (dict): Schema for response
    """
    try:
        to_verify = response.json()
    except TypeError as e:
        raise_from(
            exceptions.BadSchemaError(
                "Tried to match a pykwalify schema against a non-json response"
            ),
            e,
        )
    else:
        verify_generic(to_verify, schema)
github taverntesting / tavern / tavern / _plugins / rest / request.py View on Github external
filespec: Either a string with the path to a file or a dictionary with file_path and possible content_type and/or content_encoding

    Returns:
        tuple: (file path, content type, content encoding)
    """
    if isinstance(filespec, str):
        return filespec, None, None
    elif isinstance(filespec, dict):
        return (
            filespec.get("file_path"),
            filespec.get("content_type"),
            filespec.get("content_encoding"),
        )
    else:
        # Could remove, also done in schema check
        raise exceptions.BadSchemaError(
            "File specification must be a path or a dictionary"
        )
github taverntesting / tavern / tavern / schemas / extensions.py View on Github external
if "function" not in input_value:
        raise BadSchemaError("No function specified for validation")

    try:
        import_ext_function(input_value["function"])
    except Exception as e:  # pylint: disable=broad-except
        raise_from(
            BadSchemaError("Couldn't load {}".format(input_value["function"])), e
        )

    extra_args = input_value.get("extra_args")
    extra_kwargs = input_value.get("extra_kwargs")

    if extra_args and not isinstance(extra_args, list):
        raise BadSchemaError(
            "Expected a list of extra_args, got {}".format(type(extra_args))
        )

    if extra_kwargs and not isinstance(extra_kwargs, dict):
        raise BadSchemaError(
            "Expected a dict of extra_kwargs, got {}".format(type(extra_args))
        )
github taverntesting / tavern / tests / unit / test_helpers.py View on Github external
def nonexistent_dict(self):
        with pytest.raises(exceptions.BadSchemaError):
            self._wrap_test_block({"file_path": "gogfgl"})
github taverntesting / tavern / tavern / testutils / pytesthook.py View on Github external
def _load_fixture_values(self):
        fixture_markers = self.iter_markers("usefixtures")

        values = {}

        for m in fixture_markers:
            if isinstance(m.args, (list, tuple)):
                mark_values = {f: self.funcargs[f] for f in m.args}
            elif isinstance(m.args, str):
                # Not sure if this can happen if validation is working
                # correctly, but it appears to be slightly broken so putting
                # this check here just in case
                mark_values = {m.args: self.funcargs[m.args]}
            else:
                raise exceptions.BadSchemaError(
                    (
                        "Can't handle 'usefixtures' spec of '{}'."
                        " There appears to be a bug in pykwalify so verification of"
                        " 'usefixtures' is broken - it should be a list of fixture"
                        " names"
                    ).format(m.args)
                )

            if any(mv in values for mv in mark_values):
                logger.warning("Overriding value for %s", mark_values)

            values.update(mark_values)

        return values
github taverntesting / tavern / tavern / schemas / extensions.py View on Github external
def check_is_timeout_val(v):
        if v is True or v is False or not (is_float_like(v) or is_int_like(v)):
            logger.debug("'timeout' value not a float/int")
            raise BadSchemaError(err_msg)
github taverntesting / tavern / tests / unit / test_utilities.py View on Github external
def test_get_invalid_module(self):
        """Nonexistent module
        """

        spec = {"function": "bleuuerhug:add"}

        with pytest.raises(exceptions.BadSchemaError):
            validate_extensions(spec, None, None)
github taverntesting / tavern / tavern / schemas / extensions.py View on Github external
for _, filespec in value.items():
        if isinstance(filespec, str):
            file_path = filespec
        elif isinstance(filespec, dict):
            valid = {"file_path", "content_type", "content_encoding"}
            extra = set(filespec.keys()) - valid
            if extra:
                raise BadSchemaError(
                    "Invalid extra keys passed to file upload block: {}".format(extra)
                )

            try:
                file_path = filespec["file_path"]
            except KeyError:
                raise BadSchemaError(
                    "When using 'long form' file uplaod spec, the file_path must be present"
                )
        else:
            raise BadSchemaError(
                "File specification must be a file path or a dictionary"
            )

        if not os.path.exists(file_path):
            raise BadSchemaError(
                "Path to file to upload '{}' was not found".format(file_path)
            )

    return True