{ "info": { "author": "Sebastian Rahlf", "author_email": "basti@redtoad.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Testing" ], "description": "==================\npytest-localserver\n==================\n\npytest-localserver is a plugin for the `pytest`_ testing framework which enables\nyou to test server connections locally.\n\nSometimes `monkeypatching`_ ``urllib2.urlopen()`` just does not cut it, for\ninstance if you work with ``urllib2.Request``, define your own openers/handlers\nor work with ``httplib``. In these cases it may come in handy to have an HTTP\nserver running locally which behaves just like the real thing [1]_. Well, look\nno further!\n\nQuickstart\n==========\n\nLet's say you have a function to scrape HTML which only required to be pointed\nat a URL ::\n\n import requests\n def scrape(url):\n html = requests.get(url).text\n # some parsing happens here\n # ...\n return result\n\nYou want to test this function in its entirety without having to rely on a\nremote server whose content you cannot control, neither do you want to waste\ntime setting up a complex mechanism to mock or patch the underlying Python\nmodules dealing with the actual HTTP request (of which there are more than one\nBTW). So what do you do?\n\nYou simply use pytest's `funcargs feature`_ and simulate an entire server\nlocally! ::\n\n def test_retrieve_some_content(httpserver):\n httpserver.serve_content(open('cached-content.html').read())\n assert scrape(httpserver.url) == 'Found it!'\n\nWhat happened here is that for the duration of your tests an HTTP server is\nstarted on a random port on localhost which will serve the content you tell it\nto and behaves just like the real thing.\n\nThe added bonus is that you can test whether your code behaves gracefully if\nthere is a network problem::\n\n def test_content_retrieval_fails_graciously(httpserver):\n httpserver.serve_content('File not found!', 404)\n pytest.raises(ContentNotFoundException, scrape, httpserver.url)\n\nThe same thing works for SMTP servers, too::\n\n def test_sending_some_message(smtpserver):\n mailer = MyMailer(host=smtpserver.addr[0], port=smtpserver.addr[1])\n mailer.send(to='bob@example.com', from_='alice@example.com',\n subject='MyMailer v1.0', body='Check out my mailer!')\n assert len(smtpserver.outbox)==1\n\nHere an SMTP server is started which accepts e-mails being sent to it. The\nnice feature here is that you can actually check if the message was received\nand what was sent by looking into the smtpserver's ``outbox``.\n\nIt is really that easy!\n\nAvailable funcargs\n==================\n\nHere is a short overview of the available funcargs. For more details I suggest\npoking around in the code itself.\n\n``httpserver``\n provides a threaded HTTP server instance running on localhost. It has the\n following attributes:\n\n * ``code`` - HTTP response code (int)\n * ``content`` - content of next response (str)\n * ``headers`` - response headers (dict)\n\n Once these attribute are set, all subsequent requests will be answered with\n these values until they are changed or the server is stopped. A more \n convenient way to change these is ::\n\n httpserver.serve_content(content=None, code=200, headers=None) \n\n The server address can be found in property\n\n * ``url``\n\n which is the string representation of tuple ``server_address`` (host as str,\n port as int).\n\n If you want to check which form fields have been POSTed, Try ::\n\n httpserver.serve_content(..., show_post_vars=True)\n\n which will display them as parsable text.\n\n If you need to inspect the requests sent to the server, a list of all\n received requests can be found in property\n\n * ``requests``\n\n which is a list of ``werkzeug.wrappers.Request`` objects.\n\n``httpsserver``\n is the same as ``httpserver`` only with SSL encryption.\n\n``smtpserver``\n provides a threaded instance of ``smtpd.SMTPServer`` runnning on localhost.\n It has the following attributes:\n\n * ``addr`` - server address as tuple (host as str, port as int)\n * ``outbox`` - list of ``email.message.Message`` instances received.\n\nUsing your a WSGI application as test server\n============================================\n\nAs of version 0.3 you can now use a `WSGI application`_ to run on the test\nserver ::\n\n from pytest_localserver.http import WSGIServer\n\n def simple_app(environ, start_response):\n \"\"\"Simplest possible WSGI application\"\"\"\n status = '200 OK'\n response_headers = [('Content-type', 'text/plain')]\n start_response(status, response_headers)\n return ['Hello world!\\n']\n\n @pytest.fixture\n def testserver(request):\n \"\"\"Defines the testserver funcarg\"\"\"\n server = WSGIServer(application=simple_app)\n server.start()\n request.addfinalizer(server.stop)\n return server\n\n def test_retrieve_some_content(testserver):\n assert scrape(testserver.url) == 'Hello world!\\n'\n\nHave a look at the following page for more information on WSGI:\nhttp://wsgi.readthedocs.org/en/latest/learn.html\n\nDownload and Installation\n=========================\n\nYou can install the plugin by running ::\n\n pip install pytest-localserver\n\nAlternatively, get the latest stable version from `PyPI`_ or the latest\n`bleeding-edge archive`_ from bitbucket.org.\n\nLicense and Credits\n===================\n\nThis plugin is released under the MIT license. You can find the full text of\nthe license in the LICENSE file.\n\nCopyright (C) 2010-2013 Sebastian Rahlf and others (see AUTHORS).\n\nSome parts of this package is based on ideas or code from other people:\n\n- I borrowed some implementation ideas for the httpserver from `linkchecker`_.\n- The implementation for the SMTP server is based on the `Mailsink recipe`_ by \n Adam Feuer, Matt Branthwaite and Troy Frever.\n- The HTTPS implementation is based on work by `Sebastien Martini`_.\n\nThanks guys!\n\nDevelopment and future plans\n============================\n\nFeel free to clone the repository and add your own changes. Pull requests are\nalways welcome!::\n\n hg clone https://bitbucket.org/pytest-dev/pytest-localserver\n\nIf you find any bugs, please file a `report`_.\n\nTest can be run with tox. Note that you need virtualenv<1.8 to run tests for\nPython 2.4.\n\nI already have a couple of ideas for future versions:\n\n* support for FTP, SSH (maybe base all on twisted?)\n* making the SMTP outbox as convenient to use as ``django.core.mail.outbox``\n* add your own here!\n\n----\n\n.. [1] The idea for this project was born when I needed to check that `a piece\n of software`_ behaved itself when receiving HTTP error codes 404 and 500.\n Having unsuccessfully tried to mock a server, I stumbled across \n `linkchecker`_ which uses a the same idea to test its internals.\n\n.. _monkeypatching: http://pytest.org/latest/monkeypatch.html\n.. _pytest: http://pytest.org/\n.. _funcargs feature: http://pytest.org/latest/funcargs.html\n.. _linkchecker: http://linkchecker.sourceforge.net/\n.. _WSGI application: http://www.python.org/dev/peps/pep-0333/\n.. _PyPI: http://pypi.python.org/pypi/pytest-localserver/\n.. _bleeding-edge archive: https://bitbucket.org/pytest-dev/pytest-localserver/get/tip.tar.gz\n.. _report: https://bitbucket.org/pytest-dev/pytest-localserver/issues/\n.. _tox: http://testrun.org/tox/\n.. _a piece of software: http://pypi.python.org/pypi/python-amazon-product-api/\n.. _Mailsink recipe: http://code.activestate.com/recipes/440690/\n.. _Sebastien Martini: http://code.activestate.com/recipes/442473/\n", "description_content_type": "", "docs_url": null, "download_url": "http://bitbucket.org/pytest-dev/pytest-localserver/downloads/", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://bitbucket.org/pytest-dev/pytest-localserver/", "keywords": "py.test pytest server localhost http smtp", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "pytest-localserver", "package_url": "https://pypi.org/project/pytest-localserver/", "platform": "", "project_url": "https://pypi.org/project/pytest-localserver/", "project_urls": { "Download": "http://bitbucket.org/pytest-dev/pytest-localserver/downloads/", "Homepage": "http://bitbucket.org/pytest-dev/pytest-localserver/" }, "release_url": "https://pypi.org/project/pytest-localserver/0.5.0/", "requires_dist": null, "requires_python": "", "summary": "py.test plugin to test server connections locally.", "version": "0.5.0" }, "last_serial": 4485168, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "00f30a550370176b8b124c180b260848", "sha256": "eaf8c3cd0ed8ae93f3c2fc05062a554ac83418154c7d904ac97a6f731ca6d1da" }, "downloads": -1, "filename": "pytest-localserver-0.1.tar.gz", "has_sig": false, "md5_digest": "00f30a550370176b8b124c180b260848", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7515, "upload_time": "2011-04-07T23:08:08", "url": "https://files.pythonhosted.org/packages/1c/d8/2f68d7a4b941fc4c9b84455a045522d598b9cdcbe03ddf76c26bae4f718b/pytest-localserver-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "9e06b0c8e0218aa95e652dfe43b722e5", "sha256": "ff61c4b91ef6c67a420759c86f35bb293e407990f7596f85bb86341e8a72fa7b" }, "downloads": -1, "filename": "pytest-localserver-0.1.1.tar.gz", "has_sig": false, "md5_digest": "9e06b0c8e0218aa95e652dfe43b722e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8403, "upload_time": "2011-04-15T18:57:13", "url": "https://files.pythonhosted.org/packages/cd/7e/c81fff57769127058bd5eb3285e0a1ce05cffba5c4ed4fc83ca4f331e354/pytest-localserver-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "2639787be09633468596c630531545ee", "sha256": "36f98b23c85b09f2c7843a7110fcf9976b0917d25b7002bc2eb8755abcc33888" }, "downloads": -1, "filename": "pytest-localserver-0.1.2.tar.gz", "has_sig": false, "md5_digest": "2639787be09633468596c630531545ee", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17026, "upload_time": "2011-05-07T19:04:58", "url": "https://files.pythonhosted.org/packages/9f/e9/1cf1031c2bdb5658b7d46ddd2f078d060c30afa44145beec8367f63484b4/pytest-localserver-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "5689ee69b0ff2073fdc81cabc946332e", "sha256": "acf69d4c1838128c9d8271eb603291e7bf1a9a6f99838a8c7eab5317bd16332f" }, "downloads": -1, "filename": "pytest-localserver-0.1.3.tar.gz", "has_sig": false, "md5_digest": "5689ee69b0ff2073fdc81cabc946332e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16554, "upload_time": "2011-05-22T08:23:02", "url": "https://files.pythonhosted.org/packages/cc/b0/33ebc1a6ec90d769be26b004575ee4916c9dda336ef05ca655817893f6f7/pytest-localserver-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "2783ddd15011945185fe4d1df356c3e5", "sha256": "de7e040203c9344e62bb4cdb92cc99790fd51a0e7a4f06334c259eb31189be70" }, "downloads": -1, "filename": "pytest-localserver-0.1.4.tar.gz", "has_sig": false, "md5_digest": "2783ddd15011945185fe4d1df356c3e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22722, "upload_time": "2011-08-21T17:14:32", "url": "https://files.pythonhosted.org/packages/ba/06/a36dca983d2503a9bc05a52828f5b100b1818be27119f69b15d80a4e6151/pytest-localserver-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "b504d512ab9f0e4e456fc2a2ebdb6b4b", "sha256": "85dbe5adadcb4f28ff5f71c1e0bb2f6a956db6ad6fbccd2a94caaa84f2797243" }, "downloads": -1, "filename": "pytest-localserver-0.1.5.tar.gz", "has_sig": false, "md5_digest": "b504d512ab9f0e4e456fc2a2ebdb6b4b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18459, "upload_time": "2013-03-21T22:13:32", "url": "https://files.pythonhosted.org/packages/15/55/2cb57bbb5121328291e22e3f09bb7383356b40b160b7825399186a52b7a7/pytest-localserver-0.1.5.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "2e6f126d7df266566f4fecc12d87d468", "sha256": "89cfc5e6122f777be5d7cf2ffd4cb17d7d0b051afa70eea15c3d139713d994ec" }, "downloads": -1, "filename": "pytest-localserver-0.3.tar.gz", "has_sig": false, "md5_digest": "2e6f126d7df266566f4fecc12d87d468", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19645, "upload_time": "2013-08-02T10:15:29", "url": "https://files.pythonhosted.org/packages/4f/91/642dcf4b073feeaa66f326094df0087ca42e1da6fd295ce89b5835cad446/pytest-localserver-0.3.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "d3bd2f0944f2e61d2b64449725403441", "sha256": "07bb195ae6c0f70a93fb711648d2d72c2aaf754b3b5abae83479bfdf8578ba5b" }, "downloads": -1, "filename": "pytest-localserver-0.3.2.tar.gz", "has_sig": false, "md5_digest": "d3bd2f0944f2e61d2b64449725403441", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21667, "upload_time": "2013-10-16T13:54:51", "url": "https://files.pythonhosted.org/packages/df/48/b8effee0f9741a9d6da79ad4be28aafce63c424240596d0169d83af5f6d8/pytest-localserver-0.3.2.tar.gz" } ], "0.3.3": [ { "comment_text": "", "digests": { "md5": "44507e8db3456bffbe9d645135facb58", "sha256": "107321dc6ba1a7d4b5118a4547ff28948d1ffe673b27c6992b4bc28b54acec95" }, "downloads": -1, "filename": "pytest-localserver-0.3.3.tar.gz", "has_sig": false, "md5_digest": "44507e8db3456bffbe9d645135facb58", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21733, "upload_time": "2014-08-31T09:31:04", "url": "https://files.pythonhosted.org/packages/4a/7c/1cebf008b60addef3c683c23564125c4a92dc89f12e7b04fd143cd5423d6/pytest-localserver-0.3.3.tar.gz" } ], "0.3.4": [ { "comment_text": "", "digests": { "md5": "f233e9701798e1d6430c4f8a67c8a8b3", "sha256": "9d2dc10aa2ba7e799f22e3fc133f7562c9be5be180b788f7f9dabea30a281814" }, "downloads": -1, "filename": "pytest-localserver-0.3.4.zip", "has_sig": false, "md5_digest": "f233e9701798e1d6430c4f8a67c8a8b3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 28988, "upload_time": "2015-02-01T16:40:38", "url": "https://files.pythonhosted.org/packages/3c/8b/aee5aa7724c50813ef187ebb555253b80b830ad1f22e5def58e7c758e89c/pytest-localserver-0.3.4.zip" } ], "0.3.5": [ { "comment_text": "", "digests": { "md5": "641c6c6cbdae58cbcc62a25e398d15e1", "sha256": "97a8db7f530afdd009513ebdd86731b51e866fad82595bf92f456d93e5d57837" }, "downloads": -1, "filename": "pytest-localserver-0.3.5.tar.gz", "has_sig": false, "md5_digest": "641c6c6cbdae58cbcc62a25e398d15e1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18856, "upload_time": "2016-01-16T20:11:30", "url": "https://files.pythonhosted.org/packages/b9/2e/218aefb0ec55230c363e5b0e62365da7591cc04ae7f8c37082011c1609a6/pytest-localserver-0.3.5.tar.gz" } ], "0.3.6": [ { "comment_text": "", "digests": { "md5": "4cc336c533d2d9094dec278040b7591c", "sha256": "fa4e29a5eaf912055955c924652061e6eac0c13747cd6af7b119ed989fbeb03c" }, "downloads": -1, "filename": "pytest-localserver-0.3.6.tar.gz", "has_sig": false, "md5_digest": "4cc336c533d2d9094dec278040b7591c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19701, "upload_time": "2016-08-27T07:52:31", "url": "https://files.pythonhosted.org/packages/06/42/cc9e9101ddfcf9eefcc6bd0f9624f1631f385745e1f39a24ecc69201403c/pytest-localserver-0.3.6.tar.gz" } ], "0.3.7": [ { "comment_text": "", "digests": { "md5": "348b4dce31d7126702811c44e165f989", "sha256": "d828d79232456d0b4eb863e9de2c85699259f436a3185e39d0d5001b8c8521b0" }, "downloads": -1, "filename": "pytest-localserver-0.3.7.tar.gz", "has_sig": false, "md5_digest": "348b4dce31d7126702811c44e165f989", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19772, "upload_time": "2017-04-03T09:53:11", "url": "https://files.pythonhosted.org/packages/41/d6/90242691486b2fc42cd2dd73023760a065263d5551ef34f8e209b6fa8576/pytest-localserver-0.3.7.tar.gz" } ], "0.4.0": [], "0.4.1": [ { "comment_text": "", "digests": { "md5": "89a67f13808296e0584caa2e868e7cef", "sha256": "a72af60a1ec8f73668a7884c86baf1fbe48394573cb4fa36709887217736c021" }, "downloads": -1, "filename": "pytest-localserver-0.4.1.tar.gz", "has_sig": false, "md5_digest": "89a67f13808296e0584caa2e868e7cef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19901, "upload_time": "2017-11-28T12:29:37", "url": "https://files.pythonhosted.org/packages/79/5b/3168f8d78ca61fc9f3cee7a97d45892205e211852cf950e8770bf6595899/pytest-localserver-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "d173509c708713a7000e5f48ebb37b9b", "sha256": "0615b1698bdd2a1e6e396caf2f496020f4f69bccc0518df5050aeb02800f7c07" }, "downloads": -1, "filename": "pytest-localserver-0.4.2.tar.gz", "has_sig": false, "md5_digest": "d173509c708713a7000e5f48ebb37b9b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20253, "upload_time": "2018-11-14T10:43:20", "url": "https://files.pythonhosted.org/packages/32/fa/b762fd925bc0448c3e19a6cfb27071193703ff79cbe2b32307ea37eb111b/pytest-localserver-0.4.2.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "431d31cef0ac481f49b3755a3db1996b", "sha256": "3a5427909d1dfda10772c1bae4b9803679c0a8f04adb66c338ac607773bfefc2" }, "downloads": -1, "filename": "pytest-localserver-0.5.0.tar.gz", "has_sig": false, "md5_digest": "431d31cef0ac481f49b3755a3db1996b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20409, "upload_time": "2018-11-14T10:57:46", "url": "https://files.pythonhosted.org/packages/6c/b3/db8f8700718fbefaa2e8b2ef690fec147e560ce92e2300cdb3ff462d313c/pytest-localserver-0.5.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "431d31cef0ac481f49b3755a3db1996b", "sha256": "3a5427909d1dfda10772c1bae4b9803679c0a8f04adb66c338ac607773bfefc2" }, "downloads": -1, "filename": "pytest-localserver-0.5.0.tar.gz", "has_sig": false, "md5_digest": "431d31cef0ac481f49b3755a3db1996b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20409, "upload_time": "2018-11-14T10:57:46", "url": "https://files.pythonhosted.org/packages/6c/b3/db8f8700718fbefaa2e8b2ef690fec147e560ce92e2300cdb3ff462d313c/pytest-localserver-0.5.0.tar.gz" } ] }