Simple and elegant framework for automating your API tests
Project description
dolpa
dolpa is simple, easy to use library made for API-testing.
Installation
dolpa is available in PyPI.
python -m pip install dolpa
How to use
In a nutshell, dolpa parses your json file which contains information about your API tests. Your JSON file should have the following schema:
{
"config": {
"base_url": "http://localhost:8000",
"headers": {
"client-app": "SHM"
}
},
"calls": [
{
"resource": "/login",
"method": "POST",
"body": {
"currentUser": "alex.martin",
"currentState": "healthy"
},
"headers": {
"app-status": "current"
},
"saves": {
"authToken": "$.auth_token"
},
"assertions": {
"responseCheckAssertion": "responseSent==yes"
}
},
{
"resource": "/users",
"method": "POST",
"body": {
"currentUser": "alex.martin",
"currentState": "healthy"
},
"headers": {
"app-status": "current"
},
"saves": {
"current_block": "$.currentDepartment.currentBlock",
"currentFriend": "$.currentDepartment.departmentInfo.employees[2]"
},
"assertions": {
"nameCheck": "$.currentDepartment.departmentInfo.employees[2]==Tammy"
}
},
{
"resource": "/preference",
"method": "POST",
"body": {
"currentUser": "alex.martin",
"currentState": "healthy"
},
"headers": {
"app-status": "current"
},
"saves": {
"$.currentDepartment.currentBlock": "current_block"
},
"assertions": {
"nameCheck": "$.workingBlock=={{current_block}}",
"friendCheck": "$.friend=={{currentFriend}}"
}
}
]
}
config
can be any valid JSON. Keys of config
will remain as
global variable that can be accessed using {{<key>}}
anywhere
in the call definition.
So how to run API tests then?
You should start by making folder for your API tests where JSON files containing tests like above are stored. You can have multiple test folders inside the root test folder. When you run your API tests, it only picks JSON files for testing inside the root and subsequently, sub-folders.
Here is how you start your tests:
from dolpa import run_bulk_api_tests
run_bulk_api_tests('/User/home/test-user/test-folder-path')
That's all the code you need to run your tests.
But wait... my test-cases are little more complicated than that!
Yeah, it's seldom that simple!
However, dolpa makes it super easy to handle those kind of situations. Just write your API-tests JSON files and treat them like each of them are unrelated when you reference them their identifier. You can build complex API-tests relationship as follows:
test_handler = get_api_test_handler('/Users/home/poweruser/test.json')
first_call = test_handler.run(1)
if first_call.response.status_code == 200:
second_call = test_handler.run(2)
...
The above code already abstracts away assertions and other details in the JSON file so you don't have to worry about pesky if/else conditions and can focus on the core-logic of your tests. Enjoy!
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
Built Distribution
File details
Details for the file dolpa-0.1.41.tar.gz
.
File metadata
- Download URL: dolpa-0.1.41.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/23.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b644b4ced3aa097a224492ddd48cfd57c0cbafcac9cbfcd42a8797c1d6979484 |
|
MD5 | 7880cbff9bcb61b140dc18cdc154bdf8 |
|
BLAKE2b-256 | 8093389e419bad7cd47f82814004e70137a567f058ffaefd28641db569b9f8fc |
File details
Details for the file dolpa-0.1.41-py3-none-any.whl
.
File metadata
- Download URL: dolpa-0.1.41-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/23.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18f99473061e7d2ee88918f6de714e332bc4c1ec9cf3b687729672291375f5ad |
|
MD5 | 2c014ed08cf19a1095da6c47abd4982e |
|
BLAKE2b-256 | 1ad2f8e3dff679ad15f865bed23944181ce01fb966625fc15df273c4ec45ed47 |