Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/osantana/wsgitest
Standalone WSGI server for running tests purpose.
https://github.com/osantana/wsgitest
Last synced: 23 days ago
JSON representation
Standalone WSGI server for running tests purpose.
- Host: GitHub
- URL: https://github.com/osantana/wsgitest
- Owner: osantana
- License: mit
- Created: 2015-05-28T19:05:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-05-28T20:03:35.000Z (over 9 years ago)
- Last Synced: 2024-10-09T18:14:51.092Z (25 days ago)
- Language: Python
- Homepage: https://pypi.python.org/pypi/wsgitest
- Size: 121 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.txt
- License: LICENSE.txt
Awesome Lists containing this project
- starred-awesome - wsgitest - Standalone WSGI server for running tests purpose. (Python)
README
wsgitest
========|Build Status| |Coverage Status|
You can use `wsgitest` to start a HTTP server for a WSGI application and
control the process:.. code-block:: python
@Request.application
def application(request):
return Response('Hello World!')class AppServerTestCase(TestCase):
def test_hello_app(self):
server = WSGITestServer.create(application)
try:
response = requests.get(server.application_url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b"Hello World!")
finally:
server.terminate()def test_hello_app_reference(self):
server = WSGITestServer.create("tests.test_server.application")
try:
response = requests.get(server.application_url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b"Hello World!")
finally:
server.terminate()The method `WSGITestServer.create()` initialize a `multiprocessing.Process`_
and wait for the server startup.You can use server as a context manager to avoid that tests get stucked when
you forget to "terminate" server:.. code-block:: python
@Request.application
def application(request):
return Response('Hello World!')class AppServerTestCase(TestCase):
def test_hello_app(self):
with WSGITestServer(application) as server:
response = requests.get(server.application_url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b"Hello World!")You can also start server with an specific host/ip or TCP port:
.. code-block:: python
@Request.application
def application(request):
return Response('Hello World!')class AppServerTestCase(TestCase):
def test_hello_app(self):
with WSGITestServer(application, "0.0.0.0", 5000) as server:
response = requests.get(server.application_url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b"Hello World!").. _multiprocessing.Process: https://docs.python.org/3/library/multiprocessing.html#the-process-class
.. |Build Status| image:: https://travis-ci.org/osantana/wsgitest.png?branch=master
:target: https://travis-ci.org/osantana/wsgitest
.. |Coverage Status| image:: https://coveralls.io/repos/osantana/wsgitest/badge.svg?branch=master
:target: https://coveralls.io/r/osantana/wsgitest?branch=master