示例#1
0
 def test_do_request(self):
     conf = Config(access_key_id='access_key_id',
                   access_key_secret='access_key_secret',
                   security_token='security_token',
                   protocol='http',
                   region_id='region_id',
                   read_timeout=10000,
                   connect_timeout=5000,
                   endpoint='127.0.0.1:8888',
                   max_idle_conns=1)
     runtime = RuntimeOptions(autoretry=False, max_attempts=2)
     client = Client(conf)
     res = client.do_request(protocol='http',
                             method='GET',
                             version='version',
                             auth_type='auth_type',
                             pathname='',
                             query={},
                             body=None,
                             headers={},
                             runtime=runtime)
     res.pop('headers')
     self.assertEqual({'body': {'result': 'server test'}}, res)
     try:
         client.do_request(protocol='http',
                           method='POST',
                           version='version',
                           auth_type='auth_type',
                           pathname='',
                           query={},
                           body=None,
                           headers={},
                           runtime=runtime)
     except Exception as e:
         self.assertIsInstance(e, UnretryableException)
示例#2
0
文件: client.py 项目: aliyun/tea-roa
 def __init__(
     self,
     config: roa_models.Config,
 ):
     """
     Init client with Config
     @param config: config contains the necessary information to create a client
     """
     if UtilClient.is_unset(config):
         raise TeaException({
             'code': 'ParameterMissing',
             'message': "'config' can not be unset"
         })
     UtilClient.validate_model(config)
     if not UtilClient.empty(config.access_key_id) and not UtilClient.empty(
             config.access_key_secret):
         if not UtilClient.empty(config.security_token):
             config.type = 'sts'
         else:
             config.type = 'access_key'
         credential_config = credential_models.Config(
             access_key_id=config.access_key_id,
             type=config.type,
             access_key_secret=config.access_key_secret,
             security_token=config.security_token)
         self._credential = CredentialClient(credential_config)
     elif not UtilClient.is_unset(config.credential):
         self._credential = config.credential
     else:
         raise TeaException({
             'code':
             'ParameterMissing',
             'message':
             "'accessKeyId' and 'accessKeySecret' or 'credential' can not be unset"
         })
     self._region_id = config.region_id
     self._protocol = config.protocol
     self._endpoint_host = config.endpoint
     self._read_timeout = config.read_timeout
     self._connect_timeout = config.connect_timeout
     self._http_proxy = config.http_proxy
     self._https_proxy = config.https_proxy
     self._max_idle_conns = config.max_idle_conns
示例#3
0
 def test_check_config(self):
     config = Config(
         access_key_id='access_key_id',
         access_key_secret='access_key_secret',
         region_id='cn-hangzhou',
         endpoint='127.0.0.1:8888',
     )
     client = Client(config, _endpoint_rule='endpoint_rule')
     client.check_config(config)
     config = Config(
         access_key_id='access_key_id',
         access_key_secret='access_key_secret',
         region_id='cn-hangzhou',
     )
     client = Client(config)
     try:
         client.check_config(config)
     except Exception as e:
         self.assertEqual(e.code, 'ParameterMissing')
         self.assertEqual(e.message, "'config.endpoint' can not be empty")
示例#4
0
    def test_init(self):
        conf = Config()
        try:
            Client(conf)
        except Exception as e:
            self.assertIsInstance(e, TeaException)

        conf = Config()
        dic = {
            'accessKeyId': 'access_key_id',
            'accessKeySecret': 'access_key_secret',
            'securityToken': 'security_token',
            'protocol': 'protocol',
            'regionId': 'region_id',
            'readTimeout': 1000,
            'connectTimeout': 5000,
            'httpsProxy': 'https_proxy',
            'endpoint': 'endpoint',
            'noProxy': 'no_proxy',
            'maxIdleConns': 1,
            'network': 'network',
            'suffix': 'suffix',
            'type': 'type',
        }
        conf.from_map(dic)
        client = Client(conf)
        self.assertIsNotNone(client)
示例#5
0
 async def request(method):
     conf = Config(access_key_id='access_key_id',
                   access_key_secret='access_key_secret',
                   security_token='security_token',
                   protocol='http',
                   region_id='region_id',
                   read_timeout=10000,
                   connect_timeout=5000,
                   endpoint='127.0.0.1:8888',
                   max_idle_conns=1)
     runtime = RuntimeOptions(autoretry=False, max_attempts=2)
     client = Client(conf)
     return await client.do_request_async(protocol='http',
                                          method=method,
                                          version='version',
                                          auth_type='auth_type',
                                          pathname='',
                                          query={},
                                          body=None,
                                          headers={},
                                          runtime=runtime)