def new_builder(cls, clazz=None): if clazz is None: return ClientBuilder(cls) if clazz.__name__ != "LiveClient": raise TypeError("client type error, support client type is LiveClient") return ClientBuilder(clazz)
def new_builder(cls, clazz=None): if clazz is None: return ClientBuilder(cls, "GlobalCredentials") if clazz.__name__ != "DevStarClient": raise TypeError("client type error, support client type is DevStarClient") return ClientBuilder(clazz, "GlobalCredentials")
def test_default_sdk_logger(): ClientBuilder(Client) \ .with_http_config(config) \ .with_credentials(credentials) \ .with_endpoint(endpoint) \ .build() logger = logging.getLogger(logger_name) assert logger.propagate is False assert len(logger.handlers) == 0
def test_add_stream_handler_to_sdk_logger(): ClientBuilder(Client) \ .with_http_config(config) \ .with_credentials(credentials) \ .with_endpoint(endpoint) \ .with_stream_log(log_level=logging.DEBUG) \ .build() logger = logging.getLogger(logger_name) assert len(logger.handlers) == 1 assert isinstance(logger.handlers[0], StreamHandler) logger.removeHandler(logger.handlers[0])
def client(): ak = "my ak" sk = "my sk" project_id = "my project_id" endpoint = "https://vpc.cn-north-x.myhuaweicloud.com" config = HttpConfig.get_default_config() config.ignore_ssl_verification = True credentials = BasicCredentials(ak, sk, project_id) client = ClientBuilder(Client) \ .with_http_config(config) \ .with_credentials(credentials) \ .with_endpoint(endpoint) \ .build() yield client
def test_add_rotating_file_handler_to_sdk_logger(): ClientBuilder(Client) \ .with_http_config(config) \ .with_credentials(credentials) \ .with_file_log(path="tests.log", log_level=logging.DEBUG, max_bytes=1024, backup_count=1) \ .with_endpoint(endpoint) \ .build() logger = logging.getLogger(logger_name) assert len(logger.handlers) == 1 assert isinstance(logger.handlers[0], RotatingFileHandler) assert logger.handlers[0].baseFilename.endswith("tests.log") assert logger.handlers[0].maxBytes == 1024 assert logger.handlers[0].backupCount == 1 logger.removeHandler(logger.handlers[0]) os.remove("tests.log")
def test_build_client_by_client_builder(): client = ClientBuilder(Client) \ .with_http_config(config) \ .with_credentials(credentials) \ .with_endpoint(endpoint) \ .build() assert isinstance(client, Client) assert client.get_agent() == {"User-Agent": "huaweicloud-usdk-python/3.0"} assert client.get_credentials().ak == "my ak" assert client.get_credentials().sk == "my sk" assert isinstance(client.get_http_client(), HttpClient) assert client.get_http_client()._timeout == (3, 10) assert client.get_http_client()._verify is False
def new_builder(clazz): return ClientBuilder(clazz)
def new_builder(clazz): return ClientBuilder(clazz, "GlobalCredentials")