def test_cloud_list_workspaces_basic(
    language_server_initialized: IRobocorpLanguageServerClient,
    rcc_patch: RccPatch,
    data_regression,
):

    client = language_server_initialized

    rcc_patch.apply()

    result1 = client.cloud_list_workspaces()
    assert result1["success"]

    data_regression.check(result1)

    rcc_patch.disallow_calls()
    result2 = client.cloud_list_workspaces()
    assert result2["success"]
    assert result1["result"] == result2["result"]

    result3 = client.cloud_list_workspaces(refresh=True)
    assert "message" in result3

    # Didn't work out because the mock forbids it (as expected).
    assert not result3["success"]
    msg = result3["message"]
    assert msg and "This should not be called at this time" in msg
Exemplo n.º 2
0
def test_cloud_list_workspaces_cache_invalidate(
    rcc_patch: RccPatch,
    ws_root_path: str,
    rcc_location: str,
    ci_endpoint: str,
    rcc_config_location: str,
):
    from robocorp_code.robocorp_language_server import RobocorpLanguageServer
    from robocorp_ls_core.constants import NULL
    from robocorp_code.rcc import AccountInfo

    rcc_patch.apply()

    read_stream = NULL
    write_stream = NULL
    language_server = RobocorpLanguageServer(read_stream, write_stream)
    initialization_options = {"do-not-track": True}

    language_server.m_initialize(rootPath=ws_root_path,
                                 initialization_options=initialization_options)
    language_server.m_workspace__did_change_configuration({
        "robocorp": {
            "rcc": {
                "location": rcc_location,
                "endpoint": ci_endpoint,
                "config_location": rcc_config_location,
            }
        }
    })

    rcc = language_server._rcc
    rcc._last_verified_account_info = AccountInfo("default account", "123", "",
                                                  "")

    assert language_server._cloud_list_workspaces({"refresh":
                                                   False})["success"]
    rcc_patch.disallow_calls()
    assert language_server._cloud_list_workspaces({"refresh":
                                                   False})["success"]

    rcc.last_verified_account_info.account = AccountInfo(
        "another account", "123", "", "")

    # As account changed, the data should be fetched (as we can't due to the patching
    # the error is expected).
    with pytest.raises(AssertionError) as e:
        assert not language_server._cloud_list_workspaces({"refresh": False
                                                           })["success"]

    assert "This should not be called at this time (data should be cached)." in str(
        e)