How to use the mkmsdk.exceptions.MissingParam function in mkmsdk

To help you get started, we’ve selected a few mkmsdk 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 evonove / mkm-sdk / tests / tests_unit / test_resolvers.py View on Github external
def test_if_bad_parameters_are_handled_correctly():
    """Verifies exception is thrown when user passes an unexisting parameter."""
    live_resolver = SimpleResolver(_API_MAP["1.1"]["api_root"])
    simple_api_map_with_parameters = {"url": "/user/{user}", "method": "get"}

    with pytest.raises(exceptions.MissingParam):
        live_resolver.setup(simple_api_map_with_parameters)

    with pytest.raises(exceptions.MissingParam):
        live_resolver.setup(simple_api_map_with_parameters, bad_param="Worst parameter ever")
github evonove / mkm-sdk / tests / tests_unit / test_resolvers.py View on Github external
def test_if_bad_parameters_are_handled_correctly():
    """Verifies exception is thrown when user passes an unexisting parameter."""
    live_resolver = SimpleResolver(_API_MAP["1.1"]["api_root"])
    simple_api_map_with_parameters = {"url": "/user/{user}", "method": "get"}

    with pytest.raises(exceptions.MissingParam):
        live_resolver.setup(simple_api_map_with_parameters)

    with pytest.raises(exceptions.MissingParam):
        live_resolver.setup(simple_api_map_with_parameters, bad_param="Worst parameter ever")
github evonove / mkm-sdk / tests / tests_unit / test_exception.py View on Github external
def test_missing_param():
    """Test error string is formatted correctly"""
    error = MissingParam("payment_id")

    assert str(error) == "Missing payment_id parameter"
github evonove / mkm-sdk / mkmsdk / resolvers.py View on Github external
`api_map`: Dict with urls and methods for the request
            `kwargs`: Optional additional parameters to be attached to the url
        """

        if api_map is None:
            raise Exception("Resolve must be called with `api_map` argument")
        elif api_map.get("url") is None or api_map.get("method") is None:
            raise Exception("Resolve must be called with a map with `url` and `method`")

        url = api_map["url"]
        method = api_map["method"]

        try:
            url = url.format(**kwargs)
        except KeyError as param:
            raise exceptions.MissingParam(param=param)

        # We percent encode the url so that if any string has spaces,
        # commas or any other special character the url will be correctly formed anyway
        self.url = quote(url)
        self.method = method