Skip to main content

ctyunsdk_dcs220231018 - DCS2 SDK 实际调用测试

此项目包含针对 ctyunsdk_dcs220231018 包中 DCS2(分布式缓存 Redis)多个 API 接口的实际调用测试用例。

依赖信息

  • 包名: ctyunsdk_dcs220231018
  • 版本: 2.0.0
  • 核心依赖:
    • requests>=2.32.5
    • ctyun_python_sdk_core>=0.0.1

测试覆盖的接口

接口 测试文件 说明
get_zones test_get_zones_real.py 查询指定资源池下支持的可用区
describe_instances test_describe_instances_real.py 查询分布式缓存 Redis 实例列表
describe_backups test_describe_backups_real.py 查询备份文件信息
get_available_region test_get_available_region_real.py 查询支持的所有资源池
query_quota_total_and_used test_query_quota_total_and_used_real.py 查询配额限制
describe_available_resource test_describe_available_resource_real.py 查询可订购的实例类型属性
label_page_list test_label_page_list_real.py 查询租户所有标签列表

环境变量配置

测试通过环境变量读取 API 凭证,运行前需配置以下变量:

环境变量 说明 必填
CTYUN_ENDPOINT API endpoint 地址(如 https://dcs2.ctyun.cn) 是
CTYUN_AK access_key_id 是
CTYUN_SK access_key_secret 是
CTYUN_RES_POOL_CODE 资源池编码(用于 get_zones、get_available_region 等接口) 否
CTYUN_PROD_INST_ID 实例ID(用于 describe_backups 接口) 否
CTYUN_VERIFY_TLS 是否验证 TLS 证书(true/false,默认 true) 否

未配置必填环境变量时,测试会自动跳过。

使用方法

方法一:使用自动化脚本(推荐)

# 在项目根目录下运行
python run_real_test.py

脚本会自动:

  1. 运行所有 *_real.py 测试模块
  2. 汇总统计成功/失败/跳过数量
  3. 根据测试结果返回退出码

方法二:使用 unittest 直接运行

# 1. 安装依赖
pip install -e .

# 2. 运行所有测试
python -m unittest test_get_zones_real test_describe_instances_real test_describe_backups_real test_get_available_region_real test_query_quota_total_and_used_real test_describe_available_resource_real test_label_page_list_real -v

方法三:运行单个测试文件

# 直接运行某个测试文件
python test_describe_instances_real.py

测试设计说明

  1. 实际 API 调用:所有测试均发起真实网络请求,验证 SDK 能否正确调用 API 并解析响应。
  2. 响应缓存:每个测试类在 setUpClass 中发起一次 API 请求并缓存响应,所有测试方法复用,避免重复网络调用。
  3. 跳过机制:未配置凭证时通过 @skip_if_no_credential 自动跳过;未配置 CTYUN_PROD_INST_ID 时跳过 describe_backups 测试。
  4. 断言粒度:验证响应类型、statusCode == 800、returnObj 结构及核心字段存在性。

注意事项

  1. 网络连接: 测试需要访问天翼云 API,确保网络连通。
  2. Python版本: 需要 Python 3.9 或更高版本。
  3. TLS 验证: 默认开启 TLS 证书验证,如需关闭可设置 CTYUN_VERIFY_TLS=false。
  4. API 限流: 避免短时间内频繁运行测试,以免触发 API 限流。

故障排除

常见问题

  1. 依赖安装失败

    # 尝试更新 pip
    python -m pip install --upgrade pip
    
  2. 测试全部跳过

    • 检查 CTYUN_ENDPOINT、CTYUN_AK、CTYUN_SK 环境变量是否已配置
    • 确认凭证是否有效
  3. 测试失败

    • 检查网络连接
    • 确认 API endpoint 地址是否正确
    • 查看测试输出中的错误信息

技术支持

如有问题,请参考:

  • 项目文档
  • Python unittest 官方文档
  • ctyunsdk 官方文档

Metadata

Release files for ctyunsdk-dcs220231018 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ctyunsdk-dcs220231018 2.0.1
File Size Uploaded Provenance Actions
ctyunsdk_dcs220231018-2.0.1.tar.gz 67.5 kB Without provenance Details for ctyunsdk_dcs220231018-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ctyunsdk-dcs220231018 2.0.1
File Interpreter ABI Platform Actions
ctyunsdk_dcs220231018-2.0.1-py3-none-any.whl Python 3 none any Details for ctyunsdk_dcs220231018-2.0.1-py3-none-any.whl

Total release size: 288.3 kB

Release files / ctyunsdk_dcs220231018-2.0.1.tar.gz

Download URL ctyunsdk_dcs220231018-2.0.1.tar.gz
Size 67.5 kB
Tags Source
SHA-256 checksum
How to use checksums
231ce048c274e5eeeb851d5edb61e5b93f0b12aa905e1df3997e1d257466d3dd
BLAKE2b-256 checksum
How to use checksums
b744334839152b558276b75b151affd6bc52d0dce9625120221c29cd4791fde8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.9

Release files / ctyunsdk_dcs220231018-2.0.1-py3-none-any.whl

Download URL ctyunsdk_dcs220231018-2.0.1-py3-none-any.whl
Size 220.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f967de30a0b559b061cf71e6aa9a947a7738646305dcb4fa632d9d4a879d1b2
BLAKE2b-256 checksum
How to use checksums
a8a246f6f3fbf559efa58b1ebd395817a4183983be19f6e25f9a649348cd27c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.9

Security for ctyunsdk-dcs220231018 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page