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

Uploaded Source

File details

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

File metadata

  • Download URL: httptest-0.0.10.tar.gz
  • Upload date:
  • Size: 5.8 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.10.tar.gz
Algorithm Hash digest
SHA256 ff91d4aeb4f29c739201a27119936325504bb2b2b3d6f9af503d737c1fc854bf
MD5 5ae266d347248200675ccda0dd8209b4
BLAKE2b-256 5fa9747ed0a6b3cd5a53cbf473334eb2bc732933ca0d11b3bd7ee04b1a153721

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