|
1 | 1 | #!/usr/bin/env python
|
2 |
| -# Copyright (c) 2024 Oracle and/or its affiliates. |
| 2 | +# Copyright (c) 2024, 2025 Oracle and/or its affiliates. |
3 | 3 | # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
4 | 4 |
|
5 | 5 | import json
|
6 | 6 | 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 |
8 | 11 |
|
9 | 12 | from ads.aqua.common.entities import ContainerSpec
|
10 | 13 | from ads.aqua.config.config import get_evaluation_service_config
|
| 14 | +from ads.aqua.app import AquaApp |
11 | 15 |
|
12 | 16 |
|
13 | 17 | class TestConfig:
|
@@ -37,3 +41,63 @@ def test_evaluation_service_config(self, mock_get_container_config):
|
37 | 41 | test_result.to_dict()
|
38 | 42 | == expected_result[ContainerSpec.CONTAINER_SPEC]["test_container"]
|
39 | 43 | )
|
| 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