@@ -220,3 +220,56 @@ def test_choices_happy(mocker):
220220 mocker .patch ("builtins.input" , return_value = "1" )
221221 res = install ._choice ("foo" , ["a" , "b" ])
222222 assert "b" == res
223+
224+
225+ def test_step_list (mocker ):
226+ ws = mocker .Mock ()
227+ from databricks .labs .ucx .framework .tasks import Task
228+
229+ tasks = [
230+ Task (task_id = 0 , workflow = "wl_1" , name = "n3" , doc = "d3" , fn = lambda : None ),
231+ Task (task_id = 1 , workflow = "wl_2" , name = "n2" , doc = "d2" , fn = lambda : None ),
232+ Task (task_id = 2 , workflow = "wl_1" , name = "n1" , doc = "d1" , fn = lambda : None ),
233+ ]
234+
235+ with mocker .patch .object (WorkspaceInstaller , attribute = "_sorted_tasks" , return_value = tasks ):
236+ install = WorkspaceInstaller (ws )
237+ steps = install ._step_list ()
238+ assert len (steps ) == 2
239+ assert steps [0 ] == "wl_1" and steps [1 ] == "wl_2"
240+
241+
242+ def test_create_readme (mocker ):
243+ mocker .patch ("builtins.input" , return_value = "yes" )
244+ webbrowser_open = mocker .patch ("webbrowser.open" )
245+ ws = mocker .Mock ()
246+
247+ ws .
current_user .
me = lambda :
iam .
User (
user_name = "[email protected] " ,
groups = [
iam .
ComplexValue (
display = "admins" )])
248+ ws .config .host = "https://foo"
249+ config_bytes = yaml .dump (WorkspaceConfig (inventory_database = "a" , groups = GroupsConfig (auto = True )).as_dict ()).encode (
250+ "utf8"
251+ )
252+ ws .workspace .download = lambda _ : io .BytesIO (config_bytes )
253+
254+ from databricks .labs .ucx .framework .tasks import Task
255+
256+ tasks = [
257+ Task (task_id = 0 , workflow = "wl_1" , name = "n3" , doc = "d3" , fn = lambda : None ),
258+ Task (task_id = 1 , workflow = "wl_2" , name = "n2" , doc = "d2" , fn = lambda : None ),
259+ Task (task_id = 2 , workflow = "wl_1" , name = "n1" , doc = "d1" , fn = lambda : None ),
260+ ]
261+
262+ with mocker .patch .object (WorkspaceInstaller , attribute = "_sorted_tasks" , return_value = tasks ):
263+ install = WorkspaceInstaller (ws )
264+ install ._deployed_steps = {"wl_1" : 1 , "wl_2" : 2 }
265+ install ._create_readme ()
266+
267+ webbrowser_open .
assert_called_with (
"https://foo/#workspace/Users/[email protected] /.ucx/README.py" )
268+
269+ _ , args , kwargs = ws .mock_calls [0 ]
270+ assert args [
0 ]
== "/Users/[email protected] /.ucx/README.py" 271+
272+ import re
273+
274+ p = re .compile (".*wl_1.*n3.*n1.*wl_2.*n2.*" )
275+ assert p .match (str (args [1 ]))
0 commit comments