Exemplo n.º 1
0
def test_snippet_context_subcontext():
    ctx = CodeSnippetContext()
    ctx.add("foo", "dummy")
    sub = ctx.subcontext("foo")
    sub.add("bar", "dummy")
    ctx.add("baz", "dummy")
    assert "foo" in ctx
    assert "bar" in ctx
    assert ctx.top_level_snippets() == {"foo", "baz"}
    assert ctx.natural_order() == ["baz", "bar", "foo"]
Exemplo n.º 2
0
def test_api_gen():
    foo_type_tree = get_type_tree(Foo)
    ctx = CodeSnippetContext()
    func_code = build_ts_func("getFoo", foo_type_tree, None,
                              "/api/foo/<my_id>", ["my_id"], "GET", ctx)
    expected_func_code = """
export const getFoo = async (myId: string): Promise<Foo> => {
  const response = await fetch(`/api/foo/${myId}`, {
    method: 'GET'
  });
  if (!response.ok) {
    throw new ApiError("HTTP status code: " + response.status, response);
  }
  return await response.json();
}"""
    assert func_code == expected_func_code
    assert ctx.natural_order() == ["ApiError", "Foo"]
Exemplo n.º 3
0
def test_snippet_context_single_snippet():
    ctx = CodeSnippetContext()
    ctx.add("foo", "dummy")
    assert "foo" in ctx
    assert ctx.top_level_snippets() == {"foo"}
    assert ctx.natural_order() == ["foo"]