How to use the pactman.mock.matchers.Like 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 / mock / matchers.py View on Github external
:return: A dict containing the information about what the contents of
            the request/response should be.
        :rtype: dict
        """
        return {
            "json_class": "Pact::SomethingLike",
            "contents": generate_ruby_protocol(self.matcher),
        }

    def generate_matching_rule_v3(self):
        return {"matchers": [{"match": "type"}]}


# Remove SomethingLike in major version 1.0.0
SomethingLike = Like


class Term(Matcher):
    """
    Expect the response to match a specified regular expression.

    Example:

    >>> from pactman import Consumer, Provider
    >>> pact = Consumer('consumer').has_pact_with(Provider('provider'))
    >>> (pact.given('the current user is logged in as `tester`')
    ...  .upon_receiving('a request for the user profile')
    ...  .with_request('get', '/profile')
    ...  .will_respond_with(200, body={
    ...    'name': 'tester',
    ...    'theme': Term('light|dark|legacy', 'dark')
github reecetech / pactman / pactman / mock / matchers.py View on Github external
return term.ruby_protocol()
    else:
        raise ValueError("Unknown type: %s" % type(term))


# For backwards compatiblity with test code that uses pact-python to declare pacts,
# allow the various classes from that package to also be used to define rules
try:
    import pact as pact_python

    LIKE_CLASSES = (Like, pact_python.Like)
    EACHLIKE_CLASSES = (EachLike, pact_python.EachLike)
    TERM_CLASSES = (Term, pact_python.Term)
except ImportError:
    pact_python = None
    LIKE_CLASSES = (Like,)
    EACHLIKE_CLASSES = (EachLike,)
    TERM_CLASSES = (Term,)


# this function is long and complex (C901) because it has to handle the pact-python
# types :-(
def get_generated_values(input):  # noqa: C901
    """
    Resolve (nested) Matchers to their generated values for assertion.

    :param input: The input to be resolved to its generated values.
    :type input: None, list, dict, int, float, bool, str, unicode, Matcher
    :return: The input resolved to its generated value(s)
    :rtype: None, list, dict, int, float, bool, str, unicode, Matcher
    """
    if input is None:
github reecetech / pactman / pactman / mock / matchers.py View on Github external
elif isinstance(term, dict):
        return {k: generate_ruby_protocol(v) for k, v in term.items()}
    elif isinstance(term, list):
        return [generate_ruby_protocol(t) for i, t in enumerate(term)]
    elif issubclass(term.__class__, (Matcher,)):
        return term.ruby_protocol()
    else:
        raise ValueError("Unknown type: %s" % type(term))


# For backwards compatiblity with test code that uses pact-python to declare pacts,
# allow the various classes from that package to also be used to define rules
try:
    import pact as pact_python

    LIKE_CLASSES = (Like, pact_python.Like)
    EACHLIKE_CLASSES = (EachLike, pact_python.EachLike)
    TERM_CLASSES = (Term, pact_python.Term)
except ImportError:
    pact_python = None
    LIKE_CLASSES = (Like,)
    EACHLIKE_CLASSES = (EachLike,)
    TERM_CLASSES = (Term,)


# this function is long and complex (C901) because it has to handle the pact-python
# types :-(
def get_generated_values(input):  # noqa: C901
    """
    Resolve (nested) Matchers to their generated values for assertion.

    :param input: The input to be resolved to its generated values.