Skip to main content

Server for testing HTTP clients

Project description

Documentation for test_server package

Test Status Code Quality Type Check Test Coverage Status Documentation Status

Simple HTTP Server for testing HTTP clients.

Installation

Run pip install -U test_server

Usage Example

from unittest import TestCase
import unittest
from urllib.request import urlopen

from test_server import TestServer, Response, HttpHeaderStorage


class UrllibTestCase(TestCase):
   @classmethod
   def setUpClass(cls):
       cls.server = TestServer()
       cls.server.start()

   @classmethod
   def tearDownClass(cls):
       cls.server.stop()

   def setUp(self):
       self.server.reset()

   def test_get(self):
       self.server.add_response(
           Response(
               data=b"hello",
               headers={"foo": "bar"},
           )
       )
       self.server.add_response(Response(data=b"zzz"))
       url = self.server.get_url()
       info = urlopen(url)
       self.assertEqual(b"hello", info.read())
       self.assertEqual("bar", info.headers["foo"])
       info = urlopen(url)
       self.assertEqual(b"zzz", info.read())
       self.assertTrue("bar" not in info.headers)


   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

test_server-0.0.43.tar.gz (13.5 kB view details)

Uploaded Source

File details

Details for the file test_server-0.0.43.tar.gz.

File metadata

  • Download URL: test_server-0.0.43.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for test_server-0.0.43.tar.gz
Algorithm Hash digest
SHA256 49adbdd8d1153129c8e6300380df0f6232ade6ab4caa30016b3c3d17996e1850
MD5 d366f8975b3fcde0a577e6821a42fb2e
BLAKE2b-256 76bfc9574465f11296c89be174cc0ad485925c60401ebea901115d3c3581dc96

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