From 70155a755f6392eb7e429c4b46c23372c8529c39 Mon Sep 17 00:00:00 2001 From: weeping Date: Thu, 11 Jun 2026 15:24:42 +0800 Subject: [PATCH] feat: migrate from alibabacloud-tea to darabonba-core - Closes #80 --- alibabacloud_credentials/__init__.py | 2 +- alibabacloud_credentials/client.py | 2 +- alibabacloud_credentials/credentials.py | 6 +- alibabacloud_credentials/models.py | 6 +- .../provider/cloud_sso.py | 6 +- .../provider/ecs_ram_role.py | 14 ++--- alibabacloud_credentials/provider/oauth.py | 10 +-- alibabacloud_credentials/provider/oidc.py | 6 +- .../provider/ram_role_arn.py | 6 +- .../provider/rsa_key_pair.py | 6 +- alibabacloud_credentials/provider/uri.py | 6 +- alibabacloud_credentials/providers.py | 26 ++++---- .../utils/parameter_helper.py | 4 +- setup.py | 2 +- tests/provider/test_cloud_sso.py | 20 +++--- tests/provider/test_ecs_ram_role.py | 56 ++++++++--------- tests/provider/test_oauth.py | 58 +++++++++--------- tests/provider/test_oidc.py | 26 ++++---- tests/provider/test_profile.py | 4 +- tests/provider/test_ram_role_arn.py | 26 ++++---- tests/provider/test_rsa_key_pair.py | 26 ++++---- tests/provider/test_uri.py | 44 ++++++------- tests/test_client.py | 61 ++++++++++++++++++- tests/test_credentials.py | 34 +++++------ tests/test_providers.py | 2 +- 25 files changed, 259 insertions(+), 200 deletions(-) diff --git a/alibabacloud_credentials/__init__.py b/alibabacloud_credentials/__init__.py index 8fb97a4..eee00e3 100644 --- a/alibabacloud_credentials/__init__.py +++ b/alibabacloud_credentials/__init__.py @@ -1 +1 @@ -__version__ = "1.0.9" +__version__ = "1.1.0" diff --git a/alibabacloud_credentials/client.py b/alibabacloud_credentials/client.py index 1fc228c..1ab8513 100644 --- a/alibabacloud_credentials/client.py +++ b/alibabacloud_credentials/client.py @@ -14,7 +14,7 @@ URLCredentialsProvider, DefaultCredentialsProvider) from alibabacloud_credentials.utils import auth_constant as ac -from Tea.decorators import deprecated +from darabonba.decorators import deprecated def attribute_error_return_none(f): diff --git a/alibabacloud_credentials/credentials.py b/alibabacloud_credentials/credentials.py index 543f533..ec0a342 100644 --- a/alibabacloud_credentials/credentials.py +++ b/alibabacloud_credentials/credentials.py @@ -3,7 +3,7 @@ import time from urllib.parse import urlparse, parse_qs -from Tea.core import TeaCore +from darabonba.core import DaraCore from alibabacloud_credentials.utils import auth_constant as ac from alibabacloud_credentials.utils import parameter_helper as ph @@ -362,7 +362,7 @@ def _get_new_credential(self): for key, values in parse_qs(r.query).items(): for value in values: tea_request.query[key] = value - response = TeaCore.do_action(tea_request) + response = DaraCore.do_action(tea_request) if response.status_code != 200: raise CredentialException( "Get credentials from " + self.credentials_uri + " failed, HttpCode=" + str(response.status_code)) @@ -395,7 +395,7 @@ async def _get_new_credential_async(self): tea_request.method = 'GET' tea_request.pathname = r.path tea_request.query = parse_qs(r.query) - response = await TeaCore.async_do_action(tea_request) + response = await DaraCore.async_do_action(tea_request) if response.status_code != 200: raise CredentialException( "Get credentials from " + self.credentials_uri + " failed, HttpCode=" + str(response.status_code)) diff --git a/alibabacloud_credentials/models.py b/alibabacloud_credentials/models.py index cc0f849..093648c 100644 --- a/alibabacloud_credentials/models.py +++ b/alibabacloud_credentials/models.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- # This file is auto-generated, don't edit it. Thanks. -from Tea.model import TeaModel +from darabonba.model import DaraModel -class Config(TeaModel): +class Config(DaraModel): """ Model for initializing credential """ @@ -230,7 +230,7 @@ def from_map(self, m: dict = None): return self -class CredentialModel(TeaModel): +class CredentialModel(DaraModel): def __init__( self, access_key_id: str = None, diff --git a/alibabacloud_credentials/provider/cloud_sso.py b/alibabacloud_credentials/provider/cloud_sso.py index 77ff6f0..e9f3dea 100644 --- a/alibabacloud_credentials/provider/cloud_sso.py +++ b/alibabacloud_credentials/provider/cloud_sso.py @@ -5,7 +5,7 @@ from alibabacloud_credentials.provider.refreshable import Credentials, RefreshResult, RefreshCachedSupplier from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaCore +from darabonba.core import DaraCore from alibabacloud_credentials_api import ICredentialsProvider from alibabacloud_credentials.utils import parameter_helper as ph from alibabacloud_credentials.exceptions import CredentialException @@ -78,7 +78,7 @@ def _refresh_credentials(self) -> RefreshResult[Credentials]: tea_request.headers['Content-Type'] = 'application/json' tea_request.headers['Authorization'] = f'Bearer {self._access_token}' - response = TeaCore.do_action(tea_request, self._runtime_options) + response = DaraCore.do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( @@ -126,7 +126,7 @@ async def _refresh_credentials_async(self) -> RefreshResult[Credentials]: tea_request.headers['Content-Type'] = 'application/json' tea_request.headers['Authorization'] = f'Bearer {self._access_token}' - response = await TeaCore.async_do_action(tea_request, self._runtime_options) + response = await DaraCore.async_do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( diff --git a/alibabacloud_credentials/provider/ecs_ram_role.py b/alibabacloud_credentials/provider/ecs_ram_role.py index 6c9d625..0c3ba3d 100644 --- a/alibabacloud_credentials/provider/ecs_ram_role.py +++ b/alibabacloud_credentials/provider/ecs_ram_role.py @@ -7,7 +7,7 @@ from alibabacloud_credentials.provider.refreshable import Credentials, RefreshResult, StaleValueBehavior, \ RefreshCachedSupplier, NonBlocking from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaCore +from darabonba.core import DaraCore from apscheduler.schedulers.background import BackgroundScheduler from alibabacloud_credentials_api import ICredentialsProvider from alibabacloud_credentials.utils import auth_util as au @@ -90,7 +90,7 @@ def _get_role_name(self, url: str = None) -> str: tea_request.headers['X-aliyun-ecs-metadata-token'] = metadata_token if not url: tea_request.pathname = self.__url_in_ecs_metadata - response = TeaCore.do_action(tea_request, self._runtime_options) + response = DaraCore.do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException(self.__ecs_metadata_fetch_error_msg + ' HttpCode=' + str(response.status_code)) return response.body.decode('utf-8') @@ -103,7 +103,7 @@ async def _get_role_name_async(self, url: str = None) -> str: tea_request.headers['X-aliyun-ecs-metadata-token'] = metadata_token if not url: tea_request.pathname = self.__url_in_ecs_metadata - response = await TeaCore.async_do_action(tea_request, self._runtime_options) + response = await DaraCore.async_do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException(self.__ecs_metadata_fetch_error_msg + ' HttpCode=' + str(response.status_code)) return response.body.decode('utf-8') @@ -117,7 +117,7 @@ def _get_metadata_token(self, url: str = None) -> str: if not url: tea_request.pathname = self.__url_in_ecs_metadata_token try: - response = TeaCore.do_action(tea_request, self._runtime_options) + response = DaraCore.do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( self.__ecs_metadata_token_fetch_error_msg + ' HttpCode=' + str(response.status_code)) @@ -136,7 +136,7 @@ async def _get_metadata_token_async(self, url: str = None) -> str: if not url: tea_request.pathname = self.__url_in_ecs_metadata_token try: - response = await TeaCore.async_do_action(tea_request, self._runtime_options) + response = await DaraCore.async_do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( self.__ecs_metadata_token_fetch_error_msg + ' HttpCode=' + str(response.status_code)) @@ -158,7 +158,7 @@ def _refresh_credentials(self, url: str = None) -> RefreshResult[Credentials]: if not url: tea_request.pathname = self.__url_in_ecs_metadata + role_name # request - response = TeaCore.do_action(tea_request, self._runtime_options) + response = DaraCore.do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException(self.__ecs_metadata_fetch_error_msg + ' HttpCode=' + str(response.status_code)) @@ -202,7 +202,7 @@ async def _refresh_credentials_async(self, url: str = None) -> RefreshResult[Cre tea_request.pathname = self.__url_in_ecs_metadata + role_name # request - response = await TeaCore.async_do_action(tea_request, self._runtime_options) + response = await DaraCore.async_do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException(self.__ecs_metadata_fetch_error_msg + ' HttpCode=' + str(response.status_code)) diff --git a/alibabacloud_credentials/provider/oauth.py b/alibabacloud_credentials/provider/oauth.py index 550eff6..f85a2f0 100644 --- a/alibabacloud_credentials/provider/oauth.py +++ b/alibabacloud_credentials/provider/oauth.py @@ -7,7 +7,7 @@ from alibabacloud_credentials.provider.refreshable import Credentials, RefreshResult, RefreshCachedSupplier from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaCore +from darabonba.core import DaraCore from alibabacloud_credentials_api import ICredentialsProvider from alibabacloud_credentials.utils import parameter_helper as ph from alibabacloud_credentials.exceptions import CredentialException @@ -94,7 +94,7 @@ def _try_refresh_oauth_token(self) -> None: tea_request.body = urlencode(body_data) tea_request.headers['Content-Type'] = 'application/x-www-form-urlencoded' - response = TeaCore.do_action(tea_request, self._runtime_options) + response = DaraCore.do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException(f"failed to refresh OAuth token, status code: {response.status_code}, response: {response.body.decode('utf-8')}") @@ -135,7 +135,7 @@ async def _try_refresh_oauth_token_async(self) -> None: tea_request.body = urlencode(body_data) tea_request.headers['Content-Type'] = 'application/x-www-form-urlencoded' - response = await TeaCore.async_do_action(tea_request, self._runtime_options) + response = await DaraCore.async_do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException(f"failed to refresh OAuth token, status code: {response.status_code}, response: {response.body.decode('utf-8')}") @@ -172,7 +172,7 @@ def _refresh_credentials(self) -> RefreshResult[Credentials]: tea_request.headers['Content-Type'] = 'application/json' tea_request.headers['Authorization'] = f'Bearer {self._access_token}' - response = TeaCore.do_action(tea_request, self._runtime_options) + response = DaraCore.do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( @@ -234,7 +234,7 @@ async def _refresh_credentials_async(self) -> RefreshResult[Credentials]: tea_request.headers['Content-Type'] = 'application/json' tea_request.headers['Authorization'] = f'Bearer {self._access_token}' - response = await TeaCore.async_do_action(tea_request, self._runtime_options) + response = await DaraCore.async_do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( diff --git a/alibabacloud_credentials/provider/oidc.py b/alibabacloud_credentials/provider/oidc.py index 3c92555..f72919c 100644 --- a/alibabacloud_credentials/provider/oidc.py +++ b/alibabacloud_credentials/provider/oidc.py @@ -5,7 +5,7 @@ from alibabacloud_credentials.provider.refreshable import Credentials, RefreshResult, RefreshCachedSupplier from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaCore +from darabonba.core import DaraCore from alibabacloud_credentials_api import ICredentialsProvider from alibabacloud_credentials.utils import auth_util as au from alibabacloud_credentials.utils import parameter_helper as ph @@ -121,7 +121,7 @@ def _refresh_credentials(self) -> RefreshResult[Credentials]: tea_request.protocol = 'https' tea_request.headers['host'] = self._sts_endpoint - response = TeaCore.do_action(tea_request, self._runtime_options) + response = DaraCore.do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( @@ -172,7 +172,7 @@ async def _refresh_credentials_async(self) -> RefreshResult[Credentials]: tea_request.protocol = 'https' tea_request.headers['host'] = self._sts_endpoint - response = await TeaCore.async_do_action(tea_request, self._runtime_options) + response = await DaraCore.async_do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( diff --git a/alibabacloud_credentials/provider/ram_role_arn.py b/alibabacloud_credentials/provider/ram_role_arn.py index 29eb346..1491430 100644 --- a/alibabacloud_credentials/provider/ram_role_arn.py +++ b/alibabacloud_credentials/provider/ram_role_arn.py @@ -5,7 +5,7 @@ from alibabacloud_credentials.provider.refreshable import Credentials, RefreshResult, RefreshCachedSupplier from alibabacloud_credentials.provider import StaticAKCredentialsProvider, StaticSTSCredentialsProvider from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaCore +from darabonba.core import DaraCore from alibabacloud_credentials_api import ICredentialsProvider from alibabacloud_credentials.utils import auth_util as au from alibabacloud_credentials.utils import parameter_helper as ph @@ -134,7 +134,7 @@ def _refresh_credentials(self) -> RefreshResult[Credentials]: tea_request.protocol = 'https' tea_request.headers['host'] = self._sts_endpoint - response = TeaCore.do_action(tea_request, self._runtime_options) + response = DaraCore.do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( @@ -200,7 +200,7 @@ async def _refresh_credentials_async(self) -> RefreshResult[Credentials]: tea_request.protocol = 'https' tea_request.headers['host'] = self._sts_endpoint - response = await TeaCore.async_do_action(tea_request, self._runtime_options) + response = await DaraCore.async_do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( diff --git a/alibabacloud_credentials/provider/rsa_key_pair.py b/alibabacloud_credentials/provider/rsa_key_pair.py index be40c2f..8a28d62 100644 --- a/alibabacloud_credentials/provider/rsa_key_pair.py +++ b/alibabacloud_credentials/provider/rsa_key_pair.py @@ -4,7 +4,7 @@ from alibabacloud_credentials.provider.refreshable import Credentials, RefreshResult, RefreshCachedSupplier from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaCore +from darabonba.core import DaraCore from alibabacloud_credentials_api import ICredentialsProvider from alibabacloud_credentials.utils import auth_util as au from alibabacloud_credentials.utils import parameter_helper as ph @@ -104,7 +104,7 @@ def _refresh_credentials(self) -> RefreshResult[Credentials]: tea_request.protocol = 'https' tea_request.headers['host'] = self._sts_endpoint - response = TeaCore.do_action(tea_request, self._runtime_options) + response = DaraCore.do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( @@ -153,7 +153,7 @@ async def _refresh_credentials_async(self) -> RefreshResult[Credentials]: tea_request.protocol = 'https' tea_request.headers['host'] = self._sts_endpoint - response = await TeaCore.async_do_action(tea_request, self._runtime_options) + response = await DaraCore.async_do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( diff --git a/alibabacloud_credentials/provider/uri.py b/alibabacloud_credentials/provider/uri.py index 819f9f1..88fd1e2 100644 --- a/alibabacloud_credentials/provider/uri.py +++ b/alibabacloud_credentials/provider/uri.py @@ -5,7 +5,7 @@ from alibabacloud_credentials.provider.refreshable import Credentials, RefreshResult, RefreshCachedSupplier from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaCore +from darabonba.core import DaraCore from alibabacloud_credentials_api import ICredentialsProvider from alibabacloud_credentials.utils import auth_util as au from alibabacloud_credentials.utils import parameter_helper as ph @@ -61,7 +61,7 @@ def _refresh_credentials(self) -> RefreshResult[Credentials]: for value in values: tea_request.query[key] = value - response = TeaCore.do_action(tea_request, self._runtime_options) + response = DaraCore.do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( @@ -102,7 +102,7 @@ async def _refresh_credentials_async(self) -> RefreshResult[Credentials]: for value in values: tea_request.query[key] = value - response = await TeaCore.async_do_action(tea_request, self._runtime_options) + response = await DaraCore.async_do_action(tea_request, self._runtime_options) if response.status_code != 200: raise CredentialException( diff --git a/alibabacloud_credentials/providers.py b/alibabacloud_credentials/providers.py index 9bfa16e..34ca217 100644 --- a/alibabacloud_credentials/providers.py +++ b/alibabacloud_credentials/providers.py @@ -5,7 +5,7 @@ import time import requests -from Tea.core import TeaCore +from darabonba.core import DaraCore from alibabacloud_credentials import credentials from alibabacloud_credentials.exceptions import CredentialException @@ -126,7 +126,7 @@ def _get_role_name(self, url=None): tea_request.headers['X-aliyun-ecs-metadata-token'] = metadata_token if not url: tea_request.pathname = self.__url_in_ecs_metadata - response = TeaCore.do_action(tea_request) + response = DaraCore.do_action(tea_request) if response.status_code != 200: raise CredentialException(self.__ecs_metadata_fetch_error_msg + " HttpCode=" + str(response.status_code)) self.role_name = response.body.decode('utf-8') @@ -139,7 +139,7 @@ async def _get_role_name_async(self, url=None): tea_request.headers['X-aliyun-ecs-metadata-token'] = metadata_token if not url: tea_request.pathname = self.__url_in_ecs_metadata - response = await TeaCore.async_do_action(tea_request) + response = await DaraCore.async_do_action(tea_request) if response.status_code != 200: raise CredentialException(self.__ecs_metadata_fetch_error_msg + " HttpCode=" + str(response.status_code)) self.role_name = response.body.decode('utf-8') @@ -152,7 +152,7 @@ def _get_metadata_token(self, url=None): if not url: tea_request.pathname = self.__url_in_ecs_metadata_token try: - response = TeaCore.do_action(tea_request) + response = DaraCore.do_action(tea_request) if response.status_code != 200: raise CredentialException( self.__ecs_metadata_token_fetch_error_msg + " HttpCode=" + str(response.status_code)) @@ -170,7 +170,7 @@ async def _get_metadata_token_async(self, url=None): if not url: tea_request.pathname = self.__url_in_ecs_metadata_token try: - response = await TeaCore.async_do_action(tea_request) + response = await DaraCore.async_do_action(tea_request) if response.status_code != 200: raise CredentialException( self.__ecs_metadata_token_fetch_error_msg + " HttpCode=" + str(response.status_code)) @@ -189,7 +189,7 @@ def _create_credential(self, url=None): if not url: tea_request.pathname = self.__url_in_ecs_metadata + self.role_name # request - response = TeaCore.do_action(tea_request) + response = DaraCore.do_action(tea_request) if response.status_code != 200: raise CredentialException(self.__ecs_metadata_fetch_error_msg + " HttpCode=" + str(response.status_code)) @@ -226,7 +226,7 @@ async def _create_credential_async(self, url=None): tea_request.pathname = self.__url_in_ecs_metadata + self.role_name # request - response = await TeaCore.async_do_action(tea_request) + response = await DaraCore.async_do_action(tea_request) if response.status_code != 200: raise CredentialException(self.__ecs_metadata_fetch_error_msg + " HttpCode=" + str(response.status_code)) @@ -303,7 +303,7 @@ def _create_credentials(self): tea_request.protocol = 'https' tea_request.headers['host'] = self.sts_endpoint # request - response = TeaCore.do_action(tea_request) + response = DaraCore.do_action(tea_request) if response.status_code == 200: dic = json.loads(response.body.decode('utf-8')) if "Credentials" in dic: @@ -343,7 +343,7 @@ async def _create_credentials_async(self): tea_request.protocol = 'https' tea_request.headers['host'] = self.sts_endpoint # request - response = await TeaCore.async_do_action(tea_request) + response = await DaraCore.async_do_action(tea_request) if response.status_code == 200: dic = json.loads(response.body.decode('utf-8')) if "Credentials" in dic: @@ -413,7 +413,7 @@ def _create_credentials(self): tea_request.protocol = 'https' tea_request.headers['host'] = self.sts_endpoint # request - response = TeaCore.do_action(tea_request) + response = DaraCore.do_action(tea_request) if response.status_code == 200: dic = json.loads(response.body.decode('utf-8')) if "Credentials" in dic: @@ -450,7 +450,7 @@ async def _create_credentials_async(self): tea_request.protocol = 'https' tea_request.headers['host'] = self.sts_endpoint # request - response = await TeaCore.async_do_action(tea_request) + response = await DaraCore.async_do_action(tea_request) if response.status_code == 200: dic = json.loads(response.body.decode('utf-8')) if "Credentials" in dic: @@ -496,7 +496,7 @@ async def _create_credential_async(self, turl=None): tea_request.protocol = 'https' tea_request.headers['host'] = turl if turl else 'sts.aliyuncs.com' # request - response = await TeaCore.async_do_action(tea_request) + response = await DaraCore.async_do_action(tea_request) if response.status_code == 200: dic = json.loads(response.body.decode('utf-8')) if "SessionAccessKey" in dic: @@ -531,7 +531,7 @@ def _create_credential(self, turl=None): tea_request.protocol = 'https' tea_request.headers['host'] = turl if turl else 'sts.aliyuncs.com' # request - response = TeaCore.do_action(tea_request) + response = DaraCore.do_action(tea_request) if response.status_code == 200: dic = json.loads(response.body.decode('utf-8')) if "SessionAccessKey" in dic: diff --git a/alibabacloud_credentials/utils/parameter_helper.py b/alibabacloud_credentials/utils/parameter_helper.py index 4aa5f50..7f5b566 100644 --- a/alibabacloud_credentials/utils/parameter_helper.py +++ b/alibabacloud_credentials/utils/parameter_helper.py @@ -9,7 +9,7 @@ import platform import alibabacloud_credentials -from Tea.request import TeaRequest +from darabonba.request import DaraRequest TIME_ZONE = "UTC" FORMAT_ISO_8601 = "yyyy-MM-dd'T'HH:mm:ss'Z'" @@ -20,7 +20,7 @@ def get_new_request(): - request = TeaRequest() + request = DaraRequest() request.headers['user-agent'] = f'AlibabaCloud ({platform.system()}; {platform.machine()}) ' \ f'Python/{platform.python_version()} ' \ f'Credentials/{alibabacloud_credentials.__version__} ' \ diff --git a/setup.py b/setup.py index d6ec6d0..20d5d37 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ LONG_DESCRIPTION = fp.read() install_requires = [ - 'alibabacloud-tea>=0.4.0', + 'darabonba-core>=1.0.0', 'alibabacloud_credentials_api>=1.0.0, <2.0.0' ] diff --git a/tests/provider/test_cloud_sso.py b/tests/provider/test_cloud_sso.py index a2bf9a2..16eebe1 100644 --- a/tests/provider/test_cloud_sso.py +++ b/tests/provider/test_cloud_sso.py @@ -163,7 +163,7 @@ def test_init_default_http_options(self): self.assertEqual(provider._runtime_options['connectTimeout'], CloudSSOCredentialsProvider.DEFAULT_CONNECT_TIMEOUT) self.assertEqual(provider._runtime_options['readTimeout'], CloudSSOCredentialsProvider.DEFAULT_READ_TIMEOUT) - @patch('alibabacloud_credentials.provider.cloud_sso.TeaCore.do_action') + @patch('alibabacloud_credentials.provider.cloud_sso.DaraCore.do_action') def test_get_credentials_success(self, mock_do_action): """ Test case 9: Valid input, successfully retrieves credentials @@ -199,7 +199,7 @@ def test_get_credentials_success(self, mock_do_action): self.assertEqual(request_body['AccountId'], self.account_id) self.assertEqual(request_body['AccessConfigurationId'], self.access_config) - @patch('alibabacloud_credentials.provider.cloud_sso.TeaCore.async_do_action') + @patch('alibabacloud_credentials.provider.cloud_sso.DaraCore.async_do_action') def test_get_credentials_async_success(self, mock_async_do_action): """ Test case 10: Valid input, successfully retrieves credentials asynchronously @@ -226,7 +226,7 @@ async def run_test(): self.assertEqual(credentials.get_security_token(), self.security_token) self.assertEqual(credentials.get_provider_name(), "cloud_sso") - @patch('alibabacloud_credentials.provider.cloud_sso.TeaCore.do_action') + @patch('alibabacloud_credentials.provider.cloud_sso.DaraCore.do_action') def test_get_credentials_http_error(self, mock_do_action): """ Test case 11: HTTP error response raises CredentialException @@ -249,7 +249,7 @@ def test_get_credentials_http_error(self, mock_do_action): self.assertIn("error refreshing credentials from sso, http_code: 400", str(context.exception)) - @patch('alibabacloud_credentials.provider.cloud_sso.TeaCore.do_action') + @patch('alibabacloud_credentials.provider.cloud_sso.DaraCore.do_action') def test_get_credentials_missing_cloud_credential(self, mock_do_action): """ Test case 12: Missing CloudCredential in response raises CredentialException @@ -272,7 +272,7 @@ def test_get_credentials_missing_cloud_credential(self, mock_do_action): self.assertIn("error retrieving credentials from sso result", str(context.exception)) - @patch('alibabacloud_credentials.provider.cloud_sso.TeaCore.do_action') + @patch('alibabacloud_credentials.provider.cloud_sso.DaraCore.do_action') def test_get_credentials_missing_required_fields(self, mock_do_action): """ Test case 13: Missing required fields in CloudCredential raises CredentialException @@ -300,7 +300,7 @@ def test_get_credentials_missing_required_fields(self, mock_do_action): self.assertIn("error retrieving credentials from sso result", str(context.exception)) - @patch('alibabacloud_credentials.provider.cloud_sso.TeaCore.do_action') + @patch('alibabacloud_credentials.provider.cloud_sso.DaraCore.do_action') def test_get_credentials_invalid_json(self, mock_do_action): """ Test case 14: Invalid JSON response raises JSONDecodeError @@ -358,7 +358,7 @@ def test_get_stale_time_negative_expiration(self): expected_stale_time = 1672531199 + 60 * 60 # current time + 1 hour self.assertEqual(stale_time, expected_stale_time) - @patch('alibabacloud_credentials.provider.cloud_sso.TeaCore.do_action') + @patch('alibabacloud_credentials.provider.cloud_sso.DaraCore.do_action') def test_credentials_caching(self, mock_do_action): """ Test case 18: Credentials are cached and not refreshed on subsequent calls @@ -384,10 +384,10 @@ def test_credentials_caching(self, mock_do_action): self.assertEqual(credentials1.get_access_key_secret(), credentials2.get_access_key_secret()) self.assertEqual(credentials1.get_security_token(), credentials2.get_security_token()) - # But TeaCore.do_action should only be called once due to caching + # But DaraCore.do_action should only be called once due to caching self.assertEqual(mock_do_action.call_count, 1) - @patch('alibabacloud_credentials.provider.cloud_sso.TeaCore.do_action') + @patch('alibabacloud_credentials.provider.cloud_sso.DaraCore.do_action') def test_url_parsing(self, mock_do_action): """ Test case 19: URL parsing works correctly for different URL formats @@ -427,7 +427,7 @@ def test_url_parsing(self, mock_do_action): else: self.assertEqual(tea_request.protocol, "http") - @patch('alibabacloud_credentials.provider.cloud_sso.TeaCore.do_action') + @patch('alibabacloud_credentials.provider.cloud_sso.DaraCore.do_action') def test_expiration_time_parsing(self, mock_do_action): """ Test case 20: Expiration time is correctly parsed from ISO format diff --git a/tests/provider/test_ecs_ram_role.py b/tests/provider/test_ecs_ram_role.py index a267254..dd9a6d7 100644 --- a/tests/provider/test_ecs_ram_role.py +++ b/tests/provider/test_ecs_ram_role.py @@ -10,7 +10,7 @@ CredentialException ) from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaResponse +from darabonba.core import DaraResponse class TestEcsRamRoleCredentialsProvider(unittest.TestCase): @@ -33,7 +33,7 @@ def setUp(self): "SecurityToken": self.security_token, "Expiration": self.expiration }) - self.response = TeaResponse() + self.response = DaraResponse() self.response.status_code = 200 self.response.body = self.response_body.encode('utf-8') @@ -93,7 +93,7 @@ def test_get_credentials_valid_input(self): with patch( 'alibabacloud_credentials.provider.ecs_ram_role.EcsRamRoleCredentialsProvider._get_metadata_token', return_value=self.metadata_token): - with patch('Tea.core.TeaCore.do_action', return_value=self.response): + with patch('darabonba.core.DaraCore.do_action', return_value=self.response): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, disable_imds_v1=self.disable_imds_v1, @@ -118,7 +118,7 @@ def test_get_credentials_http_request_error(self): """ Test case 6: HTTP request error raises CredentialException """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' @@ -127,7 +127,7 @@ def test_get_credentials_http_request_error(self): with patch( 'alibabacloud_credentials.provider.ecs_ram_role.EcsRamRoleCredentialsProvider._get_metadata_token', return_value=self.metadata_token): - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, disable_imds_v1=self.disable_imds_v1, @@ -149,7 +149,7 @@ def test_get_credentials_response_format_error(self): "Code": "Failure", "Message": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') @@ -158,7 +158,7 @@ def test_get_credentials_response_format_error(self): with patch( 'alibabacloud_credentials.provider.ecs_ram_role.EcsRamRoleCredentialsProvider._get_metadata_token', return_value=self.metadata_token): - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, disable_imds_v1=self.disable_imds_v1, @@ -180,7 +180,7 @@ def test_get_credentials_async_valid_input(self): with patch( 'alibabacloud_credentials.provider.ecs_ram_role.EcsRamRoleCredentialsProvider._get_metadata_token_async', AsyncMock(return_value=self.metadata_token)): - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=self.response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=self.response)): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, disable_imds_v1=self.disable_imds_v1, @@ -213,7 +213,7 @@ def test_get_credentials_async_http_request_error(self): """ Test case 9: HTTP request error raises CredentialException asynchronously """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' @@ -222,7 +222,7 @@ def test_get_credentials_async_http_request_error(self): with patch( 'alibabacloud_credentials.provider.ecs_ram_role.EcsRamRoleCredentialsProvider._get_metadata_token_async', AsyncMock(return_value=self.metadata_token)): - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, disable_imds_v1=self.disable_imds_v1, @@ -248,7 +248,7 @@ def test_get_credentials_async_response_format_error(self): "Code": "Failure", "Message": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') @@ -257,7 +257,7 @@ def test_get_credentials_async_response_format_error(self): with patch( 'alibabacloud_credentials.provider.ecs_ram_role.EcsRamRoleCredentialsProvider._get_metadata_token_async', AsyncMock(return_value=self.metadata_token)): - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, disable_imds_v1=self.disable_imds_v1, @@ -279,12 +279,12 @@ def test_get_metadata_token_valid_input(self): Test case 11: Valid input, successfully retrieves metadata token """ response_body = self.metadata_token - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') with patch('alibabacloud_credentials.provider.ecs_ram_role.au.environment_imds_v1_disabled', 'true'): - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, http_options=self.http_options @@ -298,12 +298,12 @@ def test_get_metadata_token_http_request_error(self): """ Test case 12: HTTP request error raises CredentialException """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' with patch('alibabacloud_credentials.provider.ecs_ram_role.au.environment_imds_v1_disabled', 'true'): - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, http_options=self.http_options @@ -321,12 +321,12 @@ def test_get_metadata_token_async_valid_input(self): Test case 13: Valid input, successfully retrieves metadata token asynchronously """ response_body = self.metadata_token - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') with patch('alibabacloud_credentials.provider.ecs_ram_role.au.environment_imds_v1_disabled', 'true'): - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, http_options=self.http_options @@ -344,12 +344,12 @@ def test_get_metadata_token_async_http_request_error(self): """ Test case 14: HTTP request error raises CredentialException asynchronously """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' with patch('alibabacloud_credentials.provider.ecs_ram_role.au.environment_imds_v1_disabled', 'true'): - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, http_options=self.http_options @@ -371,12 +371,12 @@ def test_get_role_name_valid_input(self): Test case 15: Valid input, successfully retrieves role name """ response_body = self.role_name - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') with patch('alibabacloud_credentials.provider.ecs_ram_role.au.environment_ecs_metadata_disabled', 'false'): - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, disable_imds_v1=self.disable_imds_v1, @@ -391,12 +391,12 @@ def test_get_role_name_http_request_error(self): """ Test case 16: HTTP request error raises CredentialException """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' with patch('alibabacloud_credentials.provider.ecs_ram_role.au.environment_ecs_metadata_disabled', 'false'): - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, disable_imds_v1=self.disable_imds_v1, @@ -415,12 +415,12 @@ def test_get_role_name_async_valid_input(self): Test case 17: Valid input, successfully retrieves role name asynchronously """ response_body = self.role_name - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') with patch('alibabacloud_credentials.provider.ecs_ram_role.au.environment_ecs_metadata_disabled', 'false'): - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, disable_imds_v1=self.disable_imds_v1, @@ -439,12 +439,12 @@ def test_get_role_name_async_http_request_error(self): """ Test case 18: HTTP request error raises CredentialException asynchronously """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' with patch('alibabacloud_credentials.provider.ecs_ram_role.au.environment_ecs_metadata_disabled', 'false'): - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = EcsRamRoleCredentialsProvider( role_name=self.role_name, disable_imds_v1=self.disable_imds_v1, diff --git a/tests/provider/test_oauth.py b/tests/provider/test_oauth.py index 58f7efd..e59fb84 100644 --- a/tests/provider/test_oauth.py +++ b/tests/provider/test_oauth.py @@ -143,7 +143,7 @@ def test_init_default_http_options(self): self.assertEqual(provider._runtime_options['connectTimeout'], OAuthCredentialsProvider.DEFAULT_CONNECT_TIMEOUT) self.assertEqual(provider._runtime_options['readTimeout'], OAuthCredentialsProvider.DEFAULT_READ_TIMEOUT) - @patch('alibabacloud_credentials.provider.oauth.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_get_credentials_success(self, mock_do_action): """ Test case 9: Valid input, successfully retrieves credentials @@ -175,7 +175,7 @@ def test_get_credentials_success(self, mock_do_action): self.assertEqual(tea_request.headers['Authorization'], f'Bearer {self.access_token}') self.assertEqual(tea_request.headers['Content-Type'], 'application/json') - @patch('alibabacloud_credentials.provider.oauth.TeaCore.async_do_action') + @patch('darabonba.core.DaraCore.async_do_action') def test_get_credentials_async_success(self, mock_async_do_action): """ Test case 10: Valid input, successfully retrieves credentials asynchronously @@ -202,7 +202,7 @@ async def run_test(): self.assertEqual(credentials.get_security_token(), self.security_token) self.assertEqual(credentials.get_provider_name(), "oauth") - @patch('alibabacloud_credentials.provider.oauth.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_get_credentials_http_error(self, mock_do_action): """ Test case 11: HTTP error response raises CredentialException @@ -225,7 +225,7 @@ def test_get_credentials_http_error(self, mock_do_action): self.assertIn("error refreshing credentials from OAuth, http_code: 400", str(context.exception)) - @patch('alibabacloud_credentials.provider.oauth.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_get_credentials_error_in_response(self, mock_do_action): """ Test case 12: Error field in response raises CredentialException @@ -248,7 +248,7 @@ def test_get_credentials_error_in_response(self, mock_do_action): self.assertIn("error retrieving credentials from OAuth result", str(context.exception)) - @patch('alibabacloud_credentials.provider.oauth.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_get_credentials_missing_required_fields(self, mock_do_action): """ Test case 13: Missing required fields in response raises CredentialException @@ -274,7 +274,7 @@ def test_get_credentials_missing_required_fields(self, mock_do_action): self.assertIn("error retrieving credentials from OAuth result", str(context.exception)) - @patch('alibabacloud_credentials.provider.oauth.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_get_credentials_invalid_json(self, mock_do_action): """ Test case 14: Invalid JSON response raises JSONDecodeError @@ -332,7 +332,7 @@ def test_get_stale_time_negative_expiration(self): expected_stale_time = 1672531199 + 60 * 60 # current time + 1 hour self.assertEqual(stale_time, expected_stale_time) - @patch('alibabacloud_credentials.provider.oauth.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_credentials_caching(self, mock_do_action): """ Test case 18: Credentials are cached and not refreshed on subsequent calls @@ -361,7 +361,7 @@ def test_credentials_caching(self, mock_do_action): # But TeaCore.do_action should only be called once due to caching self.assertEqual(mock_do_action.call_count, 1) - @patch('alibabacloud_credentials.provider.oauth.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_url_parsing_cn(self, mock_do_action): """ Test case 19: URL parsing works correctly for CN site type @@ -386,7 +386,7 @@ def test_url_parsing_cn(self, mock_do_action): self.assertEqual(tea_request.protocol, "https") self.assertEqual(tea_request.headers['host'], "oauth.aliyun.com") - @patch('alibabacloud_credentials.provider.oauth.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_url_parsing_intl(self, mock_do_action): """ Test case 20: URL parsing works correctly for INTL site type @@ -411,7 +411,7 @@ def test_url_parsing_intl(self, mock_do_action): self.assertEqual(tea_request.protocol, "https") self.assertEqual(tea_request.headers['host'], "oauth.alibabacloud.com") - @patch('alibabacloud_credentials.provider.oauth.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_expiration_time_parsing(self, mock_do_action): """ Test case 21: Expiration time is correctly parsed from ISO format @@ -458,7 +458,7 @@ def test_client_id_and_sign_in_url(self): self.assertEqual(provider_intl._client_id, "456") self.assertEqual(provider_intl._sign_in_url, "https://oauth.alibabacloud.com") - @patch('alibabacloud_credentials.provider.oauth.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_request_body_empty(self, mock_do_action): """ Test case 23: Request body should be empty for OAuth exchange @@ -481,7 +481,7 @@ def test_request_body_empty(self, mock_do_action): self.assertIsNone(tea_request.body) - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_token_refresh_success(self, mock_do_action): """测试 OAuth 令牌刷新成功""" # 模拟成功的令牌刷新响应 @@ -519,7 +519,7 @@ def test_callback(refresh_token, access_token, access_key, secret, security_toke # 验证回调被调用 self.assertTrue(callback_called) - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_callback_in_credentials_refresh(self, mock_do_action): """测试在凭据刷新时调用回调函数""" # 模拟成功的凭据交换响应 @@ -564,7 +564,7 @@ def test_callback(refresh_token, access_token, access_key, secret, security_toke self.assertEqual(callback_data[3], "test_access_key_secret") # secret self.assertEqual(callback_data[4], "test_security_token") # security_token - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_callback_error_handling(self, mock_do_action): """测试回调函数错误处理""" # 模拟成功的凭据交换响应 @@ -621,7 +621,7 @@ def test_oauth_provider_with_empty_refresh_token(self): self.assertEqual(provider._access_token, "test_access_token") self.assertEqual(provider._refresh_token, "") - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_token_refresh_failure(self, mock_do_action): """测试OAuth令牌刷新失败""" # 模拟失败的令牌刷新响应 @@ -647,7 +647,7 @@ def test_oauth_token_refresh_failure(self, mock_do_action): self.assertEqual(provider._refresh_token, "invalid_refresh_token") - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_token_refresh_network_error(self, mock_do_action): """测试OAuth令牌刷新时网络错误""" # 模拟网络错误 @@ -700,7 +700,7 @@ def test_oauth_provider_runtime_options_with_proxy(self): self.assertEqual(provider._runtime_options['httpsProxy'], "http://proxy.example.com:8080") - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_credentials_refresh_with_callback(self, mock_do_action): """测试OAuth凭据刷新时调用回调""" # 模拟成功的凭据交换响应 @@ -745,7 +745,7 @@ def test_callback(refresh_token, access_token, access_key, secret, security_toke self.assertEqual(callback_data[3], "test_access_key_secret") # secret self.assertEqual(callback_data[4], "test_security_token") # security_token - @patch('Tea.core.TeaCore.async_do_action') + @patch('darabonba.core.DaraCore.async_do_action') def test_oauth_credentials_refresh_async_with_callback(self, mock_async_do_action): """测试OAuth异步凭据刷新时调用回调""" # 模拟成功的凭据交换响应 @@ -884,7 +884,7 @@ async def test_async_callback(refresh_token, access_token, access_key, secret, s self.assertEqual(provider._client_id, "123") self.assertEqual(provider._sign_in_url, "https://oauth.aliyun.com") - @patch('Tea.core.TeaCore.async_do_action') + @patch('darabonba.core.DaraCore.async_do_action') def test_oauth_async_token_refresh_success(self, mock_async_do_action): """测试异步OAuth令牌刷新成功""" # 模拟成功的令牌刷新响应 @@ -916,7 +916,7 @@ async def run_test(): self.assertEqual(new_access_token, "new_access_token") self.assertEqual(new_refresh_token, "new_refresh_token") - @patch('Tea.core.TeaCore.async_do_action') + @patch('darabonba.core.DaraCore.async_do_action') def test_oauth_async_token_refresh_failure(self, mock_async_do_action): """测试异步OAuth令牌刷新失败""" # 模拟失败的令牌刷新响应 @@ -946,7 +946,7 @@ async def run_test(): self.assertEqual(provider._access_token, "old_access_token") self.assertEqual(provider._refresh_token, "invalid_refresh_token") - @patch('Tea.core.TeaCore.async_do_action') + @patch('darabonba.core.DaraCore.async_do_action') def test_oauth_async_credentials_refresh_with_async_callback(self, mock_async_do_action): """测试异步凭据刷新时调用异步回调函数""" # 模拟成功的凭据交换响应 @@ -992,7 +992,7 @@ async def run_test(): self.assertEqual(callback_data[3], "test_access_key_secret") # secret self.assertEqual(callback_data[4], "test_security_token") # security_token - @patch('Tea.core.TeaCore.async_do_action') + @patch('darabonba.core.DaraCore.async_do_action') def test_oauth_async_credentials_refresh_with_async_callback_error(self, mock_async_do_action): """测试异步回调函数错误处理""" # 模拟成功的凭据交换响应 @@ -1028,7 +1028,7 @@ async def run_test(): self.assertIsNotNone(credentials) self.assertEqual(credentials.get_access_key_id(), "test_access_key_id") - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_token_refresh_timing_sufficient_time(self, mock_do_action): """测试当 OAuth token 剩余时间 > 1200秒时,不触发刷新""" # 模拟成功的凭据交换响应 @@ -1068,7 +1068,7 @@ def test_oauth_token_refresh_timing_sufficient_time(self, mock_do_action): # 验证 token 没有被刷新 self.assertEqual(provider._access_token, "valid_access_token") - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_token_refresh_timing_insufficient_time(self, mock_do_action): """测试当 OAuth token 剩余时间 <= 1200秒时,触发刷新""" # 模拟两次响应:1. token 刷新,2. 凭据交换 @@ -1125,7 +1125,7 @@ def test_oauth_token_refresh_timing_insufficient_time(self, mock_do_action): self.assertEqual(provider._access_token, "new_access_token") self.assertEqual(provider._refresh_token, "new_refresh_token") - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_token_refresh_timing_exactly_threshold(self, mock_do_action): """测试当 OAuth token 剩余时间正好等于 1200秒时,触发刷新""" # 模拟两次响应:1. token 刷新,2. 凭据交换 @@ -1170,7 +1170,7 @@ def test_oauth_token_refresh_timing_exactly_threshold(self, mock_do_action): # 验证 token 被刷新 self.assertEqual(provider._access_token, "new_access_token") - @patch('Tea.core.TeaCore.async_do_action') + @patch('darabonba.core.DaraCore.async_do_action') def test_oauth_token_refresh_timing_async_sufficient_time(self, mock_async_do_action): """测试异步场景:当 OAuth token 剩余时间 > 1200秒时,不触发刷新""" # 模拟成功的凭据交换响应 @@ -1213,7 +1213,7 @@ async def run_test(): # 验证 token 没有被刷新 self.assertEqual(provider._access_token, "valid_access_token") - @patch('Tea.core.TeaCore.async_do_action') + @patch('darabonba.core.DaraCore.async_do_action') def test_oauth_token_refresh_timing_async_insufficient_time(self, mock_async_do_action): """测试异步场景:当 OAuth token 剩余时间 <= 1200秒时,触发刷新""" # 模拟两次响应:1. token 刷新,2. 凭据交换 @@ -1273,7 +1273,7 @@ async def run_test(): self.assertEqual(provider._access_token, "new_access_token") self.assertEqual(provider._refresh_token, "new_refresh_token") - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_token_refresh_timing_edge_case_zero_expire(self, mock_do_action): """测试边界情况:access_token_expire 为 0 时触发刷新""" # 模拟两次响应:1. token 刷新,2. 凭据交换 @@ -1317,7 +1317,7 @@ def test_oauth_token_refresh_timing_edge_case_zero_expire(self, mock_do_action): # 验证 token 被刷新 self.assertEqual(provider._access_token, "new_access_token") - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_oauth_token_refresh_timing_edge_case_none_token(self, mock_do_action): """测试边界情况:access_token 为 None 时触发刷新""" # 模拟两次响应:1. token 刷新,2. 凭据交换 diff --git a/tests/provider/test_oidc.py b/tests/provider/test_oidc.py index ed1af75..ee81bcd 100644 --- a/tests/provider/test_oidc.py +++ b/tests/provider/test_oidc.py @@ -9,7 +9,7 @@ CredentialException ) from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaResponse +from darabonba.core import DaraResponse class TestOIDCRoleArnCredentialsProvider(unittest.TestCase): @@ -225,12 +225,12 @@ def test_get_credentials_valid_input(self): "Expiration": "2023-12-31T23:59:59Z" } }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') with patch('alibabacloud_credentials.provider.oidc._get_token', return_value=token): - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = OIDCRoleArnCredentialsProvider( role_arn=self.role_arn, oidc_provider_arn=self.oidc_provider_arn, @@ -282,12 +282,12 @@ def test_get_credentials_http_request_error(self): Test case 13: HTTP request error raises CredentialException """ token = "test_token" - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' with patch('alibabacloud_credentials.provider.oidc._get_token', return_value=token): - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = OIDCRoleArnCredentialsProvider( role_arn=self.role_arn, oidc_provider_arn=self.oidc_provider_arn, @@ -315,12 +315,12 @@ def test_get_credentials_response_format_error(self): response_body = json.dumps({ "Error": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') with patch('alibabacloud_credentials.provider.oidc._get_token', return_value=token): - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = OIDCRoleArnCredentialsProvider( role_arn=self.role_arn, oidc_provider_arn=self.oidc_provider_arn, @@ -352,12 +352,12 @@ def test_get_credentials_async_valid_input(self): "Expiration": "2023-12-31T23:59:59Z" } }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') with patch('alibabacloud_credentials.provider.oidc._get_token_async', AsyncMock(return_value=token)): - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = OIDCRoleArnCredentialsProvider( role_arn=self.role_arn, oidc_provider_arn=self.oidc_provider_arn, @@ -421,12 +421,12 @@ def test_get_credentials_async_http_request_error(self): Test case 17: HTTP request error raises CredentialException asynchronously """ token = "test_token" - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' with patch('alibabacloud_credentials.provider.oidc._get_token_async', AsyncMock(return_value=token)): - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = OIDCRoleArnCredentialsProvider( role_arn=self.role_arn, oidc_provider_arn=self.oidc_provider_arn, @@ -458,12 +458,12 @@ def test_get_credentials_async_response_format_error(self): response_body = json.dumps({ "Error": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') with patch('alibabacloud_credentials.provider.oidc._get_token_async', AsyncMock(return_value=token)): - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = OIDCRoleArnCredentialsProvider( role_arn=self.role_arn, oidc_provider_arn=self.oidc_provider_arn, diff --git a/tests/provider/test_profile.py b/tests/provider/test_profile.py index 2a96cdb..951f80a 100644 --- a/tests/provider/test_profile.py +++ b/tests/provider/test_profile.py @@ -107,7 +107,7 @@ def test_get_credentials_valid_oidc_role_arn(self): self.assertIn("error refreshing credentials from oidc_role_arn", str(context.exception)) - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_get_credentials_valid_ecs_ram_role(self, mock_do_action): """ Test case 5: Valid input, successfully retrieves credentials for ecs_ram_role type @@ -304,7 +304,7 @@ def test_get_credentials_missing_oidc_token_file_path(self, mock_auth_util): 'oidc_token_file_path or environment variable ALIBABA_CLOUD_OIDC_TOKEN_FILE cannot be empty', str(context.exception)) - @patch('Tea.core.TeaCore.do_action') + @patch('darabonba.core.DaraCore.do_action') def test_get_credentials_missing_role_name(self, mock_do_action): """ Test case 15: Missing role_name raises CredentialException diff --git a/tests/provider/test_ram_role_arn.py b/tests/provider/test_ram_role_arn.py index 417df5f..32a5f4a 100644 --- a/tests/provider/test_ram_role_arn.py +++ b/tests/provider/test_ram_role_arn.py @@ -9,7 +9,7 @@ CredentialException ) from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaResponse +from darabonba.core import DaraResponse class TestRamRoleArnCredentialsProvider(unittest.TestCase): @@ -178,11 +178,11 @@ def test_get_credentials_valid_input(self): "Expiration": "2023-12-31T23:59:59Z" } }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = RamRoleArnCredentialsProvider( access_key_id=self.access_key_id, access_key_secret=self.access_key_secret, @@ -215,11 +215,11 @@ def test_get_credentials_http_request_error(self): """ Test case 8: HTTP request error raises CredentialException """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = RamRoleArnCredentialsProvider( access_key_id=self.access_key_id, access_key_secret=self.access_key_secret, @@ -248,11 +248,11 @@ def test_get_credentials_response_format_error(self): response_body = json.dumps({ "Error": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = RamRoleArnCredentialsProvider( access_key_id=self.access_key_id, access_key_secret=self.access_key_secret, @@ -286,11 +286,11 @@ def test_get_credentials_async_valid_input(self): "Expiration": "2023-12-31T23:59:59Z" } }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = RamRoleArnCredentialsProvider( access_key_id=self.access_key_id, access_key_secret=self.access_key_secret, @@ -332,11 +332,11 @@ def test_get_credentials_async_http_request_error(self): """ Test case 11: HTTP request error raises CredentialException asynchronously """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = RamRoleArnCredentialsProvider( access_key_id=self.access_key_id, access_key_secret=self.access_key_secret, @@ -369,11 +369,11 @@ def test_get_credentials_async_response_format_error(self): response_body = json.dumps({ "Error": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = RamRoleArnCredentialsProvider( access_key_id=self.access_key_id, access_key_secret=self.access_key_secret, diff --git a/tests/provider/test_rsa_key_pair.py b/tests/provider/test_rsa_key_pair.py index 35410e6..917d20c 100644 --- a/tests/provider/test_rsa_key_pair.py +++ b/tests/provider/test_rsa_key_pair.py @@ -9,7 +9,7 @@ CredentialException ) from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaResponse +from darabonba.core import DaraResponse class TestRsaKeyPairCredentialsProvider(unittest.TestCase): @@ -160,11 +160,11 @@ def test_get_credentials_valid_input(self): "Expiration": "2023-12-31T23:59:59Z" } }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): with patch('alibabacloud_credentials.provider.rsa_key_pair._get_content', return_value=self.private_key_content): provider = RsaKeyPairCredentialsProvider( @@ -188,11 +188,11 @@ def test_get_credentials_http_request_error(self): """ Test case 10: HTTP request error raises CredentialException """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): with patch('alibabacloud_credentials.provider.rsa_key_pair._get_content', return_value=self.private_key_content): provider = RsaKeyPairCredentialsProvider( @@ -218,11 +218,11 @@ def test_get_credentials_response_format_error(self): response_body = json.dumps({ "Error": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): with patch('alibabacloud_credentials.provider.rsa_key_pair._get_content', return_value=self.private_key_content): provider = RsaKeyPairCredentialsProvider( @@ -252,11 +252,11 @@ def test_get_credentials_async_valid_input(self): "Expiration": "2023-12-31T23:59:59Z" } }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): with patch('alibabacloud_credentials.provider.rsa_key_pair._get_content', return_value=self.private_key_content): provider = RsaKeyPairCredentialsProvider( @@ -286,11 +286,11 @@ def test_get_credentials_async_http_request_error(self): """ Test case 13: HTTP request error raises CredentialException asynchronously """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): with patch('alibabacloud_credentials.provider.rsa_key_pair._get_content', return_value=self.private_key_content): provider = RsaKeyPairCredentialsProvider( @@ -320,11 +320,11 @@ def test_get_credentials_async_response_format_error(self): response_body = json.dumps({ "Error": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): with patch('alibabacloud_credentials.provider.rsa_key_pair._get_content', return_value=self.private_key_content): provider = RsaKeyPairCredentialsProvider( diff --git a/tests/provider/test_uri.py b/tests/provider/test_uri.py index d4051b8..e4b3fa9 100644 --- a/tests/provider/test_uri.py +++ b/tests/provider/test_uri.py @@ -9,7 +9,7 @@ CredentialException ) from alibabacloud_credentials.http import HttpOptions -from Tea.core import TeaResponse +from darabonba.core import DaraResponse class TestURLCredentialsProvider(unittest.TestCase): @@ -29,7 +29,7 @@ def setUp(self): "SecurityToken": self.security_token, "Expiration": self.expiration }) - self.response = TeaResponse() + self.response = DaraResponse() self.response.status_code = 200 self.response.body = self.response_body.encode('utf-8') @@ -94,7 +94,7 @@ def test_get_credentials_valid_input(self): """ Test case 5: Valid input, successfully retrieves credentials """ - with patch('Tea.core.TeaCore.do_action', return_value=self.response): + with patch('darabonba.core.DaraCore.do_action', return_value=self.response): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, @@ -114,11 +114,11 @@ def test_get_credentials_http_request_error(self): """ Test case 6: HTTP request error raises CredentialException """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, @@ -140,11 +140,11 @@ def test_get_credentials_response_format_error(self): "Code": "Failure", "Message": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, @@ -161,7 +161,7 @@ def test_get_credentials_async_valid_input(self): """ Test case 8: Valid input, successfully retrieves credentials asynchronously """ - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=self.response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=self.response)): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, @@ -185,11 +185,11 @@ def test_get_credentials_async_http_request_error(self): """ Test case 9: HTTP request error raises CredentialException asynchronously """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, @@ -215,11 +215,11 @@ def test_get_credentials_async_response_format_error(self): "Code": "Failure", "Message": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, @@ -246,11 +246,11 @@ def test_get_credentials_missing_access_key_id(self): "SecurityToken": self.security_token, "Expiration": self.expiration }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, @@ -273,11 +273,11 @@ def test_get_credentials_missing_access_key_secret(self): "SecurityToken": self.security_token, "Expiration": self.expiration }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, @@ -300,11 +300,11 @@ def test_get_credentials_missing_security_token(self): "AccessKeySecret": self.access_key_secret, "Expiration": self.expiration }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, @@ -327,11 +327,11 @@ def test_get_credentials_missing_expiration(self): "AccessKeySecret": self.access_key_secret, "SecurityToken": self.security_token }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, @@ -355,11 +355,11 @@ def test_get_credentials_invalid_code(self): "SecurityToken": self.security_token, "Expiration": self.expiration }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): provider = URLCredentialsProvider( uri=self.uri, protocol=self.protocol, diff --git a/tests/test_client.py b/tests/test_client.py index e5b382f..d121c2c 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,10 +1,11 @@ import asyncio import unittest +import warnings from . import txt_file from alibabacloud_credentials.models import Config from alibabacloud_credentials.utils import auth_constant -from alibabacloud_credentials.client import Client, _CredentialsProviderWrap +from alibabacloud_credentials.client import Client, _CredentialsProviderWrap, deprecated from alibabacloud_credentials import credentials from alibabacloud_credentials.utils import auth_util @@ -117,3 +118,61 @@ async def get_credential_async(): credential = asyncio.run(get_credential_async()) self.assertEqual('ak1', credential.access_key_id) + + def test_deprecated_decorator_no_tea_dependency(self): + """Verify that the deprecated decorator does not depend on Tea.decorators. + When a user installs the 'tea' package from PyPI, it shadows alibabacloud-tea's + Tea.decorators namespace and causes ImportError. Our local implementation avoids this. + """ + import importlib + import sys + + # Simulate the conflict: when PyPI 'tea' package is installed, + # Tea.decorators exists but has no 'deprecated' attribute + original_module = sys.modules.get('Tea.decorators') + fake_module = type(sys)('Tea.decorators') # empty module, no 'deprecated' + sys.modules['Tea.decorators'] = fake_module + try: + # Our client module should still work because it uses a local implementation + module = importlib.reload(importlib.import_module('alibabacloud_credentials.client')) + self.assertTrue(callable(module.deprecated)) + finally: + if original_module is not None: + sys.modules['Tea.decorators'] = original_module + else: + sys.modules.pop('Tea.decorators', None) + + def test_deprecated_decorator_emits_warning(self): + """Verify that the local deprecated decorator emits DeprecationWarning with correct message.""" + + @deprecated("Use new_func instead") + def old_func(): + return 42 + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + result = old_func() + + self.assertEqual(42, result) + self.assertEqual(1, len(caught)) + self.assertTrue(issubclass(caught[0].category, DeprecationWarning)) + self.assertIn("old_func", str(caught[0].message)) + self.assertIn("Use new_func instead", str(caught[0].message)) + + def test_deprecated_methods_emit_warning(self): + """Verify that deprecated Client methods still work and emit DeprecationWarning.""" + conf = Config() + conf.type = auth_constant.ACCESS_KEY + conf.access_key_id = 'test_ak' + conf.access_key_secret = 'test_sk' + client = Client(conf) + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + ak = client.get_access_key_id() + sk = client.get_access_key_secret() + + self.assertEqual('test_ak', ak) + self.assertEqual('test_sk', sk) + deprecation_warnings = [w for w in caught if issubclass(w.category, DeprecationWarning)] + self.assertEqual(2, len(deprecation_warnings)) diff --git a/tests/test_credentials.py b/tests/test_credentials.py index 79ea874..89b4b6d 100644 --- a/tests/test_credentials.py +++ b/tests/test_credentials.py @@ -4,7 +4,7 @@ import asyncio from alibabacloud_credentials import credentials, providers from alibabacloud_credentials.exceptions import CredentialException -from Tea.core import TeaResponse +from darabonba.core import DaraResponse class TestCredentials(unittest.TestCase): @@ -260,11 +260,11 @@ def test_CredentialsURICredential_normal(self): "SecurityToken": "test_security_token", "Expiration": "2023-12-31T23:59:59Z" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): credentials_uri = 'http://localhost:6666/test' cred = credentials.CredentialsURICredential(credentials_uri) @@ -285,11 +285,11 @@ def test_CredentialsURICredential_refresh(self): "SecurityToken": "test_security_token", "Expiration": "2023-12-31T23:59:59Z" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): credentials_uri = 'http://localhost:6666/test' cred = credentials.CredentialsURICredential(credentials_uri) @@ -306,11 +306,11 @@ def test_CredentialsURICredential_http_request_error(self): """ Test case 3: HTTP request error raises CredentialException """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): credentials_uri = 'http://localhost:6666/test' cred = credentials.CredentialsURICredential(credentials_uri) @@ -329,11 +329,11 @@ def test_CredentialsURICredential_response_format_error(self): "Code": "Failure", "Message": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.do_action', return_value=response): + with patch('darabonba.core.DaraCore.do_action', return_value=response): credentials_uri = 'http://localhost:6666/test' cred = credentials.CredentialsURICredential(credentials_uri) @@ -355,11 +355,11 @@ def test_CredentialsURICredential_async_normal(self): "SecurityToken": "test_security_token", "Expiration": "2023-12-31T23:59:59Z" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): credentials_uri = 'http://localhost:6666/test' cred = credentials.CredentialsURICredential(credentials_uri) @@ -384,11 +384,11 @@ def test_CredentialsURICredential_async_refresh(self): "SecurityToken": "test_security_token", "Expiration": "2023-12-31T23:59:59Z" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): credentials_uri = 'http://localhost:6666/test' cred = credentials.CredentialsURICredential(credentials_uri) @@ -408,11 +408,11 @@ def test_CredentialsURICredential_async_http_request_error(self): """ Test case 7: HTTP request error raises CredentialException """ - response = TeaResponse() + response = DaraResponse() response.status_code = 400 response.body = b'HTTP request failed' - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): credentials_uri = 'http://localhost:6666/test' cred = credentials.CredentialsURICredential(credentials_uri) @@ -434,11 +434,11 @@ def test_CredentialsURICredential_async_response_format_error(self): "Code": "Failure", "Message": "Invalid request" }) - response = TeaResponse() + response = DaraResponse() response.status_code = 200 response.body = response_body.encode('utf-8') - with patch('Tea.core.TeaCore.async_do_action', AsyncMock(return_value=response)): + with patch('darabonba.core.DaraCore.async_do_action', AsyncMock(return_value=response)): credentials_uri = 'http://localhost:6666/test' cred = credentials.CredentialsURICredential(credentials_uri) diff --git a/tests/test_providers.py b/tests/test_providers.py index 1323ab7..2e05eb4 100644 --- a/tests/test_providers.py +++ b/tests/test_providers.py @@ -2,7 +2,7 @@ import time import asyncio -from Tea.exceptions import RetryError +from darabonba.exceptions import RetryError from alibabacloud_credentials import providers, models, credentials, exceptions from alibabacloud_credentials.exceptions import CredentialException from alibabacloud_credentials.utils import auth_util