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.

Community

You are welcome to join Telegram chat groups to talk about web scraping and data processing: @grablab (English), @grablab_ru (Russian).

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

test_server-0.1.0-py2.py3-none-any.whl (12.8 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: test_server-0.1.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for test_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8b037fb0ceb7956ce287ddfbe6a42ee35c19a581d510806842ff003110f17330
MD5 68e7dbf03cf3cc05c8af55bb521bd6b7
BLAKE2b-256 5c7e1c6948cfa2c81b6b20477f6993f548c885b6f0d3777f4457a3f8f7ceffc4

See more details on using hashes here.

File details

Details for the file test_server-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: test_server-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for test_server-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dbc9f0e56dc44bba145a68e4b0bba032216fc86b4271c1d1f3a019e938b9b067
MD5 62295807e8d90326fac50a1564cda68f
BLAKE2b-256 f6da460c57a7db4a83f63b28218f19db76d17088b70993234a7c0695db0f8f5c

See more details on using hashes here.

Supported by

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