Exemplo n.º 1
0
    def _proc(request: Dict[str, Any]):
        # TODO: a request without path it's a valid request?
        if "path" in request:
            endpoint = pa.find_endpoint(rules, request["path"])
            # TODO: how can i deal if no endpoint found?
        else:
            return request
        rule = rules[endpoint]
        if "method" in rule and "method" in request:
            rules_method = rule["method"]
            if isinstance(rules_method, list) and not request["method"] in rules_method:
                return request
            elif request["method"] != rules_method:
                return request

        if "pathParams" in rule:
            request["path"] = pa.merge_paths(request["path"], endpoint, rule["pathParams"])
        if "queryParams" in rule:
            if "override" in rule and "queryParams" in rule["override"]:
                request["path"] = pa.override_query(request["path"], rule["queryParams"])
            else:
                request["path"] = pa.merge_queries(request["path"], rule["queryParams"])
        if "body" in rule:
            if "override" in rule and "body" in rule["override"]:
                proc = bo.override_body
            else:
                proc = bo.merge_body
            request["body"] = proc(request["body"], rule["body"])
        return request
Exemplo n.º 2
0
def test_find_endpoint_with_several_rules():
    path = "/some/{thing}/is/dinamic"
    rules = {
        path: {},
        "/this/is/not/the/path/you/are/looking/for": {},
        "/some/times/is/similar": {}
    }
    res = pa.find_endpoint(rules, "/some/how/is/dinamic")
    assert res == path
Exemplo n.º 3
0
def test_find_endpoint_invalid_params():
    none_expected_cases = [(None, None), ({}, None), (None, {}), ({}, {})]

    for a, b in none_expected_cases:
        res = pa.find_endpoint(a, b)
        assert res is None
Exemplo n.º 4
0
def test_find_endpoint_with_params():
    path = "/some/{thing}/is/dinamic"
    rules = {path: {}}
    res = pa.find_endpoint(rules, "/some/how/is/dinamic")
    assert res == path
Exemplo n.º 5
0
def test_find_endpoint_happy_path():
    path = "/some/good/path"
    rules = {path: {}}
    res = pa.find_endpoint(rules, path)
    assert res == path
Exemplo n.º 6
0
def test_endpoint_not_found():
    rules = {}
    res = pa.find_endpoint(rules, "/some/good/path")
    assert res is None