Skip to content

Commit 2a27ef6

Browse files
add comments and fix tests
1 parent 882a215 commit 2a27ef6

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

ads/aqua/extension/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ def validate_function_parameters(data_class, input_data: Dict):
2828

2929
@cached(cache=TTLCache(maxsize=1, ttl=timedelta(minutes=1), timer=datetime.now))
3030
def ui_compatability_check():
31+
"""This method caches the service compartment OCID details that is set by either the environment variable or if
32+
fetched from the configuration. The cached result is returned when multiple calls are made in quick succession
33+
from the UI to avoid multiple config file loads."""
3134
return ODSC_MODEL_COMPARTMENT_OCID or fetch_service_compartment()

tests/unitary/with_extras/aqua/test_common_handler.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import ads.config
1616
from ads.aqua.constants import AQUA_GA_LIST
1717
from ads.aqua.extension.common_handler import CompatibilityCheckHandler
18+
from ads.aqua.extension.utils import ui_compatability_check
1819

1920

2021
class TestDataset:
@@ -28,6 +29,9 @@ def setUp(self, ipython_init_mock) -> None:
2829
self.common_handler = CompatibilityCheckHandler(MagicMock(), MagicMock())
2930
self.common_handler.request = MagicMock()
3031

32+
def tearDown(self) -> None:
33+
ui_compatability_check.cache_clear()
34+
3135
def test_get_ok(self):
3236
"""Test to check if ok is returned when ODSC_MODEL_COMPARTMENT_OCID is set."""
3337
with patch.dict(
@@ -36,15 +40,22 @@ def test_get_ok(self):
3640
):
3741
reload(ads.config)
3842
reload(ads.aqua)
43+
reload(ads.aqua.extension.utils)
3944
reload(ads.aqua.extension.common_handler)
4045

4146
with patch(
4247
"ads.aqua.extension.base_handler.AquaAPIhandler.finish"
4348
) as mock_finish:
44-
mock_finish.side_effect = lambda x: x
45-
self.common_handler.request.path = "aqua/hello"
46-
result = self.common_handler.get()
47-
assert result["status"] == "ok"
49+
with patch(
50+
"ads.aqua.extension.utils.fetch_service_compartment"
51+
) as mock_fetch_service_compartment:
52+
mock_fetch_service_compartment.return_value = (
53+
TestDataset.SERVICE_COMPARTMENT_ID
54+
)
55+
mock_finish.side_effect = lambda x: x
56+
self.common_handler.request.path = "aqua/hello"
57+
result = self.common_handler.get()
58+
assert result["status"] == "ok"
4859

4960
def test_get_compatible_status(self):
5061
"""Test to check if compatible is returned when ODSC_MODEL_COMPARTMENT_OCID is not set
@@ -55,12 +66,13 @@ def test_get_compatible_status(self):
5566
):
5667
reload(ads.config)
5768
reload(ads.aqua)
69+
reload(ads.aqua.extension.utils)
5870
reload(ads.aqua.extension.common_handler)
5971
with patch(
6072
"ads.aqua.extension.base_handler.AquaAPIhandler.finish"
6173
) as mock_finish:
6274
with patch(
63-
"ads.aqua.extension.common_handler.fetch_service_compartment"
75+
"ads.aqua.extension.utils.fetch_service_compartment"
6476
) as mock_fetch_service_compartment:
6577
mock_fetch_service_compartment.return_value = None
6678
mock_finish.side_effect = lambda x: x
@@ -77,12 +89,13 @@ def test_raise_not_compatible_error(self):
7789
):
7890
reload(ads.config)
7991
reload(ads.aqua)
92+
reload(ads.aqua.extension.utils)
8093
reload(ads.aqua.extension.common_handler)
8194
with patch(
8295
"ads.aqua.extension.base_handler.AquaAPIhandler.finish"
8396
) as mock_finish:
8497
with patch(
85-
"ads.aqua.extension.common_handler.fetch_service_compartment"
98+
"ads.aqua.extension.utils.fetch_service_compartment"
8699
) as mock_fetch_service_compartment:
87100
mock_fetch_service_compartment.return_value = None
88101
mock_finish.side_effect = lambda x: x

tests/unitary/with_extras/aqua/test_handlers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from notebook.base.handlers import APIHandler, IPythonHandler
1414
from oci.exceptions import ServiceError
1515
from parameterized import parameterized
16-
from tornado.httpserver import HTTPRequest
1716
from tornado.httputil import HTTPServerRequest
1817
from tornado.web import Application, HTTPError
1918

@@ -191,6 +190,7 @@ def setUpClass(cls):
191190

192191
reload(ads.config)
193192
reload(ads.aqua)
193+
reload(ads.aqua.extension.utils)
194194
reload(ads.aqua.extension.common_handler)
195195

196196
@classmethod
@@ -200,6 +200,7 @@ def tearDownClass(cls):
200200

201201
reload(ads.config)
202202
reload(ads.aqua)
203+
reload(ads.aqua.extension.utils)
203204
reload(ads.aqua.extension.common_handler)
204205

205206
@parameterized.expand(

0 commit comments

Comments
 (0)