Account Management Tool for Testing
Project description
Ethel
Ethel is a tool that allows you to manipulate with accounts in Stage, QA or any other environment, buy Subscriptions, activate them and do other chores.
Instalation
pip install ethel
Usage
Prerequisites
Before you can use Ethel, you have to set up your environment accordingly:
# 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"
Basic usage
The most basic usecase is to simply create an account and subscribe it to a product.
>>> from ethel import Ethel
>>> ethel = Ethel.stage()
>>> account = ethel.create_account('some_fancy_username', 'not_so_secret_password')
>>> account.subscribe('product_sku')
Ethel provides access to Stage and QA environments via Ethel.stage()
and Ethel.qa()
class methods.
Advanced usage
Ethel, by default, processes everything for you when the account is being created. Also, if account with the same username already exists, Ethel verifies your credentials and returns you the already existant account entry.
When account is being created, Ethel ensures that it's Candlepins owners are created (forces Candlepin refresh) and accepts all required Terms and Conditions. To disable this behavior, you can pass create_owners=False
and/or accept_terms=False
when creating account and do it yourself later:
>>> 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
You can also specify more details about your desired subscription when asking Ethel to subscribe it you your account:
>>> 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
... )
Errors and Exceptions
If an exception is returned to Ethel from either Candlepin or the EBS rest API services, they are unified and interfaced as an EthelError
. Depending on the exact API that raised the exception, the level of detail varies. Following properties are stored:
message
- Should contain the reason why the exception occurred.message_type
- Class of the exception reason description (different toexception_type
).exception_type
- Type of exception (class name).status_code
- HTTP status code (EBS likes to return HTTP_500 for any reason).source
- API that caused the exception.uuid
- Exception's tracking code for Candlepin API.raw_error
-HTTPError
object providing access toPreparedRequest
andResponse
directly.
Ethel does not handle requests.ConnectionError
and requests.Timeout
. For convenience a shorthand EthelConnectionError
is provided. Ethel doesn't retry any request, it's up to user to handle this behavior.
>>> 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
Additional properties
Ethel stores few important properties for each of your accounts that might be usefull to you:
- Organization ID
- Candlepin Owner ID
- List of all Subscription orders done in this session
- List of all Activation orders done in this session
>>> account.org_id
123456789
>>> account.owner_id
987654321
>>> account.orders
[...]
>>> account.activations
[...]
View Account
And since Ethel allows you to have a Black Friday for subscriptions everyday, you may want to look up all the things you've bought:
>>> 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
},
...
]
Developer setup
After cloning this repo, setup the local environment via Poetry:
poetry install
Prepared tasks
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ethel-3.0.0rc2.tar.gz
.
File metadata
- Download URL: ethel-3.0.0rc2.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.5 Linux/5.8.1-zen1-1-zen
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cd7640b866b75bfd3b2fe452d62edbcb9320f2c8e4bf8383e45df443bda25cb |
|
MD5 | a2c30ac7ab2efe2a96e967319ee553db |
|
BLAKE2b-256 | fbd81aed072572b43b086de85c06b43a5f2808f00617cf22d8510d6c5338ca85 |
File details
Details for the file ethel-3.0.0rc2-py3-none-any.whl
.
File metadata
- Download URL: ethel-3.0.0rc2-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.5 Linux/5.8.1-zen1-1-zen
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3d2c45b9eee7e97331fec16fe706c81fe38a2a33c9d5596f4dee60ff6c843e8 |
|
MD5 | fd7bb8de503b25eee4b15ea08522ca2a |
|
BLAKE2b-256 | e6dbc764fc96a9e36fc2183eb2510eb81a395a6c93731071b340365e5e1914f6 |