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.8.tar.gz
(5.6 kB
view details)
File details
Details for the file httptest-0.0.8.tar.gz
.
File metadata
- Download URL: httptest-0.0.8.tar.gz
- Upload date:
- Size: 5.6 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.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d61eae6fbaa9484a5fb54c66ac56d3d1d1e83c18b5b1e69d6d76807cb7ab126a |
|
MD5 | 8dd6f8b69d2671c1d7115b6ea39bb45a |
|
BLAKE2b-256 | b0da8837029368d30f24763108e2df0ea4b78b88b4c5734c01f4d1a553ad11a0 |