예제 #1
0
def test_parse_endpoint_relation():
    """
    Complex (subject+object) endpoints can be parsed.

    """
    operation, ns = Namespace.parse_endpoint("foo.search_for.bar.v1")
    assert_that(operation, is_(equal_to(Operation.SearchFor)))
    assert_that(ns.subject, is_(equal_to("foo")))
    assert_that(ns.object_, is_(equal_to("bar")))
예제 #2
0
def test_parse_endpoint():
    """
    Simple (subject-only) endpoints can be parsed.

    """
    operation, ns = Namespace.parse_endpoint("foo.search.v1")
    assert_that(operation, is_(equal_to(Operation.Search)))
    assert_that(ns.subject, is_(equal_to("foo")))
    assert_that(ns.object_, is_(none()))
def test_parse_endpoint_relation():
    """
    Complex (subject+object) endpoints can be parsed.

    """
    operation, ns = Namespace.parse_endpoint("foo.search_for.bar.v1")
    assert_that(operation, is_(equal_to(Operation.SearchFor)))
    assert_that(ns.subject, is_(equal_to("foo")))
    assert_that(ns.object_, is_(equal_to("bar")))
def test_parse_endpoint():
    """
    Simple (subject-only) endpoints can be parsed.

    """
    operation, ns = Namespace.parse_endpoint("foo.search.v1")
    assert_that(operation, is_(equal_to(Operation.Search)))
    assert_that(ns.subject, is_(equal_to("foo")))
    assert_that(ns.object_, is_(none()))
예제 #5
0
def test_parse_endpoint_swagger():
    """
    Versioned discovery endpoint can be parsed.

    """
    operation, ns = Namespace.parse_endpoint("swagger.discover.v2")
    assert_that(operation, is_(equal_to(Operation.Discover)))
    assert_that(ns.subject, is_(equal_to("swagger")))
    assert_that(ns.version, is_(equal_to("v2")))
    assert_that(ns.object_, is_(none()))
def test_parse_endpoint_swagger():
    """
    Versioned discovery endpoint can be parsed.

    """
    operation, ns = Namespace.parse_endpoint("swagger.discover.v2")
    assert_that(operation, is_(equal_to(Operation.Discover)))
    assert_that(ns.subject, is_(equal_to("swagger")))
    assert_that(ns.version, is_(equal_to("v2")))
    assert_that(ns.object_, is_(none()))
예제 #7
0
def iter_endpoints(graph, match_func):
    """
    Iterate through matching endpoints.

    The `match_func` is expected to have a signature of:

        def matches(operation, ns, rule):
            return True

    :returns: a generator over (`Operation`, `Namespace`, rule, func) tuples.

    """
    for rule in graph.flask.url_map.iter_rules():
        try:
            operation, ns = Namespace.parse_endpoint(rule.endpoint)
        except (IndexError, ValueError, InternalServerError):
            # operation follows a different convention (e.g. "static")
            continue
        else:
            # match_func gets access to rule to support path version filtering
            if match_func(operation, ns, rule):
                func = graph.flask.view_functions[rule.endpoint]
                yield operation, ns, rule, func
예제 #8
0
def iter_endpoints(graph, match_func):
    """
    Iterate through matching endpoints.

    The `match_func` is expected to have a signature of:

        def matches(operation, ns, rule):
            return True

    :returns: a generator over (`Operation`, `Namespace`, rule, func) tuples.

    """
    for rule in graph.flask.url_map.iter_rules():
        try:
            operation, ns = Namespace.parse_endpoint(rule.endpoint, get_converter(rule))
        except (IndexError, ValueError, InternalServerError):
            # operation follows a different convention (e.g. "static")
            continue
        else:
            # match_func gets access to rule to support path version filtering
            if match_func(operation, ns, rule):
                func = graph.flask.view_functions[rule.endpoint]
                yield operation, ns, rule, func