@@ -89,6 +89,33 @@ def setup_method(self):
89
89
def test_activate (self ):
90
90
with patch .object (OCIDataScienceModelDeployment , "from_id" ) as mock_from_id :
91
91
response = copy .deepcopy (OCI_MODEL_DEPLOYMENT_PAYLOAD )
92
+ mock_from_id .return_value = OCIDataScienceModelDeployment (
93
+ ** response
94
+ )
95
+ with pytest .raises (
96
+ Exception ,
97
+ match = f"Model deployment { self .mock_model_deployment .id } is already in active state."
98
+ ):
99
+ self .mock_model_deployment .activate (
100
+ wait_for_completion = False ,
101
+ max_wait_time = 1 ,
102
+ poll_interval = 1 ,
103
+ )
104
+
105
+ response ["lifecycle_state" ] = "FAILED"
106
+ mock_from_id .return_value = OCIDataScienceModelDeployment (
107
+ ** response
108
+ )
109
+ with pytest .raises (
110
+ Exception ,
111
+ match = f"Can't activate model deployment { self .mock_model_deployment .id } when it's in FAILED state."
112
+ ):
113
+ self .mock_model_deployment .activate (
114
+ wait_for_completion = False ,
115
+ max_wait_time = 1 ,
116
+ poll_interval = 1 ,
117
+ )
118
+
92
119
response ["lifecycle_state" ] = "INACTIVE"
93
120
mock_from_id .return_value = OCIDataScienceModelDeployment (
94
121
** response
@@ -159,8 +186,37 @@ def test_activate_with_waiting(self):
159
186
160
187
def test_deactivate (self ):
161
188
with patch .object (OCIDataScienceModelDeployment , "from_id" ) as mock_from_id :
189
+ response = copy .deepcopy (OCI_MODEL_DEPLOYMENT_PAYLOAD )
190
+ response ["lifecycle_state" ] = "INACTIVE"
162
191
mock_from_id .return_value = OCIDataScienceModelDeployment (
163
- ** OCI_MODEL_DEPLOYMENT_PAYLOAD
192
+ ** response
193
+ )
194
+ with pytest .raises (
195
+ Exception ,
196
+ match = f"Model deployment { self .mock_model_deployment .id } is already in inactive state."
197
+ ):
198
+ self .mock_model_deployment .deactivate (
199
+ wait_for_completion = False ,
200
+ max_wait_time = 1 ,
201
+ poll_interval = 1 ,
202
+ )
203
+
204
+ response ["lifecycle_state" ] = "FAILED"
205
+ mock_from_id .return_value = OCIDataScienceModelDeployment (
206
+ ** response
207
+ )
208
+ with pytest .raises (
209
+ Exception ,
210
+ match = f"Can't deactivate model deployment { self .mock_model_deployment .id } when it's in FAILED state."
211
+ ):
212
+ self .mock_model_deployment .deactivate (
213
+ wait_for_completion = False ,
214
+ max_wait_time = 1 ,
215
+ poll_interval = 1 ,
216
+ )
217
+ response ["lifecycle_state" ] = "ACTIVE"
218
+ mock_from_id .return_value = OCIDataScienceModelDeployment (
219
+ ** response
164
220
)
165
221
with patch .object (
166
222
oci .data_science .DataScienceClient ,
@@ -372,8 +428,37 @@ def test_update_with_waiting(self):
372
428
373
429
def test_delete (self ):
374
430
with patch .object (OCIDataScienceModelDeployment , "from_id" ) as mock_from_id :
431
+ response = copy .deepcopy (OCI_MODEL_DEPLOYMENT_PAYLOAD )
432
+ response ["lifecycle_state" ] = "DELETED"
375
433
mock_from_id .return_value = OCIDataScienceModelDeployment (
376
- ** OCI_MODEL_DEPLOYMENT_PAYLOAD
434
+ ** response
435
+ )
436
+ with pytest .raises (
437
+ Exception ,
438
+ match = f"Model deployment { self .mock_model_deployment .id } is either deleted or being deleted."
439
+ ):
440
+ self .mock_model_deployment .delete (
441
+ wait_for_completion = False ,
442
+ max_wait_time = 1 ,
443
+ poll_interval = 1 ,
444
+ )
445
+
446
+ response ["lifecycle_state" ] = "UPDATING"
447
+ mock_from_id .return_value = OCIDataScienceModelDeployment (
448
+ ** response
449
+ )
450
+ with pytest .raises (
451
+ Exception ,
452
+ match = f"Can't delete model deployment { self .mock_model_deployment .id } when it's in UPDATING state."
453
+ ):
454
+ self .mock_model_deployment .delete (
455
+ wait_for_completion = False ,
456
+ max_wait_time = 1 ,
457
+ poll_interval = 1 ,
458
+ )
459
+ response ["lifecycle_state" ] = "ACTIVE"
460
+ mock_from_id .return_value = OCIDataScienceModelDeployment (
461
+ ** response
377
462
)
378
463
with patch .object (
379
464
oci .data_science .DataScienceClient ,
0 commit comments