Пример #1
0
def build_path(operation: Operation, ns: Namespace, schema_request_arguments: Optional[Dict[Tuple, List[str]]] = None):
    expected_arguments: List[str] = (
        schema_request_arguments.get((ns.endpoint_for(operation), operation.value.method), [])
        if schema_request_arguments
        else []
    )

    expected_uri_templates = create_uri_templates(expected_arguments)

    try:
        # flask will sometimes try to quote '{' and '}' characters
        return unquote(ns.url_for(operation, _external=False, **expected_uri_templates))
    except (BuildError, ValueError) as error:
        # NB: The arguments were misidentified in the previous step, use the ones supplied by the error
        actual_arguments = (
            error.suggested.arguments   # type: ignore
            if isinstance(error, BuildError)
            else expected_arguments
        )

        if ns.identifier_type == "int":
            return build_path_for_integer_param(ns, operation, actual_arguments)  # type: ignore
        else:
            # we are missing some URI path parameters
            uri_templates = create_uri_templates(actual_arguments)
            return unquote(ns.url_for(operation, _external=False, **uri_templates))
Пример #2
0
def test_operation_naming_relation():
    """
    Complext (subject+object) endpoint naming works.

    """
    ns = Namespace(subject="foo", object_="bar")
    endpoint = ns.endpoint_for(Operation.SearchFor)
    assert_that(endpoint, is_(equal_to("foo.search_for.bar.v1")))
Пример #3
0
def test_endpoint_for():
    """
    Simple (subject-only) endpoint naming works.

    """
    ns = Namespace(subject="foo")
    endpoint = ns.endpoint_for(Operation.Search)
    assert_that(endpoint, is_(equal_to("foo.search.v1")))
def test_operation_naming_relation():
    """
    Complext (subject+object) endpoint naming works.

    """
    ns = Namespace(subject="foo", object_="bar")
    endpoint = ns.endpoint_for(Operation.SearchFor)
    assert_that(endpoint, is_(equal_to("foo.search_for.bar.v1")))
def test_endpoint_for():
    """
    Simple (subject-only) endpoint naming works.

    """
    ns = Namespace(subject="foo")
    endpoint = ns.endpoint_for(Operation.Search)
    assert_that(endpoint, is_(equal_to("foo.search.v1")))