vedro-replay package
Project description
vedro-replay
Documentation
replay-tests
The idea is to test the API using requests that are sent to the production application. Having requests, we can send them to the API of the test version and to the API of the stable version. After receiving two responses from two versions of the application, you can compare the response status, headers, and body. The stable version in this case is considered to work correctly and in case of a difference in the answers it means that there is a bug in the test version of the application.
vedro-replay
Python package for working with replay tests on vedro (docs: vedro.io) framework. Enable generation of replay-tests by request files and contains the necessary tools for working and configuring tests.
Installation
$ pip3 install vedro-replay
Usage
Commands
$ vedro-replay -h
usage: vedro-replay [-h] {generate} ...
vedro-replay commands
positional arguments:
{generate} List of available commands
generate Generate vedro-replay tests
options:
-h, --help show this help message and exit
Generate vedro-replay tests
$ vedro-replay genearate -h
usage: vedro-replay generate [-h] [--path-requests PATH_REQUESTS] [--force]
[{all,vedro_cfg,config,interfaces,contexts,helpers,helpers_methods,scenarios}] - by default all
positional arguments:
{all,vedro_cfg,interfaces,contexts,helpers,helpers_methods,scenarios}
Generation option
options:
-h, --help show this help message and exit
--path-requests PATH_REQUESTS
The path to the directory containing the request files
--force Forced regeneration. The files will be overwritten
To be able to generate a test, you need to have a directory with files containing GET requests
(requests
directory is expected by default, you can specify a specific directory using the --path_requests
argument).
(So far only use of GET requests is possible)
Example:
tests # Root directory
|----requests
|----|----byid.txt # File with API requests of the /byid method
|----|----search.txt # File with API requests of the /search method
Example of file contents:
$ cat requests/byid.txt
/byid?id=123
/byid?id=234
...
Having requests, you can generate tests on them:
$ vedro-replay generate
Example of generation:
tests # Root directory
|----requests
|----|----byid.txt # File with API requests of the /byid method
|----|----search.txt # File with API requests of the /search method
|----contexts
|----helpers
|----interfaces
|----scenarios # Testing scenarios
|----|----byid.py # Scenario, using requests from a file requests/byid.txt
|----|----search.py
|----config.py
|----vedro.cfg.py
Running tests
To run the tests, need two hosts to send requests to them. You need to set environment variables in any convenient way:
GOLDEN_API_URL=http://master.app
TESTING_API_URL=http://branch.app
After that, you can run the tests:
$ vedro run -vvv
Setting up scenario
Sometimes there may be fields or headers in the API response that have a random value or that will differ from the value from the response from the test application. Such values will not allow testing, so they must be cut from the comparison of the two answers.
# helpers/helpers.py:
def prepare_byid(response) -> Response: # Generated method for scenario byid.py
exclude_headers = ['date'] # Date header exclusion
exclude_body = ['meta.api_version'] # Excluding a field from the body
return filter_response(JsonResponse(response), exclude_headers, exclude_body)
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 vedro-replay-0.1.3.tar.gz
.
File metadata
- Download URL: vedro-replay-0.1.3.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f36c80f36201106f141c2ede22aad4da6392220841e7c788ab76d13dce60867 |
|
MD5 | 42abf13fe8188197acf6a5c7d560c066 |
|
BLAKE2b-256 | 4926f16f441e530fa1fc411bed45bc11ba62e317f13957b4114e925619673484 |
File details
Details for the file vedro_replay-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: vedro_replay-0.1.3-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e50338e06fdc56c8394e2370ff44f35147ee213b6e9688b2ffca978199ea21ee |
|
MD5 | 7817fe308e5682fdc3092ba2f775abf1 |
|
BLAKE2b-256 | a2e6c4b2932e1ae9551ebd22518015020632498c80767af64e8a38a0c4f86482 |