How to use the pactman.verifier.matching_rule.Matcher.get_matcher 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
}
        }

    Returns a dict with lists of Matcher subclass instances (e.g. MatchType) for each of path, query, header and body.
    """
    matchers = {}
    if "path" in rules:
        # "path" rules are a bit different - there's no jsonpath as there's only a single value to compare, so we
        # hard-code the path to '' which always matches when looking for weighted path matches
        matchers["path"] = [MultipleMatchers("", **rules["path"])]
    if "query" in rules:
        # "query" rules are a bit different too - matchingRules are a flat single-level dictionary of keys which map to
        # array elements, but the data they match is keys mapping to an array, so alter the path such that the rule
        # maps to that array: "Q1" becomes "Q1[*]"
        matchers["query"] = [
            Matcher.get_matcher(path + "[*]", rule) for path, rule in rules["query"].items()
        ]
    for section in ["header", "body"]:
        if section in rules:
            matchers[section] = [
                Matcher.get_matcher(path, rule) for path, rule in rules[section].items()
            ]
    return matchers
github reecetech / pactman / pactman / verifier / matching_rule.py View on Github external
matchers = {}
    if "path" in rules:
        # "path" rules are a bit different - there's no jsonpath as there's only a single value to compare, so we
        # hard-code the path to '' which always matches when looking for weighted path matches
        matchers["path"] = [MultipleMatchers("", **rules["path"])]
    if "query" in rules:
        # "query" rules are a bit different too - matchingRules are a flat single-level dictionary of keys which map to
        # array elements, but the data they match is keys mapping to an array, so alter the path such that the rule
        # maps to that array: "Q1" becomes "Q1[*]"
        matchers["query"] = [
            Matcher.get_matcher(path + "[*]", rule) for path, rule in rules["query"].items()
        ]
    for section in ["header", "body"]:
        if section in rules:
            matchers[section] = [
                Matcher.get_matcher(path, rule) for path, rule in rules[section].items()
            ]
    return matchers
github reecetech / pactman / pactman / verifier / matching_rule.py View on Github external
}
        }

    Returns a dict with lists of Matcher subclass instances (e.g. MatchType) for each of path, query, header and body.
    """
    matchers = defaultdict(list)
    for path, spec in rules.items():
        split = list(split_path(path))
        section = split[1]
        if section == "query":
            # query rules need to be fudged so they match the elements of the *array* if the path
            # doesn't already reference the array - so $.query.customer_number will become
            # $.query.customer_number[*] but $.query.customer_number[1] will be untouched
            if split[-1][0] not in "*0123456789":
                path += "[*]"
        matchers[section].append(Matcher.get_matcher(path, spec))
    return matchers
github reecetech / pactman / pactman / verifier / matching_rule.py View on Github external
def __init__(self, path, matchers=None, combine="AND"):
        super().__init__(path, matchers)
        self.matchers = [Matcher.get_matcher(path, rule) for rule in matchers]
        self.combine = combine