Server for testing HTTP clients
Project description
Simple HTTP Server for testing HTTP clients.
Installation
pip install test-server
Usage Example
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.34.tar.gz
(11.8 kB
view details)
File details
Details for the file test-server-0.0.34.tar.gz
.
File metadata
- Download URL: test-server-0.0.34.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.26.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd33d63102d81c85aa2c54d571bd0ffff612f0086c072193392274f2e95278da |
|
MD5 | e4a94fd8ab5c781d9a5f6c67c1e29846 |
|
BLAKE2b-256 | d5f5caad241bd681b19c89322c62cce3f19e87166157898fd06e1716b2294837 |