Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)