跳转到主要内容

测试用例账户管理工具

项目描述

Ethel

Ethel是一款允许您在测试环境、QA环境或其他任何环境中操作账户、购买订阅、激活它们并执行其他任务的工具。

安装

pip install ethel

用法

先决条件

在您可以使用Ethel之前,您必须相应地设置您的环境

# Required:
EBS_CERT_PUBLIC=<PATH_TO_EBS_SSL_CLIENT_CERTIFICATE>
EBS_CERT_KEY=<PATH_TO_EBS_SSL_CLIENT_CERTIFICATE_KEY>

# Optional:
CANDLEPIN_USERNAME=<CANDLEPIN_SUPERUSER_USERNAME>  # Defaults to "candlepin_admin"
CANDLEPIN_PASSWORD=<CANDLEPIN_SUPERUSER_PASSWORD>  # Defaults to "candlepin_admin"

基本用法

最基础的用法案例是简单地创建一个账户并将其订阅到某个产品。

>>> from ethel import Ethel

>>> ethel = Ethel.stage()

>>> account = ethel.create_account('some_fancy_username', 'not_so_secret_password')

>>> account.subscribe('product_sku')

Ethel通过类方法Ethel.stage()Ethel.qa()提供对测试环境和QA环境的访问。

高级用法

Ethel默认情况下,在创建账户时会为您处理所有操作。此外,如果已存在具有相同用户名的账户,Ethel会验证您的凭据并返回已存在的账户条目。

在创建账户时,Ethel确保创建了Candlepins所有者(强制刷新Candlepin),并接受所有必需的条款和条件。要禁用此行为,您可以在创建账户时传递create_owners=False和/或accept_terms=False,然后在之后自行完成

>>> account = ethel.create_account(
... "some_fancy_username",
... "not_so_secret_password",
... first_name="Gretchen",
... last_name="SomeOldSurname",
... email="grandmas.dont.have@emails.com",
... create_owners=False,
... accept_terms=False,
... )

>>> account.start_refresh()

>>> account.get_refresh_status()
'RUNNING'

>>> account.get_refresh_status()
'FINISHED'

>>> account.accept_all_terms(optional=True)  # Accepts also the optional Terms and Conditions

您还可以在请求Ethel为您的账户订阅时指定更多关于所需订阅的详细信息

>>> account.subscribe(
... 'product_sku',
... quantity=42,
... start_date='yesterday',  # accepts 'yesterday', 'today', 'tomorrow', ISO date 'YYYY-MM-DD' or datetime.date
... duration=365 # accepts integer that means 'days' or datetime.timedelta
... )

错误和异常

如果Candlepin或EBS REST API服务返回异常到Ethel,它们将被统一并作为EthelError接口。根据引发异常的确切API,详细程度有所不同。以下属性被存储

  • message - 应包含异常发生的原因。
  • message_type - 异常原因描述的类别(与exception_type不同)。
  • exception_type - 异常类型(类名)。
  • status_code - HTTP状态码(EBS喜欢在任何原因下返回HTTP_500)。
  • source - 导致异常的API。
  • uuid - Candlepin API中异常的跟踪代码。
  • raw_error - 提供直接访问PreparedRequestResponseHTTPError对象。

Ethel不处理requests.ConnectionErrorrequests.Timeout。为了方便,提供了一个简写形式的EthelConnectionError。Ethel不会重试任何请求,处理此行为取决于用户。

>>> account = ethel.create_account('USERNAME', 'WRONG_PASSWORD')
EthelError: From: Candlepin(api_base_url=<CANDLEPIN_URL_FOR_THIS_ENV>). Reason: Invalid user credentials. Status code: 401. Call(method=GET, url=<CANDLEPIN_URL_FOR_THIS_ENV>)/users/<USERNAME>/owners).

>>> try:
...     account = ethel.create_account('<USERNAME>', '<WRONG_PASSWORD>')
... except EthelError as e:
...     logging.error("Status Code %d, Message: %s, Tracking code %s" % (e.status_code, e.message, e.uuid))

ERROR:root:Status Code 401, Message: Invalid user credentials, Tracking code e7275480-2c59-42fa-a6db-b8df6a9dc323

附加属性

Ethel存储了一些对您有用的重要属性,用于您的每个账户。

  • 组织ID
  • Candlepin所有者ID
  • 本会话中完成的所有订阅订单列表
  • 本会话中完成的所有激活订单列表
>>> account.org_id
123456789

>>> account.owner_id
987654321

>>> account.orders
[...]

>>> account.activations
[...]

查看账户

由于Ethel允许您每天都享受“黑色星期五”般的订阅优惠,您可能想查看您购买的所有东西。

>>> account.list_pools()  # You can pass future=True argument to list also pools valid in future
[
    {
        'pool_id': '<USE_THIS_TO_SUBSCRIBE>',
        'sku_id': '<PRODUCT_SKU_ID>',
        'product_name': 'Fancy Product Name',
        'start_date': '2020-02-07T05:00:00+0000',
        'end_date': '2021-02-07T04:59:59+0000',
        'muiltiplier': None,
        'quantity': 'unlimited',
        'instance_multiplier': None
    },
    {
        'pool_id': '<ALSO_USE_THIS_TO_SUBSCRIBE>',
        'sku_id': '<ANOTHER_PRODUCT_SKU_ID>',
        'product_name': 'Fancy Product Name',
        'start_date': '2020-02-06T05:00:00+0000',
        'end_date': '2021-02-06T04:59:59+0000',
        'muiltiplier': None,
        'quantity': 1,
        'instance_multiplier': 16
    },
    ...
]

开发者设置

在克隆此存储库后,通过Poetry设置本地环境。

poetry install

准备好的任务

  • poetry run task lint - 运行MypyPylint
  • poetry run task test - 运行Pytest测试套件。

项目详情


下载文件

下载适合您平台文件的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源分发

ethel-3.0.0rc2.tar.gz (17.6 kB 查看散列值)

上传时间

构建分发

ethel-3.0.0rc2-py3-none-any.whl (18.9 kB 查看散列值)

上传时间 Python 3

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面