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
Release files for pyfir 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyfir-1.0.0.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyfir-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / pyfir-1.0.0.tar.gz
| Download URL | pyfir-1.0.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a3f3d7351a6cfb2d6634ac5e0eba008e203af6a0780849c21796a7db160cdc1
|
|
BLAKE2b-256 checksum How to use checksums |
2a62ce9f59916ffa8267437d4b81beea95405006f8aad553937007f1d9f5b450
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.12
|
Release files / pyfir-1.0.0-py3-none-any.whl
| Download URL | pyfir-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f723f6e0c24b6cd88bb198ab75df28ca32eb78f6fadf2cb92d3ec2369d0260eb
|
|
BLAKE2b-256 checksum How to use checksums |
f25dcf27eef86cc841c5d2a69fac675f359382feceffbef934d34bdec7b0fab0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.12
|