pyfir


Namepyfir JSON
Version 0.0.6 PyPI version JSON
download
home_pagehttps://github.com/Claudjos/fir
SummaryModule to ease WSGI App testing.
upload_time2023-07-27 15:18:39
maintainer
docs_urlNone
authorClaudjos
requires_python
license
keywords web app testing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Claudjos/fir",
    "name": "pyfir",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Web App,Testing",
    "author": "Claudjos",
    "author_email": "claudjosmail@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a2/b3/910fdce64c55379bbe9bb5fd32cedfb5a1aca9f9cc98dbefd2931bbaf87d/pyfir-0.0.6.tar.gz",
    "platform": null,
    "description": "# About\nProvides 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.\n\n## Install\n```\npip install pyfir\n```\n\n## How to test your WSGI APP\n\n#### Basic example\ntest_api.py\n```\nfrom fir.wsgi import Client\nfrom fir.http import Request\nfrom <package.module> import app # for example your Flask APP\n\n\n# Create a WSGI Client\nclient = Client(app)\n\n\ndef test_api():\n\t# Use the client to perform request to your APP\n\tres = client.request(Request(\n\t\tmethod=\"GET\",\n\t\turi=\"/customers\"\n\t))\n\tassert res.status_code == 200\n\tassert res.get_json() == [{\"name\":\"john\", \"surname\": \"doe\"}]\n\n```\n\n#### Example of data driven tests\ntest_api.py\n```\nimport unittest\nfrom ddt import ddt, file_data\nfrom fir.wsgi import Client\nfrom fir.http import Request\nfrom <package.module> import app # for example your Flask APP\n\n\n# Create a WSGI Client\nclient = Client(app)\n\n\n@ddt\nclass WSGITestCase(unittest.TestCase):\n\n\t@file_data('data.yaml')\n\tdef test_api(self, request, response):\n\t\tglobal client\n\t\tres = client.request(Request(**request))\n\t\tassert res.status_code == response.get(\"status\")\n\t\tif res.headers.get(\"content-type\") == \"application/json\":\n\t\t\tassert res.get_json() == response.get(\"json\")\n\n```\ndata.yaml\n```\n- request:\n\tmethod: GET\n\turi: /customers\n  response:\n\tstatus: 200\n\tjson:\n\t- name: jhon\n\t  surname: doe\n\n- request:\n\tmethod: GET\n\turi: /customers/mark\n  response:\n\tstatus: 404\n```\n\n## Unit test\n```\npip install -r test-requirements.txt\npython -m pytest tests/ --cov=fir\n```\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Module to ease WSGI App testing.",
    "version": "0.0.6",
    "project_urls": {
        "Homepage": "https://github.com/Claudjos/fir"
    },
    "split_keywords": [
        "web app",
        "testing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ea5b876a612795c560fa834a737b7e60f5d530c2417f5a0646675d9027b44ed4",
                "md5": "f025f9c1f335a95a5df654072ceb1edb",
                "sha256": "dd559d8d452edfebe8b2a1a765250abe894b73fb731eab15c7fdddc9f202fc9e"
            },
            "downloads": -1,
            "filename": "pyfir-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f025f9c1f335a95a5df654072ceb1edb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5169,
            "upload_time": "2023-07-27T15:18:38",
            "upload_time_iso_8601": "2023-07-27T15:18:38.220783Z",
            "url": "https://files.pythonhosted.org/packages/ea/5b/876a612795c560fa834a737b7e60f5d530c2417f5a0646675d9027b44ed4/pyfir-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a2b3910fdce64c55379bbe9bb5fd32cedfb5a1aca9f9cc98dbefd2931bbaf87d",
                "md5": "5f720f0be588ac5c7763bf9fc970031a",
                "sha256": "1b95f59a714aa50539472ba3845b0a0586a665d805f35798e4b372a0d37c51ee"
            },
            "downloads": -1,
            "filename": "pyfir-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "5f720f0be588ac5c7763bf9fc970031a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4624,
            "upload_time": "2023-07-27T15:18:39",
            "upload_time_iso_8601": "2023-07-27T15:18:39.240537Z",
            "url": "https://files.pythonhosted.org/packages/a2/b3/910fdce64c55379bbe9bb5fd32cedfb5a1aca9f9cc98dbefd2931bbaf87d/pyfir-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-27 15:18:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Claudjos",
    "github_project": "fir",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyfir"
}
        
Elapsed time: 0.09866s