github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/python/tests/unit/sdk/test_client.py (about) 1 # 2 # Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. 3 # 4 5 import unittest 6 from unittest.mock import patch 7 8 from aistore.sdk import Client 9 from aistore.sdk.cluster import Cluster 10 from aistore.sdk.etl import Etl 11 from aistore.sdk.request_client import RequestClient 12 from aistore.sdk.types import Namespace 13 from aistore.sdk.job import Job 14 from tests.const import ETL_NAME 15 from tests.utils import test_cases 16 17 18 class TestClient(unittest.TestCase): # pylint: disable=unused-variable 19 def setUp(self) -> None: 20 self.endpoint = "https://aistore-endpoint" 21 self.client = Client(self.endpoint) 22 23 @patch("aistore.sdk.client.RequestClient") 24 def test_init_defaults(self, mock_request_client): 25 Client(self.endpoint) 26 mock_request_client.assert_called_with(self.endpoint, False, None, None) 27 28 @test_cases( 29 (True, None, None), 30 (False, "ca_cert_location", None), 31 (False, None, 30.0), 32 (False, None, (10, 30.0)), 33 ) 34 @patch("aistore.sdk.client.RequestClient") 35 def test_init(self, test_case, mock_request_client): 36 skip_verify, ca_cert, timeout = test_case 37 Client(self.endpoint, skip_verify=skip_verify, ca_cert=ca_cert, timeout=timeout) 38 mock_request_client.assert_called_with( 39 self.endpoint, skip_verify, ca_cert, timeout 40 ) 41 42 def test_bucket(self): 43 bck_name = "bucket_123" 44 provider = "bucketProvider" 45 namespace = Namespace(uuid="id", name="namespace") 46 bucket = self.client.bucket(bck_name, provider, namespace) 47 self.assertEqual(self.endpoint, bucket.client.endpoint) 48 self.assertIsInstance(bucket.client, RequestClient) 49 self.assertEqual(bck_name, bucket.name) 50 self.assertEqual(provider, bucket.provider) 51 self.assertEqual(namespace, bucket.namespace) 52 53 def test_cluster(self): 54 res = self.client.cluster() 55 self.assertEqual(self.endpoint, res.client.endpoint) 56 self.assertIsInstance(res.client, RequestClient) 57 self.assertIsInstance(res, Cluster) 58 59 def test_job(self): 60 job_id = "1234" 61 job_kind = "test kind" 62 res = self.client.job(job_id, job_kind) 63 self.assertIsInstance(res, Job) 64 self.assertEqual(job_id, res.job_id) 65 self.assertEqual(job_kind, res.job_kind) 66 67 def test_etl(self): 68 res = self.client.etl(ETL_NAME) 69 self.assertIsInstance(res, Etl) 70 self.assertEqual(ETL_NAME, res.name)