{ "info": { "author": "Thomas Sileo", "author_email": "thomas.sileo@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python" ], "description": "============\n Eve-Mocker\n============\n\nMocking tool for `Eve powered REST API `_, based on the excellent `HTTPretty `_, aimed to be used in your unit tests, when you rely on an Eve API.\n\nFeatures\n========\n\nEve-Mocker doesn't try to replicate every Eve features, by design, it doesn't need any Eve settings files, doesn't support schema validation and more advanced features. Don't hesitate to contribute if you need more complex features.\n\n* Everything is stored in memory (``self.items``)\n* Support all methods except HEAD requests\n* Handle ETags, and always return meaningful status code, like Eve.\n* Partial support of filtering and sorting (only mongo query syntax)\n* No need to change your code for testing, HTTPretty does everything for you, it works well with `requests `_.\n* It renders only JSON, no XML yet.\n\nInstalling\n==========\n\n.. code-block::\n\n $ pip install eve-mocker\n\n\nUsage\n=====\n\nYou should read `HTTPretty `_ documentation before starting.\n\nHere is a basic example:\n\n.. code-block:: python\n\n from httpretty import HTTPretty\n import requests\n\n HTTPretty.enable()\n EveMocker(\"http://myapi.com/api/\")\n \n response = requests.get(\"http://myapi.com/api/mymodel/\")\n assert response.status_code == 200\n assert response.json() == {\"_items\": []}\n\n HTTPretty.disable()\n\nYou can add data directly with ``EveMocker.set_resource``:\n\n.. code-block:: python\n\n from httpretty import HTTPretty\n import requests\n\n HTTPretty.enable()\n eve_mocker = EveMocker(\"http://myapi.com/api/\")\n\n mymodel_data = [{\"_id\": \"fakeid\", \"content\": \"mycontent\"}]\n eve_mocker.set_resource(\"mymodel\", mymodel_data)\n\n response = requests.get(\"http://myapi.com/api/mymodel/\")\n assert response.status_code == 200\n assert response.json() == {\"_items\": mymodel_data}\n\n HTTPretty.disable()\n\n\nAlternatively, you use ``EveMocker`` within a context manager, and it will automatically call ``HTTPretty.enable()`` and ``HTTPretty.disable()``.\n\n.. code-block:: python\n\n from eve_mocker import EveMocker\n import requests\n\n with EveMocker(\"http://myapi.com/api/\"):\n response = requests.get(\"http://myapi.com/api/mymodel/\")\n assert response.status_code == 200\n assert response.json() == {\"_items\": []}\n\nCheck the tests (in ``test_eve_mocker.py``) if you want to check more examples.\n\nGetting started\n===============\n\nLet's say you want to test the following class stored in ``remote_items.py`` that need to call an Eve powered REST API:\n\n.. code-block:: python\n\n from urlparse import urljoin\n from functools import partial\n import requests\n\n API_URL = \"http://my-eve-api.com/api/\"\n\n\n class RemoteItems(object):\n def __init__(self, api_url=API_URL):\n self.api_url = api_url\n self.endpoint_url = partial(urljoin, self.api_url)\n\n def get_latest(self):\n r = requests.get(self.endpoint_url(\"items\"))\n r.raise_for_status()\n return r.json().get(\"_items\", [])\n\n\nHere is how you can do it with Eve-Mocker:\n\n.. code-block:: python\n\n from eve_mocker import EveMocker\n import unittest\n from remote_items import RemoteItems, API_URL\n\n class TestRemoteItems(unittest.TestCase):\n def testGetLatestItems(self):\n items = [{\"_id\": \"fakeid\", \"content\": \"my content\"},\n {\"_id\": \"fakeid2\", \"content\": \"another_content\"}]\n with EveMocker(API_URL) as eve_mocker:\n # We feed EveMocker DB with some items\n eve_mocker.set_resource(\"items\", items)\n\n remote_items = RemoteItems()\n latest_items = remote_items.get_latest()\n\n self.assertEqual(sorted(latest_items), sorted(items))\n\n if __name__ == '__main__':\n unittest.main()\n\n\nYou can find these two files in the **examples** directory.\n\n\nAdvanced Usage\n==============\n\n``EveMocker`` takes two additonals arguments, ``default_pk`` if you need a primary key other than ``_id``, and ``pk_maps`` which is a mapping resource => primary key: ``{\"resource\": \"pk_field\", \"resource2\": \"pk_field\"}``.\n\nLicense (MIT)\n=============\n\nCopyright (c) 2013 Thomas Sileo\n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.", "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/tsileo/eve-mocker", "keywords": "eve api mock mocking mocker", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "eve-mocker", "package_url": "https://pypi.org/project/eve-mocker/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/eve-mocker/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/tsileo/eve-mocker" }, "release_url": "https://pypi.org/project/eve-mocker/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Mocking tool for Eve powered REST API.", "version": "0.1.0" }, "last_serial": 816916, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "cd491ee7a9cad7566a9df734799ebbdf", "sha256": "cb1ae0fd35fb528190033ba17d516dbf9be357afd0009428e61af232cda9d690" }, "downloads": -1, "filename": "eve-mocker-0.1.0.tar.gz", "has_sig": false, "md5_digest": "cd491ee7a9cad7566a9df734799ebbdf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7469, "upload_time": "2013-07-16T20:19:49", "url": "https://files.pythonhosted.org/packages/f5/6d/d8863217ba670a3c53f4da32a17f0a7063230ab0589258a3bb4e086ff1bb/eve-mocker-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cd491ee7a9cad7566a9df734799ebbdf", "sha256": "cb1ae0fd35fb528190033ba17d516dbf9be357afd0009428e61af232cda9d690" }, "downloads": -1, "filename": "eve-mocker-0.1.0.tar.gz", "has_sig": false, "md5_digest": "cd491ee7a9cad7566a9df734799ebbdf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7469, "upload_time": "2013-07-16T20:19:49", "url": "https://files.pythonhosted.org/packages/f5/6d/d8863217ba670a3c53f4da32a17f0a7063230ab0589258a3bb4e086ff1bb/eve-mocker-0.1.0.tar.gz" } ] }