Skip to content

Commit 7c17130

Browse files
add unit tests
1 parent a016e33 commit 7c17130

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

tests/unitary/with_extras/aqua/test_config.py

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2024 Oracle and/or its affiliates.
2+
# Copyright (c) 2024, 2025 Oracle and/or its affiliates.
33
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
44

55
import json
66
import os
7-
from unittest.mock import patch
7+
import pytest
8+
from unittest.mock import patch, MagicMock
9+
10+
import oci.data_science.models
811

912
from ads.aqua.common.entities import ContainerSpec
1013
from ads.aqua.config.config import get_evaluation_service_config
14+
from ads.aqua.app import AquaApp
1115

1216

1317
class TestConfig:
@@ -37,3 +41,63 @@ def test_evaluation_service_config(self, mock_get_container_config):
3741
test_result.to_dict()
3842
== expected_result[ContainerSpec.CONTAINER_SPEC]["test_container"]
3943
)
44+
45+
@pytest.mark.parametrize(
46+
"custom_metadata",
47+
[
48+
{
49+
"category": "Other",
50+
"description": "test_desc",
51+
"key": "artifact_location",
52+
"value": "artifact_location",
53+
},
54+
{},
55+
],
56+
)
57+
@pytest.mark.parametrize("verified_model", [True, False])
58+
@pytest.mark.parametrize("path_exists", [True, False])
59+
@patch("ads.aqua.app.load_config")
60+
def test_load_config(
61+
self, mock_load_config, custom_metadata, verified_model, path_exists
62+
):
63+
mock_load_config.return_value = {"config_key": "config_value"}
64+
service_model_tag = (
65+
{"aqua_service_model": "aqua_service_model_id"} if verified_model else {}
66+
)
67+
68+
self.app = AquaApp()
69+
70+
model = {
71+
"id": "mock_id",
72+
"lifecycle_details": "mock_lifecycle_details",
73+
"lifecycle_state": "mock_lifecycle_state",
74+
"project_id": "mock_project_id",
75+
"freeform_tags": {
76+
**{
77+
"OCI_AQUA": "",
78+
},
79+
**service_model_tag,
80+
},
81+
"custom_metadata_list": [
82+
oci.data_science.models.Metadata(**custom_metadata)
83+
],
84+
}
85+
86+
self.app.ds_client.get_model = MagicMock(
87+
return_value=oci.response.Response(
88+
status=200,
89+
request=MagicMock(),
90+
headers=MagicMock(),
91+
data=oci.data_science.models.Model(**model),
92+
)
93+
)
94+
with patch("ads.aqua.app.is_path_exists", return_value=path_exists):
95+
result = self.app.get_config(
96+
model_id="test_model_id", config_file_name="test_config_file_name"
97+
)
98+
if not path_exists:
99+
assert result == {}
100+
if not custom_metadata:
101+
assert result == {}
102+
if path_exists and custom_metadata:
103+
assert result == {"config_key": "config_value"}

0 commit comments

Comments
 (0)