Beispiel #1
0
def test_it_runs_inline_query(sdk: mtds.LookerSDK, queries: TQueries):
    """run_inline_query() should run a query and return its results.
    """
    for q in queries:
        limit = cast(str, q["limit"]) or "10"
        request = create_query_request(q, limit)

        json_resp = sdk.run_inline_query("json", request)
        assert isinstance(json_resp, str)
        json_: List[Dict[str, Any]] = json.loads(json_resp)
        assert len(json_) == int(limit)

        row = json_[0]
        if q.get("fields"):
            for field in q["fields"]:
                assert field in row.keys()

        csv = sdk.run_inline_query("csv", request)
        assert isinstance(csv, str)
        assert len(re.findall(r"\n", csv)) == int(limit) + 1

    # only do 1 image download since it takes a while
    png = sdk.run_inline_query("png", request)
    assert isinstance(png, bytes)
    try:
        Image.open(io.BytesIO(png))
    except IOError:
        raise AssertionError("png format failed to return an image")
def test_it_runs_inline_query(looker_client: mtds.LookerSDK, queries: TQueries):
    """run_inline_query() should run a query and return its results.
    """
    for q in queries:
        limit = cast(str, q["limit"]) or "10"
        request = create_query_request(q, limit)

        json_resp = looker_client.run_inline_query("json", request)
        assert isinstance(json_resp, str)
        json_: List[Dict[str, Any]] = json.loads(json_resp)
        assert len(json_) == int(limit)

        row = json_[0]
        if q.get("fields"):
            for field in q["fields"]:
                assert field in row.keys()

        csv = looker_client.run_inline_query("csv", request)
        assert isinstance(csv, str)
        assert len(re.findall(r"\n", csv)) == int(limit) + 1

        looker_client.logout()