test-server


Nametest-server JSON
Version 0.0.43 PyPI version JSON
download
home_page
SummaryServer for testing HTTP clients
upload_time2023-08-01 07:44:34
maintainer
docs_urlNone
author
requires_python>=3.8
licenseThe MIT License (MIT) Copyright (c) 2015-2023, Gregory Petukhov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords test testing server http server
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Documentation for test_server package

[![Test Status](https://github.com/lorien/test_server/actions/workflows/test.yml/badge.svg)](https://github.com/lorien/test_server/actions/workflows/test.yml)
[![Code Quality](https://github.com/lorien/test_server/actions/workflows/check.yml/badge.svg)](https://github.com/lorien/test_server/actions/workflows/test.yml)
[![Type Check](https://github.com/lorien/test_server/actions/workflows/mypy.yml/badge.svg)](https://github.com/lorien/test_server/actions/workflows/mypy.yml)
[![Test Coverage Status](https://coveralls.io/repos/github/lorien/test_server/badge.svg)](https://coveralls.io/github/lorien/test_server)
[![Documentation Status](https://readthedocs.org/projects/test_server/badge/?version=latest)](http://user-agent.readthedocs.org)

Simple HTTP Server for testing HTTP clients.


## Installation

Run `pip install -U test_server`


## Usage Example

```python
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()
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "test-server",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "test,testing,server,http server",
    "author": "",
    "author_email": "Gregory Petukhov <lorien@lorien.name>",
    "download_url": "https://files.pythonhosted.org/packages/76/bf/c9574465f11296c89be174cc0ad485925c60401ebea901115d3c3581dc96/test_server-0.0.43.tar.gz",
    "platform": null,
    "description": "# Documentation for test_server package\n\n[![Test Status](https://github.com/lorien/test_server/actions/workflows/test.yml/badge.svg)](https://github.com/lorien/test_server/actions/workflows/test.yml)\n[![Code Quality](https://github.com/lorien/test_server/actions/workflows/check.yml/badge.svg)](https://github.com/lorien/test_server/actions/workflows/test.yml)\n[![Type Check](https://github.com/lorien/test_server/actions/workflows/mypy.yml/badge.svg)](https://github.com/lorien/test_server/actions/workflows/mypy.yml)\n[![Test Coverage Status](https://coveralls.io/repos/github/lorien/test_server/badge.svg)](https://coveralls.io/github/lorien/test_server)\n[![Documentation Status](https://readthedocs.org/projects/test_server/badge/?version=latest)](http://user-agent.readthedocs.org)\n\nSimple HTTP Server for testing HTTP clients.\n\n\n## Installation\n\nRun `pip install -U test_server`\n\n\n## Usage Example\n\n```python\nfrom unittest import TestCase\nimport unittest\nfrom urllib.request import urlopen\n\nfrom test_server import TestServer, Response, HttpHeaderStorage\n\n\nclass UrllibTestCase(TestCase):\n   @classmethod\n   def setUpClass(cls):\n       cls.server = TestServer()\n       cls.server.start()\n\n   @classmethod\n   def tearDownClass(cls):\n       cls.server.stop()\n\n   def setUp(self):\n       self.server.reset()\n\n   def test_get(self):\n       self.server.add_response(\n           Response(\n               data=b\"hello\",\n               headers={\"foo\": \"bar\"},\n           )\n       )\n       self.server.add_response(Response(data=b\"zzz\"))\n       url = self.server.get_url()\n       info = urlopen(url)\n       self.assertEqual(b\"hello\", info.read())\n       self.assertEqual(\"bar\", info.headers[\"foo\"])\n       info = urlopen(url)\n       self.assertEqual(b\"zzz\", info.read())\n       self.assertTrue(\"bar\" not in info.headers)\n\n\n   unittest.main()\n```\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2015-2023, Gregory Petukhov  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Server for testing HTTP clients",
    "version": "0.0.43",
    "project_urls": {
        "homepage": "http://github.com/lorien/test_server"
    },
    "split_keywords": [
        "test",
        "testing",
        "server",
        "http server"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "76bfc9574465f11296c89be174cc0ad485925c60401ebea901115d3c3581dc96",
                "md5": "d366f8975b3fcde0a577e6821a42fb2e",
                "sha256": "49adbdd8d1153129c8e6300380df0f6232ade6ab4caa30016b3c3d17996e1850"
            },
            "downloads": -1,
            "filename": "test_server-0.0.43.tar.gz",
            "has_sig": false,
            "md5_digest": "d366f8975b3fcde0a577e6821a42fb2e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 13513,
            "upload_time": "2023-08-01T07:44:34",
            "upload_time_iso_8601": "2023-08-01T07:44:34.711927Z",
            "url": "https://files.pythonhosted.org/packages/76/bf/c9574465f11296c89be174cc0ad485925c60401ebea901115d3c3581dc96/test_server-0.0.43.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-01 07:44:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lorien",
    "github_project": "test_server",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "test-server"
}
        
Elapsed time: 0.75662s