Skip to content

Commit d02f0af

Browse files
OrisdaddyJacksonTian
authored andcommitted
Add test case
1 parent d9918e1 commit d02f0af

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

aliyun-python-sdk-core/aliyunsdkcore/utils/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ def validate_pattern(prop, prop_name, pattern):
2929
match_obj = re.search(pattern, prop, re.M | re.I)
3030
if not match_obj:
3131
raise ClientException(error_code.SDK_INVALID_PARAMETER,
32-
prop_name + ' is not match')
32+
'The parameter %s not match with %s' % (prop_name, pattern))

aliyun-python-sdk-core/tests/test_client.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# coding=utf-8
22

3-
from tests import unittest
3+
from tests import unittest, MyServer
44

5+
from aliyunsdkcore.request import RpcRequest
56
from aliyunsdkcore.acs_exception.exceptions import ClientException
67
from aliyunsdkcore.client import AcsClient
78

89

910
class TestAcsClient(unittest.TestCase):
1011

12+
@staticmethod
13+
def do_request(client, request):
14+
with MyServer() as s:
15+
client.do_action_with_exception(request)
16+
return s.content
17+
1118
def test_acs_client(self):
1219
with self.assertRaises(ClientException) as ex:
1320
AcsClient()
@@ -50,3 +57,26 @@ def test_parse_error_info_from_response_body(self):
5057
'invalid json')
5158
self.assertEqual(code, "SDK.UnknownServerError")
5259
self.assertEqual(body, "ServerResponseBody: invalid json")
60+
61+
def test_resolve_endpoint(self):
62+
client = AcsClient("id", "aks", region_id='', port=51352)
63+
req = RpcRequest(
64+
'sts',
65+
'2020',
66+
'test'
67+
)
68+
req.endpoint = 'localhost'
69+
req.request_network = ''
70+
req.product_suffix = ''
71+
self.do_request(client, req)
72+
73+
try:
74+
client._resolve_endpoint(req)
75+
except Exception as e:
76+
self.assertEqual("No such region ''. Please check your region ID.", e.message)
77+
78+
client.set_region_id('cn@hangzhou')
79+
try:
80+
client._resolve_endpoint(req)
81+
except Exception as e:
82+
self.assertEqual('The parameter region_id not match with ^[a-zA-Z0-9_-]+$', e.message)

0 commit comments

Comments
 (0)