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

Uploaded Source

File details

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

File metadata

  • Download URL: httptest-0.0.6.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for httptest-0.0.6.tar.gz
Algorithm Hash digest
SHA256 5926df5eb19e21bdc4643e54c4e7ca224e0f16d463ec399ed724c5e940ebcf64
MD5 e7562b61d034e572a75e151ba6c64c3b
BLAKE2b-256 d8d08c22c0b00baa75158113e48eef5d09babec5780819fec8476e1845eeb37e

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