Skip to main content

A simple python app for sending a set of consecutive HTTP requests defined in YAML requests plan.

Project description

yaml_requests

CI Release Maintainability Test Coverage

A simple python app for sending a set of consecutive HTTP requests defined in YAML requests plan.

Installing

Ensure that you are using Python >= 3.7 with python --version. This app/package is available in PyPI. To install, run:

pip install yaml_requests

Usage

The app is used to execute HTTP requests defined in YAML files. The YAML file must contain main-level key requests, that contains an array of requests, where each item of the list is a request object. The request object contains at least a method key (get, post, options, ...) which value is passed to requests.request function, or to requests.Session.request if plan level option session is truthy.

Minimal YAML request plan should thus include requests array, with single item in it:

requests:
- get:
    url: https://google.com

In addition to this basic behavior, more advanced features are provided as well:

  • All value fields in requests array items support jinja2 templating.
  • Variables can be defined in YAML request plan and overridden from commandline arguments.
  • Response of the most recent request is stored in response variable as requests.Response object.
  • Responses can be stored as variables with register keyword.
  • Response can be verified with assertions.

More advanded example that can be run against dummy API provided by tst/server/api.py:

name: Simulate execution of a build from queue
variables:
  base_url: http://localhost:5000
  node: default
requests:
- name: Get queued items
  get:
    url: "{{ base_url }}/queue"
  assert:
  - name: Queue is not empty
    expression: response.json() | length
  - name: Status code is 200
    expression: response.status_code == 200
  - name: Request took less than 5 seconds
    expression: response.elapsed.total_seconds() < 5
  register: queue_response_1
- name: "Create build for first item in the queue ({{ response.json().0.id }})"
  post:
    url: "{{ base_url }}/queue/{{ response.json().0.id }}/init"
    json:
      node: "{{ node }}"
  register: build_create
- name: Get queued items
  get:
    url: "{{ base_url }}/queue"
  assert:
  - name: Queue is shorter than initially
    expression: response.json() | length < queue_response_1.json() | length
- name: "Complete the created build ({{ build_create.json().build_id }})"
  post:
    url: "{{ base_url }}/builds/{{ build_create.json().build_id }}/complete"
- name: Output build details
  get:
    url: "{{ base_url }}/builds/{{ build_create.json().build_id }}"
  output: yaml

These two examples are also available in tst/plans directory and can be executed with:

yaml_requests tst/minimal_plan.yml
yaml_requests tst/build_queue.yml

See yaml_requests --help for full CLI usage.

Testing

Check and automatically fix formatting with:

pycodestyle yaml_requests
autopep8 -aaar --in-place yaml_requests

Run static analysis with:

pylint -E --enable=invalid-name,unused-import,useless-object-inheritance yaml_requests

Run unit tests with command:

python3 -m unittest discover -s tst/

Get test coverage with commands:

coverage run --branch --source yaml_requests/ -m unittest discover -s tst/
coverage report -m

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yaml_requests-0.6.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

yaml_requests-0.6.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file yaml_requests-0.6.0.tar.gz.

File metadata

  • Download URL: yaml_requests-0.6.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for yaml_requests-0.6.0.tar.gz
Algorithm Hash digest
SHA256 70e361203dc2aa913364c9532f18b8992ecb58f7effa59084c751e8ce69c5257
MD5 abe0199a96d440438dc50d113b0fb1b7
BLAKE2b-256 d7644576d467dd8436491a4491ad1541aad81e48689e85ce6da0019f6ec71a2f

See more details on using hashes here.

File details

Details for the file yaml_requests-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: yaml_requests-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for yaml_requests-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77d1659bf5fd9c9d63a334f4e7ac7def84c4b1024eaa5885d597e82f648371e9
MD5 1002e3e07c58a62010770af3a000f089
BLAKE2b-256 00d69b2bc259e49896d3d7a88cc5a948a913f3c0148ed593b21ee802c20f5a9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page