visit
- A command-line tool for HTTP tests over RESTful APIs
This tool automate testing in a simple three steps.1. Install the package
pip install pyhttptest
2. Describe your HTTP Requests test cases against your API service in a simplest and widely used format JSON within a file.
Single test case definition examples
{
"name": "TEST: Get server status",
"verb": "GET",
"endpoint": "/get",
"host": "//httpbin.org",
"headers": {
"Accept-Language": "en-US"
}
}
{
"name": "TEST: Create an HTML bin",
"verb": "POST",
"endpoint": "post",
"host": "//httpbin.org",
"payload": {
"content": "Hello, world!"
}
}
Multiple test cases definition example
[
{
"name": "TEST: List all users",
"verb": "GET",
"endpoint": "api/v1/users",
"host": "//localhost:8085/",
"headers": {
"Accept-Language": "en-US"
},
"query_string": {
"limit": 1
}
},
{
"name": "TEST: Add a new user",
"verb": "POST",
"endpoint": "api/v1/users",
"host": "//localhost:8085/",
"payload": {
"username": "pyhttptest",
"email": "[email protected]"
}
},
{
"name": "TEST: Modify an existing user",
"verb": "PUT",
"endpoint": "api/v1/users/XeEsscGqweEttXsgY",
"host": "//localhost:8085/",
"payload": {
"username": "pyhttptest"
}
},
{
"name": "TEST: Delete an existing user",
"verb": "DELETE",
"endpoint": "api/v1/users/XeEsscGqweEttXsgY",
"host": "//localhost:8085/"
}
]
3. Run command and gain report
pyhttptest execute data/test_server_status.json
pyhttptest execute data/requests.json
The properties, which you can pass to a .
json
file are:Best practices
One question may arise in your mind, how to add, structure and organize the test cases into my existing/new project. Every Python project, which has tests contains in his project directory a folder namely
tests/
. From this directory by convention, great frameworks like
unittest
and pytest
discover and execute defined test cases in Python scripts. To not mess up with these tests and break the conventions, I suggest creating a new directory in your project root directory named live_tests/
. Inside the new directory, you can put all .
json
files with defined test cases for the API. By doing this your tests will be easily distinguished. But it’s really up to you!