Пример #1
0
def make_operation_name(path, method, resource_name):
    """Create an appropriate CLI command for an operation.

    Examples
    --------
    >>> make_operation_name('/scripts/r/{id}/runs/{run_id}', 'get', 'scripts')
    get-r-runs
    """
    path = path.lower().lstrip('/')

    # Remove resource prefix. Note that the path name for some operations is
    # just the resource name (e.g., /databases).
    if path.startswith(resource_name):
        path = path[len(resource_name):].strip("-")

    name = parse_method_name(method, path).replace("_", "-")
    return name
Пример #2
0
def test_parse_method_name():
    x = _resources.parse_method_name("get", "url.com/containers")
    y = _resources.parse_method_name("get", "url.com/containers/{id}")
    z = _resources.parse_method_name("get",
                                     "url.com/containers/{id}/runs/{run_id}")
    a = _resources.parse_method_name("post",
                                     "url.com/containers/{id}/runs/{run_id}")
    b = _resources.parse_method_name("get", "url.com/containers/{id}/{run_id}")
    c = _resources.parse_method_name(
        "get", "url.com/containers/{id}/{run_id}/shares")
    assert x == "list_containers"
    assert y == "get_containers"
    assert z == "get_containers_runs"
    assert a == "post_containers_runs"
    assert b == "get_containers_id"
    assert c == "list_containers_id_shares"