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.5.tar.gz
(4.2 kB
view details)
File details
Details for the file httptest-0.0.5.tar.gz
.
File metadata
- Download URL: httptest-0.0.5.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cc981cd917818a7ab6d89525178ad38f4011bda45caba7f115db666a032e2c7 |
|
MD5 | 0a9f34fd5d4b3deb3d5096e01c9ed261 |
|
BLAKE2b-256 | 608aa5eecb7ba1d4664bfc66ab34b30dbdfae5e268d2b245ced1ade8dd67cf7b |