Skip to main content

Server for testing HTTP clients

Project description

https://travis-ci.org/lorien/test_server.png?branch=master

Simple HTTP Server for testing HTTP clients.

Installation

pip install test_server

Usage Example

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

Uploaded Source

File details

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

File metadata

  • Download URL: test_server-0.0.37.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.26.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.3

File hashes

Hashes for test_server-0.0.37.tar.gz
Algorithm Hash digest
SHA256 094e439a4c813c39244be4bcbd973e8e1f1730ce4c5ff1829af3f6cf26112275
MD5 467c53627c2f9f39b07634d1a542a91c
BLAKE2b-256 bbe7cb21cdb3dd7fe64a13ba0f022d3a4b4fa38a3eae5339b9bb40d022a9c8de

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