{ "info": { "author": "\u0141ukasz Langa", "author_email": "lukasz@langa.pl", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "====================\nrequests-testadapter\n====================\n\n.. image:: https://secure.travis-ci.org/ambv/requests-testadapter.png\n :target: https://secure.travis-ci.org/ambv/requests-testadapter\n\nCurrently a very basic module that provides an adapter for `requests\n`_ that mocks network activity for unit\ntest purposes.\n\nHow to use\n----------\n\nThis code assumes your HTTP client is written in a way that enables passing\na custom `Session\n`_\nobject. When that's the case, all you have to do is to mount the adapter to\nanswer for a specific prefix::\n\n >>> import requests\n >>> from requests_testadapter import TestAdapter\n >>> s = requests.Session()\n >>> s.mount('http://', TestAdapter(b'Mock!', status=404))\n >>> r = s.get('http://mocked.com')\n >>> r.status_code\n 404\n >>> r.text\n 'Mock!'\n\nYou can also specify a ``headers`` dictionary as a keyword argument to\n``TestAdapter``.\n\nTestSession\n~~~~~~~~~~~\n\nIn ``requests`` 1.2.0 and older, the order of mounted adapters is\nunpredictable. To make sure you can mount arbitrary paths with their own\nrespective adapters, use ``TestSession`` which always matches the longest\nprefix::\n\n >>> from requests_testadapter import TestAdapter, TestSession\n >>> s = TestSession()\n >>> s.mount('http://git', TestAdapter(b'git'))\n >>> s.mount('http://github', TestAdapter(b'github'))\n >>> s.mount('http://github.com', TestAdapter(b'github.com'))\n >>> s.mount('http://github.com/about/', TestAdapter(b'github.com/about'))\n >>> r = s.get('http://github.com/about/')\n >>> r.text\n u'github.com/about'\n >>> r = s.get('http://github.com')\n >>> r.text\n u'github.com'\n >>> r = s.get('http://gittip.com')\n >>> r.text\n u'git'\n\n``TestSession`` doesn't connect the default handlers for HTTP and HTTPS so you\nwill be notified if your requests unintentionally try to reach external\nwebsites in your unit tests::\n\n >>> r = s.get('http://bitbucket.org')\n Traceback (most recent call last):\n ...\n requests.exceptions.InvalidSchema: No connection adapters were found for\n 'http://bitbucket.org/'\n\nHow do I run the tests?\n-----------------------\n\nThe easiest way would be to extract the source tarball and run::\n\n $ python test/test_testadapter.py\n\nIf you have all compatible Python implementations available on your system, you\ncan run tests on all of them by using tox::\n\n $ pip install tox\n $ tox\n GLOB sdist-make: setup.py\n py26 inst-nodeps: .tox/dist/requests-testadapter-0.1.0.zip\n py26 runtests: commands[0]\n ..\n ----------------------------------------------------------------------\n Ran 2 tests in 0.014s\n\n OK\n py27 inst-nodeps: .tox/dist/requests-testadapter-0.1.0.zip\n py27 runtests: commands[0]\n ..\n ----------------------------------------------------------------------\n Ran 2 tests in 0.014s\n\n OK\n py32 inst-nodeps: .tox/dist/requests-testadapter-0.1.0.zip\n py32 runtests: commands[0]\n ..\n ----------------------------------------------------------------------\n Ran 2 tests in 0.024s\n\n OK\n py33 inst-nodeps: .tox/dist/requests-testadapter-0.1.0.zip\n py33 runtests: commands[0]\n ..\n ----------------------------------------------------------------------\n Ran 2 tests in 0.017s\n\n OK\n _______________________________ summary ______________________________\n py26: commands succeeded\n py27: commands succeeded\n py32: commands succeeded\n py33: commands succeeded\n congratulations :)\n\nChange Log\n----------\n\n0.3.0\n~~~~~\n\n* fixed a compatibility problem with ``requests`` 1.2.1+\n\n0.2.0\n~~~~~\n\n* introduced ``TestSession`` to make adapter order predictable in ``requests``\n 1.2 and older\n\n* ``TestAdapter`` doesn't prefetch ``response.content`` anymore if\n ``stream=True`` is passed to a request. This lets the user read\n ``response.raw`` herself.\n\n0.1.0\n~~~~~\n\n* initial published version\n\nAuthors\n-------\n\nGlued together by `\u0141ukasz Langa `_. Additional fixes by\nLuke Sneeringer.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ambv/requests-testadapter", "keywords": "requests unit testing tests mock http", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "requests-testadapter", "package_url": "https://pypi.org/project/requests-testadapter/", "platform": "any", "project_url": "https://pypi.org/project/requests-testadapter/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/ambv/requests-testadapter" }, "release_url": "https://pypi.org/project/requests-testadapter/0.3.0/", "requires_dist": null, "requires_python": null, "summary": "Provides an adapter for mocking HTTP requests for unit test purposes.", "version": "0.3.0" }, "last_serial": 807442, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "f4120c871a63204e172c5f1c504b1d0d", "sha256": "0e3296863e3ab13cf786cd7c92840c08762bf8608740b86dac049989deb61efc" }, "downloads": -1, "filename": "requests-testadapter-0.1.0.tar.gz", "has_sig": false, "md5_digest": "f4120c871a63204e172c5f1c504b1d0d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3811, "upload_time": "2013-04-23T20:19:25", "url": "https://files.pythonhosted.org/packages/47/fb/e6b487974a71f5026c16d87fc38474372ac37b14b1ad2c0e00ba70002949/requests-testadapter-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "3dbe313337c2016c7155411fd7bc01ac", "sha256": "4b5a24c72c7b367df540d24088e1d12803baf1490d1eb649d69abdb6a7e6baad" }, "downloads": -1, "filename": "requests-testadapter-0.2.0.tar.gz", "has_sig": false, "md5_digest": "3dbe313337c2016c7155411fd7bc01ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5294, "upload_time": "2013-05-01T20:03:53", "url": "https://files.pythonhosted.org/packages/5e/12/b5c51d26e063b0692db7dd731c2ecce5058c0adf464bb29cdd4240993a31/requests-testadapter-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "6e5725a798aff4a22894dea4a0854264", "sha256": "0a9f824acc995753ca6f2e306fbbdb16015c8c44c1d14c9060717e32b99318b0" }, "downloads": -1, "filename": "requests-testadapter-0.3.0.tar.gz", "has_sig": false, "md5_digest": "6e5725a798aff4a22894dea4a0854264", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5383, "upload_time": "2013-07-03T19:22:35", "url": "https://files.pythonhosted.org/packages/7f/83/bf096ac4dbbbdce38685bc8796147bfa371e29ee8a64860201db29668910/requests-testadapter-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6e5725a798aff4a22894dea4a0854264", "sha256": "0a9f824acc995753ca6f2e306fbbdb16015c8c44c1d14c9060717e32b99318b0" }, "downloads": -1, "filename": "requests-testadapter-0.3.0.tar.gz", "has_sig": false, "md5_digest": "6e5725a798aff4a22894dea4a0854264", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5383, "upload_time": "2013-07-03T19:22:35", "url": "https://files.pythonhosted.org/packages/7f/83/bf096ac4dbbbdce38685bc8796147bfa371e29ee8a64860201db29668910/requests-testadapter-0.3.0.tar.gz" } ] }