Module to ease WSGI 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.
Install
pip install pyfir
How to test your WSGI APP
Basic example
test_api.py
from fir.wsgi import Client
from fir.http import Request
from <package.module> import app # for example your Flask APP
# Create a WSGI Client
client = Client(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 Client
from fir.http import Request
from <package.module> import app # for example your Flask APP
# Create a WSGI Client
client = Client(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
pyfir-0.0.7.tar.gz
(4.7 kB
view details)
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
pyfir-0.0.7-py3-none-any.whl
(5.2 kB
view details)
File details
Details for the file pyfir-0.0.7.tar.gz.
File metadata
- Download URL: pyfir-0.0.7.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2133eb51d214926a6a9453ac5e52455b1b28f2e892e8af66ae877e98ae6ad79
|
|
| MD5 |
4218d74cad729f91c46430a0887b78ad
|
|
| BLAKE2b-256 |
1c5dbc42b61228550d81293c1b6507da3562c949edca91cc48e576bca1d61076
|
File details
Details for the file pyfir-0.0.7-py3-none-any.whl.
File metadata
- Download URL: pyfir-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8ea93de2419ce216dadaf3c6f444aba673aba36d32baa33e2314d2705f62da6
|
|
| MD5 |
d267996c1adc282be6b5ca59f85d57d7
|
|
| BLAKE2b-256 |
da2165fe87545778d386aa6f96004e5c7215ab342433a894787b599856eee9b7
|