Skip to content

Commit d24f0a1

Browse files
committed
Added more unit tests.
1 parent a4539ba commit d24f0a1

File tree

1 file changed

+87
-2
lines changed

1 file changed

+87
-2
lines changed

tests/unitary/default_setup/model_deployment/test_oci_datascience_model_deployment.py

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,33 @@ def setup_method(self):
8989
def test_activate(self):
9090
with patch.object(OCIDataScienceModelDeployment, "from_id") as mock_from_id:
9191
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+
92119
response["lifecycle_state"] = "INACTIVE"
93120
mock_from_id.return_value = OCIDataScienceModelDeployment(
94121
**response
@@ -159,8 +186,37 @@ def test_activate_with_waiting(self):
159186

160187
def test_deactivate(self):
161188
with patch.object(OCIDataScienceModelDeployment, "from_id") as mock_from_id:
189+
response = copy.deepcopy(OCI_MODEL_DEPLOYMENT_PAYLOAD)
190+
response["lifecycle_state"] = "INACTIVE"
162191
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
164220
)
165221
with patch.object(
166222
oci.data_science.DataScienceClient,
@@ -372,8 +428,37 @@ def test_update_with_waiting(self):
372428

373429
def test_delete(self):
374430
with patch.object(OCIDataScienceModelDeployment, "from_id") as mock_from_id:
431+
response = copy.deepcopy(OCI_MODEL_DEPLOYMENT_PAYLOAD)
432+
response["lifecycle_state"] = "DELETED"
375433
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
377462
)
378463
with patch.object(
379464
oci.data_science.DataScienceClient,

0 commit comments

Comments
 (0)