Module to ease WSGI/ASGI App testing.
Project description
About
Provides utilities to convert WSGI environ/output to HTTP Request/Response. The main use case for this package is WSGI APP testing through its WSGI client. It provides a simple ASGI client to allow reuse test code when migrating from WSGI to ASGI.
Install
pip install pyfir
How to test your WSGI APP
Basic example
test_api.py
from fir.wsgi import WSGIClient
from fir.http import Request
from <package.module> import app # for example your Flask APP
# Create a WSGI Client
client = WSGIClient(app)
def test_api():
# Use the client to perform request to your APP
res = client.request(Request(
method="GET",
uri="/customers"
))
assert res.status_code == 200
assert res.get_json() == [{"name":"john", "surname": "doe"}]
Example of data driven tests
test_api.py
import unittest
from ddt import ddt, file_data
from fir.wsgi import WSGIClient
from fir.http import Request
from <package.module> import app # for example your Flask APP
# Create a WSGI Client
client = WSGIClient(app)
@ddt
class WSGITestCase(unittest.TestCase):
@file_data('data.yaml')
def test_api(self, request, response):
global client
res = client.request(Request(**request))
assert res.status_code == response.get("status")
if res.headers.get("content-type") == "application/json":
assert res.get_json() == response.get("json")
data.yaml
- request:
method: GET
uri: /customers
response:
status: 200
json:
- name: jhon
surname: doe
- request:
method: GET
uri: /customers/mark
response:
status: 404
Unit test
pip install -r test-requirements.txt
python -m pytest tests/ --cov=fir
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfir-1.0.0.tar.gz.
File metadata
- Download URL: pyfir-1.0.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a3f3d7351a6cfb2d6634ac5e0eba008e203af6a0780849c21796a7db160cdc1
|
|
| MD5 |
8601615851a7e9269d7cc72d3a1e5aba
|
|
| BLAKE2b-256 |
2a62ce9f59916ffa8267437d4b81beea95405006f8aad553937007f1d9f5b450
|
File details
Details for the file pyfir-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyfir-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f723f6e0c24b6cd88bb198ab75df28ca32eb78f6fadf2cb92d3ec2369d0260eb
|
|
| MD5 |
89afcbf16af6310e0ecdb8c911766d44
|
|
| BLAKE2b-256 |
f25dcf27eef86cc841c5d2a69fac675f359382feceffbef934d34bdec7b0fab0
|