Skip to main content

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.6.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

pyfir-0.0.6-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file pyfir-0.0.6.tar.gz.

File metadata

  • Download URL: pyfir-0.0.6.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pyfir-0.0.6.tar.gz
Algorithm Hash digest
SHA256 1b95f59a714aa50539472ba3845b0a0586a665d805f35798e4b372a0d37c51ee
MD5 5f720f0be588ac5c7763bf9fc970031a
BLAKE2b-256 a2b3910fdce64c55379bbe9bb5fd32cedfb5a1aca9f9cc98dbefd2931bbaf87d

See more details on using hashes here.

File details

Details for the file pyfir-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: pyfir-0.0.6-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.6

File hashes

Hashes for pyfir-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dd559d8d452edfebe8b2a1a765250abe894b73fb731eab15c7fdddc9f202fc9e
MD5 f025f9c1f335a95a5df654072ceb1edb
BLAKE2b-256 ea5b876a612795c560fa834a737b7e60f5d530c2417f5a0646675d9027b44ed4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page