|
1 | 1 | # coding=utf-8
|
2 | 2 |
|
3 |
| -from tests import unittest |
| 3 | +from tests import unittest, MyServer |
4 | 4 |
|
| 5 | +from aliyunsdkcore.request import RpcRequest |
5 | 6 | from aliyunsdkcore.acs_exception.exceptions import ClientException
|
6 | 7 | from aliyunsdkcore.client import AcsClient
|
7 | 8 |
|
8 | 9 |
|
9 | 10 | class TestAcsClient(unittest.TestCase):
|
10 | 11 |
|
| 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 | + |
11 | 18 | def test_acs_client(self):
|
12 | 19 | with self.assertRaises(ClientException) as ex:
|
13 | 20 | AcsClient()
|
@@ -50,3 +57,26 @@ def test_parse_error_info_from_response_body(self):
|
50 | 57 | 'invalid json')
|
51 | 58 | self.assertEqual(code, "SDK.UnknownServerError")
|
52 | 59 | 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