https://github.com/lorien/test_server
Server to test HTTP clients
https://github.com/lorien/test_server
http-server mock-server test testing testing-tools
Last synced: 8 months ago
JSON representation
Server to test HTTP clients
- Host: GitHub
- URL: https://github.com/lorien/test_server
- Owner: lorien
- License: mit
- Created: 2015-02-17T08:40:25.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-03-16T21:16:06.000Z (almost 2 years ago)
- Last Synced: 2025-04-08T18:38:48.936Z (9 months ago)
- Topics: http-server, mock-server, test, testing, testing-tools
- Language: Python
- Size: 287 KB
- Stars: 4
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Documentation for test_server package
[](https://github.com/lorien/test_server/actions/workflows/test.yml)
[](https://github.com/lorien/test_server/actions/workflows/test.yml)
[](https://github.com/lorien/test_server/actions/workflows/mypy.yml)
[](https://coveralls.io/github/lorien/test_server)
[](http://user-agent.readthedocs.org)
Simple HTTP Server for testing HTTP clients.
## Installation
Run `pip install -U test_server`
## Usage Example
```python
from unittest import TestCase
import unittest
from urllib.request import urlopen
from test_server import TestServer, Response, HttpHeaderStorage
class UrllibTestCase(TestCase):
@classmethod
def setUpClass(cls):
cls.server = TestServer()
cls.server.start()
@classmethod
def tearDownClass(cls):
cls.server.stop()
def setUp(self):
self.server.reset()
def test_get(self):
self.server.add_response(
Response(
data=b"hello",
headers={"foo": "bar"},
)
)
self.server.add_response(Response(data=b"zzz"))
url = self.server.get_url()
info = urlopen(url)
self.assertEqual(b"hello", info.read())
self.assertEqual("bar", info.headers["foo"])
info = urlopen(url)
self.assertEqual(b"zzz", info.read())
self.assertTrue("bar" not in info.headers)
unittest.main()
```