11"""Unit tests for Model with default_deployment_template functionality."""
2+
23from pathlib import Path
34from unittest .mock import Mock , patch
45
@@ -34,22 +35,20 @@ def test_model_init_with_default_deployment_template_object(self) -> None:
3435 path = "./model.pkl" ,
3536 default_deployment_template = template ,
3637 )
37-
38+
3839 assert model .default_deployment_template is not None
3940 assert model .default_deployment_template .asset_id == template .asset_id
4041
4142 def test_model_init_with_default_deployment_template_dict (self ) -> None :
4243 """Test creating a Model with default_deployment_template as dict."""
43- template_dict = {
44- "asset_id" : "azureml://registries/test-registry/deploymenttemplates/template1/versions/1"
45- }
44+ template_dict = {"asset_id" : "azureml://registries/test-registry/deploymenttemplates/template1/versions/1" }
4645 model = Model (
4746 name = "test-model" ,
4847 version = "1" ,
4948 path = "./model.pkl" ,
5049 default_deployment_template = template_dict , # type: ignore[arg-type]
5150 )
52-
51+
5352 assert model .default_deployment_template is not None
5453 assert isinstance (model .default_deployment_template , DefaultDeploymentTemplate )
5554 assert model .default_deployment_template .asset_id == template_dict ["asset_id" ]
@@ -61,7 +60,7 @@ def test_model_init_without_default_deployment_template(self) -> None:
6160 version = "1" ,
6261 path = "./model.pkl" ,
6362 )
64-
63+
6564 assert model .default_deployment_template is None
6665
6766 def test_model_to_rest_object_with_default_deployment_template (self ) -> None :
@@ -76,9 +75,9 @@ def test_model_to_rest_object_with_default_deployment_template(self) -> None:
7675 description = "Test model" ,
7776 default_deployment_template = template ,
7877 )
79-
78+
8079 rest_object = model ._to_rest_object ()
81-
80+
8281 # Should return ModelVersionData when default_deployment_template is present
8382 assert isinstance (rest_object , ModelVersionData )
8483 assert isinstance (rest_object .properties , ModelVersionDetails )
@@ -95,9 +94,9 @@ def test_model_to_rest_object_without_default_deployment_template(self) -> None:
9594 description = "Test model" ,
9695 stage = "Production" ,
9796 )
98-
97+
9998 rest_object = model ._to_rest_object ()
100-
99+
101100 # Should return ModelVersion when default_deployment_template is not present
102101 assert isinstance (rest_object , ModelVersion )
103102 assert isinstance (rest_object .properties , ModelVersionProperties )
@@ -106,7 +105,7 @@ def test_model_to_rest_object_without_default_deployment_template(self) -> None:
106105 def test_model_from_rest_object_with_default_deployment_template_dict (self ) -> None :
107106 """Test Model._from_rest_object() with default_deployment_template as dict."""
108107 template_asset_id = "azureml://registries/test-registry/deploymenttemplates/template1/versions/1"
109-
108+
110109 # Create mock REST object
111110 rest_properties = Mock (spec = ModelVersionDetails )
112111 rest_properties .description = "Test model"
@@ -120,29 +119,29 @@ def test_model_from_rest_object_with_default_deployment_template_dict(self) -> N
120119 rest_properties .intellectual_property = None
121120 rest_properties .system_metadata = None
122121 rest_properties .default_deployment_template = {"asset_id" : template_asset_id }
123-
122+
124123 rest_object = Mock (spec = ModelVersionData )
125124 rest_object .id = "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.MachineLearningServices/workspaces/ws/models/test-model/versions/1"
126125 rest_object .properties = rest_properties
127-
126+
128127 # Mock system_data
129128 mock_system_data = Mock ()
130129 mock_system_data .created_by = "test_user"
131130 mock_system_data .created_at = None
132131 mock_system_data .last_modified_by = None
133132 mock_system_data .last_modified_at = None
134133 rest_object .system_data = mock_system_data
135-
134+
136135 model = Model ._from_rest_object (rest_object )
137-
136+
138137 assert model .default_deployment_template is not None
139138 assert isinstance (model .default_deployment_template , DefaultDeploymentTemplate )
140139 assert model .default_deployment_template .asset_id == template_asset_id
141140
142141 def test_model_from_rest_object_with_default_deployment_template_object (self ) -> None :
143142 """Test Model._from_rest_object() with default_deployment_template as object."""
144143 template_asset_id = "azureml://registries/test-registry/deploymenttemplates/template1/versions/1"
145-
144+
146145 # Create mock REST object
147146 rest_properties = Mock (spec = ModelVersionDetails )
148147 rest_properties .description = "Test model"
@@ -155,26 +154,26 @@ def test_model_from_rest_object_with_default_deployment_template_object(self) ->
155154 rest_properties .job_name = None
156155 rest_properties .intellectual_property = None
157156 rest_properties .system_metadata = None
158-
157+
159158 # Create template object with asset_id attribute
160159 template_obj = Mock ()
161160 template_obj .asset_id = template_asset_id
162161 rest_properties .default_deployment_template = template_obj
163-
162+
164163 rest_object = Mock (spec = ModelVersionData )
165164 rest_object .id = "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.MachineLearningServices/workspaces/ws/models/test-model/versions/1"
166165 rest_object .properties = rest_properties
167-
166+
168167 # Mock system_data
169168 mock_system_data = Mock ()
170169 mock_system_data .created_by = "test_user"
171170 mock_system_data .created_at = None
172171 mock_system_data .last_modified_by = None
173172 mock_system_data .last_modified_at = None
174173 rest_object .system_data = mock_system_data
175-
174+
176175 model = Model ._from_rest_object (rest_object )
177-
176+
178177 assert model .default_deployment_template is not None
179178 assert isinstance (model .default_deployment_template , DefaultDeploymentTemplate )
180179 assert model .default_deployment_template .asset_id == template_asset_id
@@ -192,21 +191,21 @@ def test_model_from_rest_object_without_default_deployment_template(self) -> Non
192191 rest_properties .stage = "Production"
193192 rest_properties .job_name = None
194193 rest_properties .intellectual_property = None
195-
194+
196195 rest_object = Mock (spec = ModelVersion )
197196 rest_object .id = "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.MachineLearningServices/workspaces/ws/models/test-model/versions/1"
198197 rest_object .properties = rest_properties
199-
198+
200199 # Mock system_data
201200 mock_system_data = Mock ()
202201 mock_system_data .created_by = "test_user"
203202 mock_system_data .created_at = None
204203 mock_system_data .last_modified_by = None
205204 mock_system_data .last_modified_at = None
206205 rest_object .system_data = mock_system_data
207-
206+
208207 model = Model ._from_rest_object (rest_object )
209-
208+
210209 assert model .default_deployment_template is None
211210 assert model .stage == "Production"
212211
@@ -222,13 +221,13 @@ def test_model_with_stage_and_default_deployment_template(self) -> None:
222221 stage = "Production" ,
223222 default_deployment_template = template ,
224223 )
225-
224+
226225 assert model .stage == "Production"
227226 assert model .default_deployment_template is not None
228-
227+
229228 # Serialize to REST object
230229 rest_object = model ._to_rest_object ()
231-
230+
232231 # Note: When default_deployment_template is present, it uses ModelVersionDetails
233232 # which doesn't support stage in the v2021_10_01_dataplanepreview API
234233 # This is expected behavior - stage is only supported in workspace operations
@@ -239,7 +238,7 @@ def test_model_yaml_with_default_deployment_template(self, tmp_path: Path) -> No
239238 # Create a dummy model file
240239 model_file = tmp_path / "model.pkl"
241240 model_file .write_text ("dummy model" )
242-
241+
243242 yaml_content = f"""
244243name: test-model
245244version: "1"
@@ -250,9 +249,9 @@ def test_model_yaml_with_default_deployment_template(self, tmp_path: Path) -> No
250249"""
251250 yaml_file = tmp_path / "model_with_template.yml"
252251 yaml_file .write_text (yaml_content )
253-
252+
254253 model = load_model (source = yaml_file )
255-
254+
256255 assert model .name == "test-model"
257256 assert model .version == "1"
258257 assert model .default_deployment_template is not None
0 commit comments