3131 "recorded_test" , "mock_workspace_arm_template_deployment_name" , "mock_workspace_dependent_resource_name_generator"
3232)
3333class TestWorkspace (AzureRecordedTestCase ):
34+
35+ # WARNING: This test takes a long time to run in live mode.
3436 @pytest .mark .skipif (
3537 condition = not is_live (),
3638 reason = "ARM template makes playback complex, so the test is flaky when run against recording" ,
3739 )
38- def test_workspace_create_update_and_delete (
39- self , client : MLClient , randstr : Callable [[], str ], location : str
40- ) -> None :
40+ def test_workspace_create_and_delete (self , client : MLClient , randstr : Callable [[], str ], location : str ) -> None :
4141 wps_name = f"e2etest_{ randstr ('wps_name' )} "
4242 wps_description = f"{ wps_name } description"
4343 wps_display_name = f"{ wps_name } display name"
@@ -77,8 +77,55 @@ def workspace_validation(wps):
7777 assert isinstance (workspace , Workspace )
7878 assert workspace .name == wps_name
7979
80- static_acr = "/subscriptions/8f338f6e-4fce-44ae-969c-fc7d8fda030e/resourceGroups/rg-mhe-e2e-test-dont-remove/providers/Microsoft.ContainerRegistry/registries/acrmhetest2"
81- static_appinsights = "/subscriptions/8f338f6e-4fce-44ae-969c-fc7d8fda030e/resourceGroups/rg-mhe-e2e-test-dont-remove/providers/microsoft.insights/components/aimhetest2"
80+ poller = client .workspaces .begin_delete (wps_name , delete_dependent_resources = True , permanently_delete = True )
81+ # verify that request was accepted by checking if poller is returned
82+ assert poller
83+ assert isinstance (poller , LROPoller )
84+
85+ # Despite the name, also tests create and delete by necessity to have an update-able workspace.
86+ # WARNING: This test takes a LONG time to run in live mode.
87+ @pytest .mark .skipif (
88+ condition = not is_live (),
89+ reason = "ARM template makes playback complex, so the test is flaky when run against recording" ,
90+ )
91+ def test_workspace_update (self , client : MLClient , randstr : Callable [[], str ], location : str ) -> None :
92+ wps_name = f"e2etest_{ randstr ('wps_name' )} "
93+ wps_description = f"{ wps_name } description"
94+ wps_display_name = f"{ wps_name } display name"
95+ params_override = [
96+ {"name" : wps_name },
97+ {"location" : location },
98+ {"description" : wps_description },
99+ {"display_name" : wps_display_name },
100+ {"enable_data_isolation" : True },
101+ ]
102+
103+ def workspace_validation (wps ):
104+ workspace_poller = client .workspaces .begin_create (workspace = wps )
105+ assert isinstance (workspace_poller , LROPoller )
106+ workspace = workspace_poller .result ()
107+ assert isinstance (workspace , Workspace )
108+ assert workspace .name == wps_name
109+ assert workspace .location == location
110+ assert workspace .description == wps_description
111+ assert workspace .display_name == wps_display_name
112+ assert workspace .public_network_access == PublicNetworkAccess .ENABLED
113+ # TODO uncomment this when enableDataIsolation flag change bug resolved for PATCH on the service side
114+ # assert workspace.enable_data_isolation == True
115+
116+ workspace = verify_entity_load_and_dump (
117+ load_workspace ,
118+ workspace_validation ,
119+ "./tests/test_configs/workspace/workspace_min.yaml" ,
120+ params_override = params_override ,
121+ )[0 ]
122+
123+ workspace_list = client .workspaces .list ()
124+ assert isinstance (workspace_list , ItemPaged )
125+ workspace = client .workspaces .get (wps_name )
126+ assert isinstance (workspace , Workspace )
127+ assert workspace .name == wps_name
128+
82129 param_image_build_compute = "compute"
83130 param_display_name = "Test display name"
84131 param_description = "Test description"
@@ -90,8 +137,6 @@ def workspace_validation(wps):
90137 description = param_description ,
91138 image_build_compute = param_image_build_compute ,
92139 public_network_access = PublicNetworkAccess .DISABLED ,
93- container_registry = static_acr ,
94- application_insights = static_appinsights ,
95140 update_dependent_resources = True ,
96141 tags = param_tags ,
97142 )
@@ -102,12 +147,68 @@ def workspace_validation(wps):
102147 assert workspace .description == param_description
103148 assert workspace .image_build_compute == param_image_build_compute
104149 assert workspace .public_network_access == PublicNetworkAccess .DISABLED
105- assert workspace .container_registry .lower () == static_acr .lower ()
106- assert workspace .application_insights .lower () == static_appinsights .lower ()
107150 assert workspace .tags == param_tags
108151 # enable_data_isolation flag can be only set at workspace creation stage, update for both put/patch is invliad
109152 # TODO uncomment this when enableDataIsolation flag change bug resolved for PATCH on the service side
110153 # assert workspace.enable_data_isolation == True
154+ poller = client .workspaces .begin_delete (wps_name , delete_dependent_resources = True , permanently_delete = True )
155+ # verify that request was accepted by checking if poller is returned
156+ assert poller
157+ assert isinstance (poller , LROPoller )
158+
159+ @pytest .mark .skipif (
160+ condition = True ,
161+ reason = "This test was refactored out from the original workspace CRUD test because not everyone has access to the "
162+ + "static resources referenced here. We need to refactor the testing of ACR and appinsights to "
163+ + "not be dependent on user access rights." ,
164+ )
165+ def test_acr_and_appinsights_in_create (self , client : MLClient , randstr : Callable [[], str ], location : str ) -> None :
166+ wps_name = f"e2etest_{ randstr ('wps_name' )} "
167+ wps_description = f"{ wps_name } description"
168+ wps_display_name = f"{ wps_name } display name"
169+ params_override = [
170+ {"name" : wps_name },
171+ {"location" : location },
172+ {"description" : wps_description },
173+ {"display_name" : wps_display_name },
174+ {"enable_data_isolation" : True },
175+ {
176+ "container_registry" : "/subscriptions/8f338f6e-4fce-44ae-969c-fc7d8fda030e/resourceGroups/rg-mhe-e2e-test-dont-remove/providers/Microsoft.ContainerRegistry/registries/acrmhetest2"
177+ },
178+ {
179+ "application_insights" : "/subscriptions/8f338f6e-4fce-44ae-969c-fc7d8fda030e/resourceGroups/rg-mhe-e2e-test-dont-remove/providers/microsoft.insights/components/aimhetest2"
180+ },
181+ ]
182+
183+ # only test simple aspects of both a pointer and path-loaded workspace
184+ # save actual service calls for a single object (below).
185+ def workspace_validation (wps ):
186+ workspace_poller = client .workspaces .begin_create (workspace = wps )
187+ assert isinstance (workspace_poller , LROPoller )
188+ workspace = workspace_poller .result ()
189+ assert isinstance (workspace , Workspace )
190+ assert workspace .name == wps_name
191+ assert workspace .location == location
192+ assert workspace .description == wps_description
193+ assert workspace .display_name == wps_display_name
194+ assert workspace .public_network_access == PublicNetworkAccess .ENABLED
195+ # TODO uncomment this when enableDataIsolation flag change bug resolved for PATCH on the service side
196+ # assert workspace.enable_data_isolation == True
197+
198+ workspace = verify_entity_load_and_dump (
199+ load_workspace ,
200+ workspace_validation ,
201+ "./tests/test_configs/workspace/workspace_min.yaml" ,
202+ params_override = params_override ,
203+ )[0 ]
204+
205+ workspace_list = client .workspaces .list ()
206+ assert isinstance (workspace_list , ItemPaged )
207+ workspace = client .workspaces .get (wps_name )
208+ assert isinstance (workspace , Workspace )
209+ assert workspace .name == wps_name
210+ assert workspace .container_registry .lower () == params_override ["container_registry" ].lower ()
211+ assert workspace .application_insights .lower () == params_override ["application_insights" ].lower ()
111212
112213 poller = client .workspaces .begin_delete (wps_name , delete_dependent_resources = True , permanently_delete = True )
113214 # verify that request was accepted by checking if poller is returned
0 commit comments