Skip to main content

Asynchronously make and validate requests!

Project description

Quickbolt

Asynchronously make and validate requests!

This was forked from api-automation-tools.

Table of contents

Installation

$ pip install quickbolt

Usage

Pytest

The CorePytestBase loads json files from credentials and data folders during setup. Validations and reporting are performed during the teardown.

Async requests with aiohttp or httpx

Make single or batched style async requests using aiohttp or httpx. Each request method call will generate a csv containing useful data about the request(s). The usual request arguments of aiohttp and httpx are supported.

There's a nifty function called generate_batch that'll intake valid (200 type) request information and return a list of corruptions for execution.

from quickbolt.clients import AioRequests, HttpxRequests

aiohttp_requests = AioRequests()
httpx_requests = HttpxRequests()

batch = {'method': 'get', 'headers': {...}, 'url': '...'}
response = aiohttp_requests.request(batch)
response = httpx_requests.request(batch)

or

batch = [{'method': 'get', 'headers': {...}, 'url': '...'}, {...}, ...]
responses = aiohttp_requests.request(batch)
responses = httpx_requests.request(batch)

or 

from quickbolt.batch_generation import generate_batch

batch = generate_batch("get", ...)
responses = aiohttp_requests.request(batch)
responses = httpx_requests.request(batch)

Note: Both clients have an awaitable request method called async_request e.g. await aiohttp_requests.async_request(...) or await httpx_requests.async_request(...).

Note: You can indicate where the batch generator will start looking for path parameters by placing a semicolon (;) where the path parameters start (before a /) e.g. https://httpbin.org/get;/param/value.

Async calls with grpc

Make single or batched style async calls using grpc. Each call method call will generate a csv containing useful data about the call(s).

See here for a quick tutorial on the mechanics of making grpc calls.

from quickbolt.clients import AioGPRC
from tests.client.gprc.servers import helloworld_pb2, helloworld_pb2_grpc

aio_grpc = AioGPRC()

options = {
    "address": "localhost:50051", # the address of the server
    "stub": helloworld_pb2_grpc.GreeterStub, # the stub class reference of the service
    "method": "SayHello", # the service method to call
    "method_args": helloworld_pb2.HelloRequest(name="Quickbolt"), # the args the service method accepts
}
responses = await pytest.aio_grpc.call(options)

Note: Generate batch is not supported for async grpc calls.

Validations

After each request, a scrubbed copy of the csv history of the execution will be generated. This file (or the original) can be used to validate against executions over time. These files will have the same name as the running test, just with the csv extenstion instead. Any mismatches can be raised as errors and are reported in a separate csv. Historical csv files to be used as reference can be stored in a validations folder at the root level.

from quickbolt.validations import Validations

...requests were made and csv files were generated...

validations = Validations()
mismatches = await validations.validate_references(actual_refs={...})
mismatches => 
[
    {
        "values": [{"key": "ACTUAL_CODE", "d1": "404", "d2": "999"}, ...],
        "keys": [...],
        "skipped_keys": [...],
        "actual_refs": {...},
        "expected_refs": {...},
        "unscrubbed_refs": {...},
    },
    {...},
]

Examples

An example of a test - test_get.py

An example of a base class showing a setup and teardown - some_pytest_base.py

An example of the scrubbed csv report file generated from running the test - get_scrubbed.csv

Project structure

This package requires the following base structure for the project.

.
├── credentials                         # Optional - credentials
│   └── credentials.json                # Optional - credentials as json
├── tests                               # Required - test files
│   ├── data                            # Optional - test data
│   │   └── data.json                   # Optional - test data as json
│   └── test_some_request.py            # Required - pytest test
└── validations                         # Optional - validation data
    └── some_request.json               # Optional - validation data as json. the validation files 
                                                     directory structure must match the structure of the tests in the tests folder.

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

quickbolt-0.4.2.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quickbolt-0.4.2-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file quickbolt-0.4.2.tar.gz.

File metadata

  • Download URL: quickbolt-0.4.2.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.2 Linux/6.10.14-linuxkit

File hashes

Hashes for quickbolt-0.4.2.tar.gz
Algorithm Hash digest
SHA256 99a135c9abf0e45a9973fd1efffb8bd24ed737b69e81f9e9b6b84cbf37cfd304
MD5 018a948a747246fc61fdac2ae5578431
BLAKE2b-256 cd80bb741561da2123eeab8084e09f0a2b0855aec9c0e2f8132855808a260249

See more details on using hashes here.

File details

Details for the file quickbolt-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: quickbolt-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.2 Linux/6.10.14-linuxkit

File hashes

Hashes for quickbolt-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 563700b1853d49dd0849b4e884ee78cc6212f3683a827a747a66a60b157dd0f0
MD5 92d5117a2e296952256b691f25f9fe63
BLAKE2b-256 01f41c1086eac7445dae97e3676fec097c7a13ea9a953ceaab9d37e9add903c5

See more details on using hashes here.

Supported by

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