コード例 #1
0
ファイル: test_client.py プロジェクト: aliyun/tea-rpc
 def test_do_request(self):
     conf = Config(access_key_id='access_key_id',
                   security_token='security_token',
                   protocol='http',
                   region_id='region_id',
                   read_timeout=1000,
                   connect_timeout=5000,
                   endpoint='127.0.0.1:8888',
                   max_idle_conns=1)
     conf.access_key_secret = 'access_key_secret'
     runtime = RuntimeOptions(autoretry=False, max_attempts=2)
     client = Client(conf)
     res = client.do_request(action='action',
                             protocol='http',
                             method='GET',
                             version='version',
                             auth_type='auth_type',
                             query={},
                             body={},
                             runtime=runtime)
     self.assertEqual({'result': 'server test'}, res)
     try:
         client.do_request(action='action',
                           protocol='http',
                           method='POST',
                           version='version',
                           auth_type='auth_type',
                           query={},
                           body={},
                           runtime=runtime)
         assert False
     except Exception as e:
         self.assertIsInstance(e, UnretryableException)
コード例 #2
0
ファイル: test_client.py プロジェクト: aliyun/tea-rpc
    def test_init(self):
        conf = Config()
        try:
            Client(conf)
        except Exception as e:
            self.assertIsInstance(e, TeaException)
        try:
            Client(None)
        except Exception as e:
            self.assertIsInstance(e, TeaException)
            self.assertEqual("'config' can not be unset", e.message)

        conf = Config(
            access_key_id='access_key_id',
            security_token='security_token',
            protocol='protocol',
            region_id='region_id',
            read_timeout=1000,
            connect_timeout=5000,
            http_proxy='http_proxy',
            https_proxy='https_proxy',
            endpoint='endpoint',
            no_proxy='no_proxy',
            max_idle_conns=1,
            network='network',
            user_agent='user_agent',
            suffix='suffix',
            endpoint_type='endpoint_type',
            open_platform_endpoint='open_platform_endpoint',
            type='type',
        )
        conf.access_key_secret = 'access_key_secret'
        client = Client(conf)
        self.assertIsNotNone(client)
コード例 #3
0
ファイル: client.py プロジェクト: aliyun/tea-rpc
 def __init__(
     self,
     config: rpc_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._network = config.network
     self._suffix = config.suffix
     self._endpoint = config.endpoint
     self._protocol = config.protocol
     self._region_id = config.region_id
     self._user_agent = config.user_agent
     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._no_proxy = config.no_proxy
     self._socks_5proxy = config.socks_5proxy
     self._socks_5net_work = config.socks_5net_work
     self._max_idle_conns = config.max_idle_conns
     self._endpoint_type = config.endpoint_type
     self._open_platform_endpoint = config.open_platform_endpoint
コード例 #4
0
ファイル: test_client.py プロジェクト: aliyun/tea-rpc
 async def request(method):
     conf = Config(access_key_id='access_key_id',
                   security_token='security_token',
                   protocol='http',
                   region_id='region_id',
                   read_timeout=1000,
                   connect_timeout=5000,
                   endpoint='127.0.0.1:8888',
                   max_idle_conns=1)
     conf.access_key_secret = 'access_key_secret'
     runtime = RuntimeOptions(autoretry=False, max_attempts=2)
     client = Client(conf)
     return await client.do_request_async(action='action',
                                          protocol='http',
                                          method=method,
                                          version='version',
                                          auth_type='auth_type',
                                          query={},
                                          body={},
                                          runtime=runtime)
コード例 #5
0
ファイル: test_client.py プロジェクト: aliyun/tea-rpc
 def test_model(self):
     conf = Config(access_key_id='access_key_id',
                   access_key_secret='access_key_secret',
                   protocol='http',
                   endpoint='127.0.0.1:8888')
     conf.validate()
     conf = Config(access_key_id='access_key_id',
                   access_key_secret='access_key_secret',
                   protocol='http',
                   region_id=None,
                   endpoint='127.0.0.1:8888',
                   network=None,
                   suffix=None)
     self.assertIsInstance(conf, Config)
     conf.validate()
     conf.to_map()
     conf.from_map({})