예제 #1
0
def test_it_updates_session(sdk: mtds.Looker31SDK):
    """update_session() should allow us to change the current workspace."""
    # Switch workspace to dev mode
    sdk.update_session(ml.WriteApiSession(workspace_id="dev"))
    current_session = sdk.session()

    assert isinstance(current_session, ml.ApiSession)
    assert current_session.workspace_id == "dev"

    # Switch workspace back to production
    current_session = sdk.update_session(ml.WriteApiSession(workspace_id="production"))

    assert isinstance(current_session, ml.ApiSession)
    assert current_session.workspace_id == "production"
예제 #2
0
    expected: MutableMapping[str, str],
):
    actual = api._convert_query_params(test_query_params)
    assert actual == expected


@pytest.mark.parametrize(
    "test_body, expected",
    [
        ("some body text", b"some body text"),
        ("", b""),
        ([1, 2, 3], b"[1, 2, 3]"),
        (["a", "b", "c"], b'["a", "b", "c"]'),
        ({"foo": "bar"}, b'{"foo": "bar"}'),
        (None, None),
        (models.WriteApiSession(workspace_id="dev"), b'{"workspace_id": "dev"}'),
        (
            [
                models.WriteApiSession(workspace_id="dev"),
                models.WriteApiSession(workspace_id="dev"),
            ],
            b'[{"workspace_id": "dev"}, {"workspace_id": "dev"}]',
        ),
    ],
)
def test_get_serialized(
    api: api_methods.APIMethods, test_body: api_methods.TBody, expected: Optional[bytes]
):
    actual = api._get_serialized(test_body)
    assert actual == expected
예제 #3
0
    actual = api._convert_query_params(test_query_params)
    assert actual == expected


@pytest.mark.parametrize(
    "test_body, expected",
    [
        ("some body text", b"some body text"),
        ("", b""),
        ([1, 2, 3], b"[1, 2, 3]"),
        (["a", "b", "c"], b'["a", "b", "c"]'),
        ({
            "foo": "bar"
        }, b'{"foo": "bar"}'),
        (None, None),
        (models.WriteApiSession(workspace_id="dev"),
         b'{"workspace_id": "dev"}'),
        (
            [
                models.WriteApiSession(workspace_id="dev"),
                models.WriteApiSession(workspace_id="dev"),
            ],
            b'[{"workspace_id": "dev"}, {"workspace_id": "dev"}]',
        ),
    ],
)
def test_get_serialized(api: api_methods.APIMethods,
                        test_body: api_methods.TBody,
                        expected: Optional[bytes]):
    actual = api._get_serialized(test_body)
    assert actual == expected