def test_cloud_list_workspaces_errors_single_ws_not_available( language_server_initialized: IRobocorpLanguageServerClient, rcc_patch: RccPatch, data_regression, ): client = language_server_initialized def custom_handler(args, *sargs, **kwargs): if args[:4] == ["cloud", "workspace", "--workspace", "workspace_id_1"]: # List packages for workspace 1 return ActionResult( success=False, message= """{"error":{"code":"WORKSPACE_TREE_NOT_FOUND","subCode":"","message":"workspace tree not found"}""", result=None, ) rcc_patch.custom_handler = custom_handler rcc_patch.apply() result1 = client.cloud_list_workspaces() # i.e.: Should show only workspace 2 as workspace 1 errored. data_regression.check(result1) rcc_patch.custom_handler = None result2 = client.cloud_list_workspaces() assert result1["result"] == result2["result"] # Use cached result3 = client.cloud_list_workspaces(refresh=True) data_regression.check(result3, basename="test_cloud_list_workspaces_basic")
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
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)
def test_cloud_list_workspaces_sorting( language_server_initialized: IRobocorpLanguageServerClient, rcc_patch: RccPatch, tmpdir: py.path.local, ): client = language_server_initialized root_dir = str(tmpdir.join("root").mkdir()) rcc_patch.apply() result = client.cloud_list_workspaces() assert result["success"] ws_info = result["result"] assert ws_info ci_workspace_info = get_workspace_from_name(ws_info, "CI workspace") result = client.upload_to_new_robot( ci_workspace_info["workspaceId"], f"New package {time.time()}", "<dir not there>", ) assert not result["success"] msg = result["message"] assert msg and "to exist" in msg result = client.upload_to_new_robot( ci_workspace_info["workspaceId"], "New package", root_dir ) assert result["success"] result = client.cloud_list_workspaces() assert result["success"] res = result["result"] assert res assert _get_as_name_to_sort_key_and_package_id(res) == { "Package Name 1": ("00010package name 1", "452"), "Package Name 2": ("00010package name 2", "453"), "New package": ("00000new package", "2323"), } result = client.upload_to_existing_activity( ci_workspace_info["workspaceId"], "453", root_dir ) assert result["success"]
def test_cloud_list_workspaces_errors_no_ws_available( language_server_initialized: IRobocorpLanguageServerClient, rcc_patch: RccPatch ): client = language_server_initialized def custom_handler(args, *sargs, **kwargs): if args[:3] == ["cloud", "workspace", "--workspace"]: # List packages for workspace 1 return ActionResult( success=False, message="""{"error":{"code":"WORKSPACE_TREE_NOT_FOUND","subCode":"","message":"workspace tree not found"}""", result=None, ) rcc_patch.custom_handler = custom_handler rcc_patch.apply() result1 = client.cloud_list_workspaces() assert not result1["success"]