Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Orisdaddy authored and JacksonTian committed Jul 28, 2020
1 parent d9918e1 commit d02f0af
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aliyun-python-sdk-core/aliyunsdkcore/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def validate_pattern(prop, prop_name, pattern):
match_obj = re.search(pattern, prop, re.M | re.I)
if not match_obj:
raise ClientException(error_code.SDK_INVALID_PARAMETER,
prop_name + ' is not match')
'The parameter %s not match with %s' % (prop_name, pattern))
32 changes: 31 additions & 1 deletion aliyun-python-sdk-core/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# coding=utf-8

from tests import unittest
from tests import unittest, MyServer

from aliyunsdkcore.request import RpcRequest
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.client import AcsClient


class TestAcsClient(unittest.TestCase):

@staticmethod
def do_request(client, request):
with MyServer() as s:
client.do_action_with_exception(request)
return s.content

def test_acs_client(self):
with self.assertRaises(ClientException) as ex:
AcsClient()
Expand Down Expand Up @@ -50,3 +57,26 @@ def test_parse_error_info_from_response_body(self):
'invalid json')
self.assertEqual(code, "SDK.UnknownServerError")
self.assertEqual(body, "ServerResponseBody: invalid json")

def test_resolve_endpoint(self):
client = AcsClient("id", "aks", region_id='', port=51352)
req = RpcRequest(
'sts',
'2020',
'test'
)
req.endpoint = 'localhost'
req.request_network = ''
req.product_suffix = ''
self.do_request(client, req)

try:
client._resolve_endpoint(req)
except Exception as e:
self.assertEqual("No such region ''. Please check your region ID.", e.message)

client.set_region_id('cn@hangzhou')
try:
client._resolve_endpoint(req)
except Exception as e:
self.assertEqual('The parameter region_id not match with ^[a-zA-Z0-9_-]+$', e.message)

0 comments on commit d02f0af

Please sign in to comment.