Python REST Playbook
Provides a framework for defining a series (playbook) of rest messages to perform automated testing or access of an endpoint.
Features
- Substitution of values in a templated REST message
- Content can be optional or mandatory for provided values
- Run messages in a user defined order
- Define pause times between messages
- Validate status codes for each step
- Run code after each step to validate or modify future behaviour
- Use different basic authentication details per call
Usage
Since playbook is driven from defined input files the code required to run a playbook is short. All of the development time as a goal should be spent in the input files
from rest_playbook_micro.rest_playbook import RESTPlaybook as RP
pb = RP("test.playbook","test.scenario","test.vars")
results = pb.run_playbook()
print(results)
All files are flat text and we will discuss their format now. Examples are provided in ./tests
Vars file
All variables are defined in the format <variable_name>=<value>,
<variable_name> character set is best restricted to [A-Z*]and never=. = symbols in<value> do not need to be escaped since the parser will only use the first occurance in each line as a separator.
PAGE=1
ID=ORDER001
SERVICE_ID=SERVICEORDER001
TIMESTAMP=2023-01-02 12:25:01
Scenario
Define a scenario for a specific message content. SCENARIO= block outlines meta information for the content, whereas HEADER=, PARAMS= and BODY= outline standard HTTP REST data. Close each block with the block name prepended with =
Variable substitutions are marked with %ENV_<VARNAME>%. You can define content that will not be copied with %OPTIONAL: and enforce variables being provided with %MANDATORY:%
----
SCENARIO=
NAME=EASY NAME
DESCRIPTION=Scenario Example
TYPE=POST
ENDPOINT=http://localhost:3876/200
=SCENARIO
HEADER=
Content-Type:application/json
Accept:application/json
=HEADER
PARAMS=
page=%ENV_PAGE%
=PARAMS
BODY=
{
"timestamp":"%ENV_TIMESTAMP%"
%OPTIONAL:ENV_ID%,"id":"%ENV_ID%"
%MANDATORY:ENV_SERVICE_ID%,"service_id":"%ENV_SERVICE_ID%"
}
=BODY
----
Playbook
A Playbook is a defined series of steps relating to scenario names and the step that follows
NAME- Scenario name
WAIT- Time in seconds to wait in the step
STEP- Identifies each step in the book
NEXT_STEP- Which step to move onto, without the playbook will end
----
NAME=aa
WAIT=1
STEP=1
NEXT_STEP=2
----
NAME=ac
WAIT=1
STEP=2
----
Assertion
Create an inheritance of the Assertion class provided by the module. Implement the run_assert function to process for each step provided to it and return True or False to continue or halt the playbook.
You have access to the current Play class and the variables being used in the
from rest_playbook_micro import Assertion
from rest_playbook_micro import Play as P
class TestAssertion(Assertion):
def __init__(self) -> None:
pass
def run_assert(self, play: P, variables) -> bool:
match play.STEP:
case '1':
self.run_01(play, variables)
case '2':
self.run_02(play, variables)
case _:
pass
return True
def run_01(self, play: P, variables) -> bool:
play.result.assert_test = True
return True
def run_02(self, play: P, variables) -> bool:
play.result.assert_test = False
return True
Then we can instantiate this class and use it in the call to the playbook
from rest_playbook_micro.rest_playbook import RESTPlaybook as RP
assertion = TestAssertion()
pb = RP("test.playbook",
"test.scenario",
"test.vars",
assertion=assertion)
results = pb.run_playbook()
print(results[0].assert_test)
# True
Build
python -m build
python -m twine upload dist/*
Metadata
Release files for rest-playbook-micro 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rest_playbook_micro-0.1.3.tar.gz | 11.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rest_playbook_micro-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.1 kB
Release files / rest_playbook_micro-0.1.3.tar.gz
| Download URL | rest_playbook_micro-0.1.3.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dcea91325a67557ecea23efac77638503c0bc83f88547fa5cf71ae8f2842ee2e
|
|
BLAKE2b-256 checksum How to use checksums |
06cf2341acd722722f26351be15652206abb5d74fa91ff5e10048cfb5a9676cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / rest_playbook_micro-0.1.3-py3-none-any.whl
| Download URL | rest_playbook_micro-0.1.3-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d16e79dff7a3e4672ec7a4a094da5e65a295bdf7e952dbe137f0e27852c4e17b
|
|
BLAKE2b-256 checksum How to use checksums |
eac9e25e044e6014e5ee9bd17dceda8a666fcff147d5cb23bfd9220e4c9d7054
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Security for rest-playbook-micro 0.1.3
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.