Skip to main content

Assertio

Pseudo-functional Python api testing framework.

Installation

pip install assertio

Basic Usage

Assertio consists on create requests on a chain way, you can organize this requests within a Runner class in order to define test cases.

You can find below an example using the Pokemon API

# main.py
from assertio import Request, Runner


class MyRunner(Runner):

    def test_get_pikachu(self):
        Request()\
            .to("/pokemon/pikachu")\
            .with_method("GET")\
            .perform()\
            .assert_http_ok()\
            .assert_response_field("name")\
            .equals("pikachu")

MyRunner().start()

This will run all the defined methods within MyRunner as long as they start with test.

Wait, where should I add my API URL? Well you can export an enviromnent variable for that!

$ export ASSERTIO_BASE_URL=https://pokeapi.co/api/v2

Once this environment variable is setup let's start the test!

$ python main.py

Should do the trick!

But that's not it!

Assertio has many assertions defined and is flexible enough to let you define your custom assertions and preconditions.

You can chain as many assertions and preconditions as you want, just remember to keep it simple, if your request chain is 15 lines long, maybe it's time to consider to split it in smaller tests.

Anyway, let's take a look to a more complex example using a POST to a custom API.

Remember to change the ASSERTIO_BASE_URL environment variable

$ export ASSERTIO_BASE_URL=http://my-books-api-domain/api/v1

And let's try to add a new resource.

# main.py
from assertio import Request, Runner

DEFAULT_HEADERS = {"Content-Type": "application/json"}
BOOK_PAYLOAD = {
    "id": 144,
    "title": "The Divine Comedy", 
    "author": {
        "id": 12,
        "name": "Dante Alighieri",
        "nationality": "Italian"
    }, 
    "year": 1472
}

class MyRunner(Runner):

    def test_create_book(self):
        Request()\
            .to("/books/")\
            .with_method("POST")\
            .with_headers(DEFAULT_HEADERS)\
            .with_body(BOOK_PAYLOAD)\
            .perform()\
            .assert_http_created()\
            .assert_response_field("author.nationality")\
            .equals("Italian")

MyRunner().start()

All the tests must start with test! Otherwise start() method will not run it

Metadata

Release files for assertio 1.5.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for assertio 1.5.11
File Size Uploaded
assertio-1.5.11.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for assertio 1.5.11
File Interpreter ABI Platform
assertio-1.5.11-py3-none-any.whl Python 3 none any Details

Total release size: 26.1 kB

Release files / assertio-1.5.11.tar.gz

Download URL assertio-1.5.11.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0b82f3c3196c73991e87d6bef31f738e71c85d9e3802f5967409b8bd36e8b952
BLAKE2b-256 checksum
How to use checksums
34788a6304bcadcd082eba190f26e697b99589d7e1bb3f75d4e157be3bae4566
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / assertio-1.5.11-py3-none-any.whl

Download URL assertio-1.5.11-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d465f1651de89ac8bb0fd65cbf3e2d00c5903a6e4494d81686b3440d2691b2dc
BLAKE2b-256 checksum
How to use checksums
f5d48f796cd2382035f9db50b0ad5aca823d58a2711935fbc606ea2b08e3e4ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release history Release notifications | RSS feed

This release

1.5.11 This release

2 release files

1.5.9

2 release files

1.5.8

2 release files

1.5.7

2 release files

1.5.6

2 release files

1.5.5

2 release files

1.5.4

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.9

2 release files

1.1.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page