Server for testing HTTP clients
Project description
Documentation for test_server package
Simple HTTP Server for testing HTTP clients.
Community
You are welcome to join Telegram chat groups to talk about web scraping and data processing: @grablab (English), @grablab_ru (Russian).
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.1.0.tar.gz
(17.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file test_server-0.1.0.tar.gz.
File metadata
- Download URL: test_server-0.1.0.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b037fb0ceb7956ce287ddfbe6a42ee35c19a581d510806842ff003110f17330
|
|
| MD5 |
68e7dbf03cf3cc05c8af55bb521bd6b7
|
|
| BLAKE2b-256 |
5c7e1c6948cfa2c81b6b20477f6993f548c885b6f0d3777f4457a3f8f7ceffc4
|
File details
Details for the file test_server-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: test_server-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbc9f0e56dc44bba145a68e4b0bba032216fc86b4271c1d1f3a019e938b9b067
|
|
| MD5 |
62295807e8d90326fac50a1564cda68f
|
|
| BLAKE2b-256 |
f6da460c57a7db4a83f63b28218f19db76d17088b70993234a7c0695db0f8f5c
|