Add unit tests to your http clients
Project description
HTTP testing inspired by golang’s httptest package.
Usage
import unittest
import urllib.request
import httptest
class TestHTTPServer(httptest.Handler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write(bytes("what up", "utf-8"))
class TestHTTPTestMethods(unittest.TestCase):
@httptest.Server(TestHTTPServer)
def test_call_response(self, ts=httptest.NoServer()):
with urllib.request.urlopen(ts.url()) as f:
self.assertEqual(f.read().decode('utf-8'), "what up")
if __name__ == '__main__':
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
httptest-0.0.13.tar.gz
(6.3 kB
view details)
File details
Details for the file httptest-0.0.13.tar.gz
.
File metadata
- Download URL: httptest-0.0.13.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94b837d6e2e6fc317196182054167b006fbf0e96722dc17f63dcca41af5870f0 |
|
MD5 | eb3f093a38e912ff5f17ca5e852870eb |
|
BLAKE2b-256 | 92000afe1f4393af27f34434892f8a8eacac978771122cac549fa06e805eed5f |