{ "info": { "author": "Todd Wolfson", "author_email": "todd@twolfson.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: Public Domain", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "httpretty-fixtures\n==================\n\n.. image:: https://travis-ci.org/underdogio/httpretty-fixtures.png?branch=master\n :target: https://travis-ci.org/underdogio/httpretty-fixtures\n :alt: Build Status\n\nFixture manager for `httpretty`_\n\n**Features:**\n\n- Reuse responses across tests\n- Allows maintaining state between requests\n\n - See the `Examples section for a demonstration <#preserving-state-between-requests>`_\n\n- Access past request information\n\n - On per-fixture basis\n - Across all fixtures\n\nThis was written to solve communicating to an Elasticsearch during tests. For our usage, ``mock`` didn't scale well and placing `httpretty`_ fixtures on our base test case was impratical. To solve this, we wrote a fixture manager, ``httpretty-fixtures``.\n\n.. _`httpretty`: https://github.com/gabrielfalcao/HTTPretty\n\nGetting Started\n---------------\nInstall the module with: ``pip install httpretty_fixtures``\n\n.. code:: python\n\n # Load in our dependencies\n import json\n import unittest\n\n import httpretty_fixtures\n import requests\n\n\n # Set up our fixture manager\n class FakeElasticsearch(httpretty_fixtures.FixtureManager):\n @httpretty_fixtures.get('http://localhost:9200/my_index/my_document/my_id')\n def es_index(self, request, uri, res_headers):\n return (200, res_headers, json.dumps({\n '_index': 'my_index',\n '_type': 'my_document',\n '_id': 'my_id',\n '_version': 1,\n 'found': True,\n }))\n\n\n # Define our tests\n class MyTestCase(unittest.TestCase):\n @FakeElasticsearch.run(['es_index'])\n def test_retrieve_from_es(self, fake_elasticsearch):\n \"\"\"Verify we can retrieve an item from Elasticsearch\"\"\"\n # Make our request and verify we hit Elasticsearch\n res = requests.get('http://localhost:9200/my_index/my_document/my_id?first')\n self.assertEqual(res.status_code, 200)\n self.assertEqual(res.json()['_index'], 'my_index')\n\n # Make a second request for demonstration purposes\n requests.get('http://localhost:9200/my_index/my_document/my_id?second')\n\n # Introspect our request received on `FakeElasticsearch`\n fixture = fake_elasticsearch.es_index\n self.assertEqual(fixture.first_request.path, '/my_index/my_document/my_id?first')\n self.assertEqual(fixture.last_request.path, '/my_index/my_document/my_id?second')\n self.assertEqual(len(fixture.requests), 2)\n self.assertEqual(fixture.requests[0].path, '/my_index/my_document/my_id?first')\n self.assertEqual(fixture.requests[1].path, '/my_index/my_document/my_id?second')\n\n # Access request information from all `httpretty` requests\n self.assertEqual(httpretty_fixtures.first_request().path, '/my_index/my_document/my_id?first')\n self.assertEqual(httpretty_fixtures.last_request().path, '/my_index/my_document/my_id?second')\n self.assertEqual(len(httpretty_fixtures.requests()), 2)\n self.assertEqual(httpretty_fixtures.requests()[0].path, '/my_index/my_document/my_id?first')\n self.assertEqual(httpretty_fixtures.requests()[1].path, '/my_index/my_document/my_id?second')\n\nDocumentation\n-------------\n``httpretty-fixtures`` exports ``FixtureManager``, ``get``, ``put``, ``post``, ``delete``, ``head``, ``patch``, ``options``, ``connect``, ``first_request``, ``last_request``, and ``requests`` as methods/variables.\n\nWe will refer to the package as ``httpretty_fixtures``.\n\nFixtureManager()\n^^^^^^^^^^^^^^^^\nClass for setting up a set of fixtures on. This should be inherited from into another class with its own set of fixtures.\n\n.. code:: python\n\n class FakeElasticsearch(httpretty_fixtures.FixtureManager):\n @httpretty_fixtures.get('http://localhost:9200/my_index/my_document/my_id')\n def es_index(self, request, uri, res_headers):\n return (200, res_headers, json.dumps({'content': 'goes here'}))\n\n\nfixture_manager.run(fixtures)\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nDecorator to run a set of fixtures during a function\n\n- fixtures ``list`` - Names of fixture functions to run\n\n - \\* ``str`` - Name of fixtures function to run\n\nWe will pass in the server instance as an argument to the decorated function. From the server, we can `access per-instance fixture information and requests <#function-attributes>`_.\n\n.. code:: python\n\n class FakeElasticsearch(httpretty_fixtures.FixtureManager):\n @httpretty_fixtures.get('http://localhost:9200/my_index/my_document/my_id')\n def es_index(self, request, uri, res_headers):\n return (200, res_headers, json.dumps({}))\n\n class MyTestCase(unittest.TestCase):\n # The `es_index` fixture will be live for all of this test case\n @FakeElasticsearch.run(['es_index'])\n def test_retrieve_from_es(self, fake_elasticsearch):\n \"\"\"Verify we can retrieve an item from Elasticsearch\"\"\"\n # Make our request and verify we hit Elasticsearch\n res = requests.get('http://localhost:9200/my_index/my_document/my_id')\n\nfixture_manager.start(fixtures)\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nStart running HTTPretty with a set of fixtures\n\n- fixtures ``list`` - Names of fixture functions to run\n\n - \\* ``str`` - Name of fixtures function to run\n\n**Returns:**\n\n- Returns a running instance of ``fixture_manager``. This can be used to `access fixtures and their request information <#function-attributes>`_.\n\n``.start()`` will run HTTPretty indefinitely until ``.stop()`` is called.\n\nfixture_manager.stop()\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nStop a running instance of HTTPretty. This should always be run at some point after a ``.start()``\n\nhttpretty_fixtures.{verb}(\\*register_uri_args, \\*\\*register_uri_kwargs)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nDecorator to register a fixture function under an HTTP verb\n\nThis is a summary for all possible HTTP verbs:\n\n.. code:: python\n\n @httpretty_fixtures.get()\n @httpretty_fixtures.put()\n @httpretty_fixtures.post()\n @httpretty_fixtures.delete()\n @httpretty_fixtures.head()\n @httpretty_fixtures.patch()\n @httpretty_fixtures.options()\n @httpretty_fixtures.connect()\n\nEach of these verbs functions passes its arguments/keyword arguments to ``HTTPretty's register_uri` function``.\n\nIf there are any arguments you want to apply to your fixture with respect to ``HTTPretty``, this is how to do it.\n\nhttps://github.com/gabrielfalcao/HTTPretty/tree/0.8.3#usage\n\n.. code:: python\n\n @httpretty_fixtures.get(\"http://underdog.io/\")\n\nFunction signature\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n``httpretty_fixtures`` leverages the dynamic callback functionality of ``httpretty``:\n\nhttps://github.com/gabrielfalcao/HTTPretty/tree/0.8.3#dynamic-responses-through-callbacks\n\nAs a result, we expect our decorator to receive a function that matches the following signature:\n\n.. code:: python\n\n @httpretty_fixtures.get(\"http://underdog.io/\")\n def request_handler(self, request, uri, res_headers):\n res_tuple = (status_code, res_headers, body)\n return res_tuple\n\n # Example\n @httpretty_fixtures.get(\"http://underdog.io/\")\n def hello(self, request, uri, res_headers):\n return (200, res_headers, 'Hello World!')\n\nThe signature is as follows:\n\n- request_handler ``function`` - Handler for our request callback\n- self ``object`` - Instance of class extended on top of for ``FixtureManager``\n- uri ``object`` - Information about incoming request\n\n - Structure is managed by ``httpretty``\n - More info can be read from the source code\n\n - https://github.com/gabrielfalcao/HTTPretty/blob/0.8.3/httpretty/core.py#L615-L647\n\n- res_headers ``object`` - Default response headers to provide to request\n\n - These should be modified and/or passed through in the `res_tuple`\n\n- res_tuple ``tuple`` - Collection of information for our response\n\n - [0] ``int`` - Status code to provide for response\n\n - For example, 200 would be a 200 HTTP status code\n\n - [1] ``object`` - Modified or provided set of headers provided as a parameter\n - [2] ``str`` - Response body for our request\n\n - In the example above, we replied with ``'Hello World!'`` but this could be JSON, XML, or whatever you need\n\nFunction attributes\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n``httpretty_fixtures`` provides helper properties to access past request information. For the sake of reference, we will refer to a fixture as ``fixture``\n\n- ``fixture.first_request`` - Accesses first request received by fixture in our ``.run()`` current instance\n\n - If no request was received, then this will be ``None``\n\n- ``fixture.last_request`` - Accesses last request received by fixture in our ``.run()`` current instance\n\n - If no request was received, then this will be ``None``\n\n- ``fixture.requests`` - List of all requests received by our fixture\n\nA ``fixture`` should be accessible via the returned server from our ``.run()`` decorator or ``.start()``\n\n.. code:: python\n\n class MyTestCase(unittest.TestCase):\n # The `es_index` fixture will be live for all of this test case\n @FakeElasticsearch.run(['es_index'])\n def test_retrieve_from_es(self, fake_elasticsearch):\n # Access our `fixture` and its properties\n fake_elasticsearch.es_index\n fake_elasticsearch.es_index.first_request\n fake_elasticsearch.es_index.last_request\n fake_elasticsearch.es_index.requests\n\nhttpretty_fixtures.first_request()\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nAlias to access the first request received by ``HTTPretty``.\n\n**Warning:** If you are using ``HTTPretty`` in other locations, then this will register those requests as well.\n\nhttpretty_fixtures.last_request()\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nAlias to access the last request received by ``HTTPretty``.\n\n**Warning:** If you are using ``HTTPretty`` in other locations, then this will register those requests as well.\n\nhttpretty_fixtures.requests()\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nAlias to access all requests received by ``HTTPretty``.\n\n**Warning:** If you are using ``HTTPretty`` in other locations, then this will register those requests as well.\n\nExamples\n--------\nPreserving state between requests\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nIn this example, we will count between multiple requests to indicate that state is being preserved.\n\n.. code:: python\n\n # Load in our dependencies\n import unittest\n\n import httpretty_fixtures\n import requests\n\n\n # Set up our fixture manager\n class CounterServer(httpretty_fixtures.FixtureManager):\n def __init__(self):\n self.count = 0\n super(CounterServer, self).__init__()\n\n @httpretty_fixtures.get('http://localhost:9000/')\n def counter(self, request, uri, res_headers):\n self.count += 1\n return (200, res_headers, str(self.count))\n\n\n # Define our tests\n class MyTestCase(unittest.TestCase):\n @CounterServer.run(['counter'])\n def test_counter_state(self, counter_server):\n \"\"\"Verify we can preserve state between requests\"\"\"\n # Make our first request and verify its count\n res = requests.get('http://localhost:9000/')\n self.assertEqual(res.status_code, 200)\n self.assertEqual(res.text, '1')\n\n # Make our second request and verify its count\n res = requests.get('http://localhost:9000/')\n self.assertEqual(res.status_code, 200)\n self.assertEqual(res.text, '2')\n\n @CounterServer.run(['counter'])\n def test_counter_alternate_state(self, counter_server):\n \"\"\"Verify state is not maintained between separate `FixtureManager.run()'s`\"\"\"\n res = requests.get('http://localhost:9000/')\n self.assertEqual(res.status_code, 200)\n self.assertEqual(res.text, '1')\n\nContributing\n------------\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Test via ``nosetests``.\n\nLicense\n-------\nCopyright (c) 2015 Underdog.io\n\nLicensed under the MIT license.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/underdogio/httpretty-fixtures/archive/master.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/underdogio/httpretty-fixtures", "keywords": "httpretty,fixture,responses,mock", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "httpretty_fixtures", "package_url": "https://pypi.org/project/httpretty_fixtures/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/httpretty_fixtures/", "project_urls": { "Download": "https://github.com/underdogio/httpretty-fixtures/archive/master.zip", "Homepage": "https://github.com/underdogio/httpretty-fixtures" }, "release_url": "https://pypi.org/project/httpretty_fixtures/2.1.1/", "requires_dist": null, "requires_python": null, "summary": "Fixture manager for httpretty", "version": "2.1.1" }, "last_serial": 2278360, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "9677625203f41cacabd8e39c81f48ffb", "sha256": "13b2c7c0ce3493f926b5766bc941e807493d3d32214533d1312cacd5e4af3f61" }, "downloads": -1, "filename": "httpretty_fixtures-1.0.0.tar.gz", "has_sig": false, "md5_digest": "9677625203f41cacabd8e39c81f48ffb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13248, "upload_time": "2015-06-02T18:04:34", "url": "https://files.pythonhosted.org/packages/e1/61/517c360f6fadc159b61bc83772747d792709f450566aab077654e0b9aaf9/httpretty_fixtures-1.0.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "55068eca0d318c5c5be48ae21c1e86f4", "sha256": "8e44ea96f5918616ad26d16668076d4a147e09bedf0eb0224da66d7d7827de7f" }, "downloads": -1, "filename": "httpretty_fixtures-1.0.0.zip", "has_sig": false, "md5_digest": "55068eca0d318c5c5be48ae21c1e86f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20823, "upload_time": "2015-06-02T18:04:37", "url": "https://files.pythonhosted.org/packages/3e/e4/a888ce605c92fe486100dd0d7e277a198ccbe872983b18d03a1f4d4cd66e/httpretty_fixtures-1.0.0.zip" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "d7f1849f5afc23b7f198c04ac3ecfc6b", "sha256": "c23c82bfe0176d0c670fa9143b18cddbf6c89f332517beaf38210983ec370932" }, "downloads": -1, "filename": "httpretty_fixtures-1.0.1.tar.gz", "has_sig": false, "md5_digest": "d7f1849f5afc23b7f198c04ac3ecfc6b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13279, "upload_time": "2015-06-02T18:06:07", "url": "https://files.pythonhosted.org/packages/ab/89/b3dc1777af6d7f40a2373607683361b50911df84487053f663fc31c513c7/httpretty_fixtures-1.0.1.tar.gz" }, { "comment_text": "", "digests": { "md5": "82aa7da883e02a6f246e382b2d1155b1", "sha256": "df063c48768a1a0b5a7e31b1c278f77989a71c480ec9f45759388bf79e87d80e" }, "downloads": -1, "filename": "httpretty_fixtures-1.0.1.zip", "has_sig": false, "md5_digest": "82aa7da883e02a6f246e382b2d1155b1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20853, "upload_time": "2015-06-02T18:06:10", "url": "https://files.pythonhosted.org/packages/7d/6a/5a5df93bb7a6ef8303ca9118afed8b62dc316b36eaa0c03012afff7a738c/httpretty_fixtures-1.0.1.zip" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "f3ea71ab0b27c80ac87302e9bc6b3682", "sha256": "0aba528c467be1f1a0a9cfe67c9c3e513948e8b5cb1d9179be4fda6802cb31b2" }, "downloads": -1, "filename": "httpretty_fixtures-1.0.2.tar.gz", "has_sig": false, "md5_digest": "f3ea71ab0b27c80ac87302e9bc6b3682", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13297, "upload_time": "2015-06-02T18:11:46", "url": "https://files.pythonhosted.org/packages/14/36/45c5154d82c1ba4dd87e02f26fb65c3f50d30a5acaab957c971dffbd6d24/httpretty_fixtures-1.0.2.tar.gz" }, { "comment_text": "", "digests": { "md5": "33e24430411771178e5d2be94a6ee89c", "sha256": "28365ac81f4051d94d8796272b2002a8e4cb859688c0c87fdf7ff16a8a8bcdb2" }, "downloads": -1, "filename": "httpretty_fixtures-1.0.2.zip", "has_sig": false, "md5_digest": "33e24430411771178e5d2be94a6ee89c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20871, "upload_time": "2015-06-02T18:11:49", "url": "https://files.pythonhosted.org/packages/37/0e/0027d97d06d0e0dd4cadc2b50456abf9db6f81e4f20c5f6e902560d13bf2/httpretty_fixtures-1.0.2.zip" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "3827cbe9610abf76db60fda19969ac5d", "sha256": "b3cb5379f1dad188de8338861679c83b86283c1c15052a2cc9a1444433f18ee3" }, "downloads": -1, "filename": "httpretty_fixtures-2.0.0.tar.gz", "has_sig": false, "md5_digest": "3827cbe9610abf76db60fda19969ac5d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15104, "upload_time": "2015-06-04T22:48:55", "url": "https://files.pythonhosted.org/packages/8e/f2/7a915cd3b8ca2bee69171658b947af10f08031c0ba283a9f6f67fded0002/httpretty_fixtures-2.0.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "a25f718e25f22ef87f17ec562e0b4e97", "sha256": "29a3e001528f13ebb9bf1aa581fe971a550f8df6a8a0c8da03b9a2e57ae8d5fa" }, "downloads": -1, "filename": "httpretty_fixtures-2.0.0.zip", "has_sig": false, "md5_digest": "a25f718e25f22ef87f17ec562e0b4e97", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23274, "upload_time": "2015-06-04T22:48:59", "url": "https://files.pythonhosted.org/packages/20/80/a80c6f0f5d5db27c78a57fce7c190b34e65823637246c9c7a72f218af844/httpretty_fixtures-2.0.0.zip" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "cc6a7614ea0a6956f6e8db0514502893", "sha256": "5bc4b1b3eb4fe905b1a982e1c2d46827277fdca08eee24658289f1f4c4c92861" }, "downloads": -1, "filename": "httpretty_fixtures-2.0.1.tar.gz", "has_sig": false, "md5_digest": "cc6a7614ea0a6956f6e8db0514502893", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12814, "upload_time": "2015-07-14T21:29:39", "url": "https://files.pythonhosted.org/packages/0b/8e/3d24890e22d85c49902f5b51750a3217d580aefdfd58f2421aefc93df6ef/httpretty_fixtures-2.0.1.tar.gz" }, { "comment_text": "", "digests": { "md5": "6249ec242e2691c29b94c65829e6ab74", "sha256": "8d1a0cc5c716fb3560bea90b6ac841e0b92afbbb6c120b511036a56292c799c6" }, "downloads": -1, "filename": "httpretty_fixtures-2.0.1.zip", "has_sig": false, "md5_digest": "6249ec242e2691c29b94c65829e6ab74", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23678, "upload_time": "2015-07-14T21:29:43", "url": "https://files.pythonhosted.org/packages/e0/9e/9520dd724f592a44e759578d0e7611c154129e736eb3027bc71495d1a200/httpretty_fixtures-2.0.1.zip" } ], "2.1.0": [ { "comment_text": "", "digests": { "md5": "e7a8d19280bb9be078c31d5cf16d8bda", "sha256": "5b6e10a611a979e5a1b46c91f85976cd5ea4172e5e26d4519a33c0e5334ae179" }, "downloads": -1, "filename": "httpretty_fixtures-2.1.0.tar.gz", "has_sig": false, "md5_digest": "e7a8d19280bb9be078c31d5cf16d8bda", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13083, "upload_time": "2015-09-28T18:23:24", "url": "https://files.pythonhosted.org/packages/f9/de/2992b5c548873990b056255d533dd961997004905037581dbc2b75447b3a/httpretty_fixtures-2.1.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "371a15746da1ae6c11ed27ee5869b0c3", "sha256": "7daffcbb74cb21d6a8d087d216f5fdc0a6e80c0d9e8a8dbd953347e6411676e6" }, "downloads": -1, "filename": "httpretty_fixtures-2.1.0.zip", "has_sig": false, "md5_digest": "371a15746da1ae6c11ed27ee5869b0c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 24220, "upload_time": "2015-09-28T18:23:28", "url": "https://files.pythonhosted.org/packages/5a/51/617d8c903f42aa21557314af57be983b92033dcc63938114ec4bf95d50f1/httpretty_fixtures-2.1.0.zip" } ], "2.1.1": [ { "comment_text": "", "digests": { "md5": "8d7969a2e4b3d4f581cd67337dc5d362", "sha256": "e027d361eb73e202d42909b23a04e0725a222145783371b33f4abdce55208173" }, "downloads": -1, "filename": "httpretty_fixtures-2.1.1.tar.gz", "has_sig": false, "md5_digest": "8d7969a2e4b3d4f581cd67337dc5d362", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10254, "upload_time": "2016-08-12T16:29:25", "url": "https://files.pythonhosted.org/packages/f6/b5/82b95bad0ccddbe006ad9fddabccb5feedd5cf889d56fd6b865aaf8afd40/httpretty_fixtures-2.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8d7969a2e4b3d4f581cd67337dc5d362", "sha256": "e027d361eb73e202d42909b23a04e0725a222145783371b33f4abdce55208173" }, "downloads": -1, "filename": "httpretty_fixtures-2.1.1.tar.gz", "has_sig": false, "md5_digest": "8d7969a2e4b3d4f581cd67337dc5d362", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10254, "upload_time": "2016-08-12T16:29:25", "url": "https://files.pythonhosted.org/packages/f6/b5/82b95bad0ccddbe006ad9fddabccb5feedd5cf889d56fd6b865aaf8afd40/httpretty_fixtures-2.1.1.tar.gz" } ] }