Server for testing HTTP clients
Project description
Documentation for test_server package
Simple HTTP Server for testing HTTP clients.
Installation
Run pip install -U test_server
Usage Example
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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
test_server-0.0.42.tar.gz
(9.8 kB
view details)
File details
Details for the file test_server-0.0.42.tar.gz
.
File metadata
- Download URL: test_server-0.0.42.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62ab06174e94f133d644dce4de7e2bc53c46a39ed8a554e1b7abc04ee1baa96c |
|
MD5 | 8b2b76d9d4f19049e79e35f03661e20a |
|
BLAKE2b-256 | 23ddd8e2f93c19d18351235f9540ec7d8eec7559c0160db8c8007c01595dc90e |