Skip to main content

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


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.12.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file httptest-0.0.12.tar.gz.

File metadata

  • Download URL: httptest-0.0.12.tar.gz
  • Upload date:
  • Size: 5.9 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

Hashes for httptest-0.0.12.tar.gz
Algorithm Hash digest
SHA256 499d841fdb30abffe10b7381f2923fa17f26bb5172851900b0cae4428a5c6dbb
MD5 60c38e259b7545b24d7216b84f8e57e9
BLAKE2b-256 abc615dda9b9820b9f596b12e274f2fe1d0f8684b75dbadd0d4529de1b22e05f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page