|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*-- |
| 3 | + |
| 4 | +# Copyright (c) 2024 Oracle and/or its affiliates. |
| 5 | +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ |
| 6 | + |
| 7 | +import os |
| 8 | +import json |
| 9 | +from importlib import reload |
| 10 | +from tornado.web import Application |
| 11 | +from tornado.testing import AsyncHTTPTestCase |
| 12 | + |
| 13 | +import ads.config |
| 14 | +import ads.aqua |
| 15 | +from ads.aqua.utils import AQUA_GA_LIST |
| 16 | +from ads.aqua.extension.common_handler import CompatibilityCheckHandler |
| 17 | + |
| 18 | + |
| 19 | +class TestDataset: |
| 20 | + SERVICE_COMPARTMENT_ID = "ocid1.compartment.oc1..<OCID>" |
| 21 | + |
| 22 | + |
| 23 | +class TestYourHandler(AsyncHTTPTestCase): |
| 24 | + def get_app(self): |
| 25 | + return Application([(r"/hello", CompatibilityCheckHandler)]) |
| 26 | + |
| 27 | + def setUp(self): |
| 28 | + super().setUp() |
| 29 | + os.environ["ODSC_MODEL_COMPARTMENT_OCID"] = TestDataset.SERVICE_COMPARTMENT_ID |
| 30 | + reload(ads.config) |
| 31 | + reload(ads.aqua) |
| 32 | + reload(ads.aqua.extension.common_handler) |
| 33 | + |
| 34 | + def tearDown(self): |
| 35 | + super().tearDown() |
| 36 | + os.environ.pop("ODSC_MODEL_COMPARTMENT_OCID", None) |
| 37 | + reload(ads.config) |
| 38 | + reload(ads.aqua) |
| 39 | + reload(ads.aqua.extension.common_handler) |
| 40 | + |
| 41 | + def test_get_ok(self): |
| 42 | + response = self.fetch("/hello", method="GET") |
| 43 | + assert json.loads(response.body)["status"] == "ok" |
| 44 | + |
| 45 | + def test_get_compatible_status(self): |
| 46 | + os.environ["ODSC_MODEL_COMPARTMENT_OCID"] = "" |
| 47 | + os.environ["CONDA_BUCKET_NS"] = AQUA_GA_LIST[0] |
| 48 | + reload(ads.common) |
| 49 | + reload(ads.aqua) |
| 50 | + reload(ads.aqua.extension.common_handler) |
| 51 | + response = self.fetch("/hello", method="GET") |
| 52 | + assert json.loads(response.body)["status"] == "compatible" |
| 53 | + |
| 54 | + def test_raise_not_compatible_error(self): |
| 55 | + os.environ["ODSC_MODEL_COMPARTMENT_OCID"] = "" |
| 56 | + os.environ["CONDA_BUCKET_NS"] = "test-namespace" |
| 57 | + reload(ads.common) |
| 58 | + reload(ads.aqua) |
| 59 | + reload(ads.aqua.extension.common_handler) |
| 60 | + response = self.fetch("/hello", method="GET") |
| 61 | + assert ( |
| 62 | + json.loads(response.body)["message"] |
| 63 | + == "Authorization Failed: The resource you're looking for isn't accessible." |
| 64 | + ) |
0 commit comments