How to use the pactman.verifier.matching_rule.RuleFailed function in pactman

To help you get started, we’ve selected a few pactman 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 reecetech / pactman / pactman / verifier / matching_rule.py View on Github external
def apply(self, data, spec, path):
        log.debug(f"MultipleMatchers.__call__ {data!r} {spec!r} {path!r}")
        for matcher in self.matchers:
            log.debug(f"... matching {matcher}")
            try:
                matcher.apply(data, spec, path)
            except RuleFailed:
                if self.combine == "AND":
                    raise
            else:
                if self.combine == "OR":
                    return
github reecetech / pactman / pactman / verifier / matching_rule.py View on Github external
def apply(self, data, spec, path):
        log.debug(f"match equality {data!r} {spec!r} {path!r}")
        if data != spec:
            raise RuleFailed(path, f"value {data!r} does not equal expected {spec!r}")
github reecetech / pactman / pactman / verifier / verify.py View on Github external
def apply_rules(self, data, spec, path):
        # given some actual data and a pact spec at a certain path, check any rules for that path
        log.debug(f"apply_rules data={data!r} spec={spec!r} path={format_path(path)}")
        weighted_rule = self.find_rule(path)
        log.debug(f"... rule lookup got {weighted_rule}")
        if weighted_rule:
            try:
                weighted_rule.rule.apply(data, spec, path)
            except RuleFailed as e:
                log.debug(f"... failed: {e}")
                return self.result.fail(str(e), path)
            log.debug("... passed")

        # we passed the matchingRule but we also need to check the contents of arrays/dicts
        if fold_type(spec) is list:
            r = self.apply_rules_array(data, spec, path)
            log.debug(f"apply_rules {format_path(path)} success={r!r}")
            return r
        elif fold_type(spec) is dict:
            r = self.apply_rules_dict(data, spec, path)
            log.debug(f"apply_rules {format_path(path)} success={r!r}")
            return r
        elif not weighted_rule:
            if path[0] in ("header", "headers"):
                log.debug("... falling back on header matching")
github reecetech / pactman / pactman / verifier / matching_rule.py View on Github external
def check_min(self, data, path):
        if "min" not in self.rule:
            return
        if type(data) not in (dict, list, str):
            return
        if len(data) < self.rule["min"]:
            raise RuleFailed(
                path, f'size {len(data)!r} is smaller than minimum size {self.rule["min"]}'
            )
github reecetech / pactman / pactman / verifier / matching_rule.py View on Github external
def check_max(self, data, path):
        if "max" not in self.rule:
            return
        if type(data) not in (dict, list, str):
            return
        if len(data) > self.rule["max"]:
            raise RuleFailed(
                path, f'size {len(data)!r} is larger than maximum size {self.rule["max"]}'
            )