{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6" ], "description": "# Installation\n\n```\npip install pytest-mock-helper\n```\n\n# Usage\n\nIn develop you need those enviroments:\n\n```\nexport PYTEST_NETWORK_MOCK=develop\nexport PYTEST_NETWORK_FILEPATH=/tmp\n```\n\nFor example you have a test file called test_request.py:\n\n```\n# -*- coding: utf-8 -*-\n\nimport requests\n\n\ndef test_requests_send(capsys):\n requests.get(\"https://httpbin.org\")\n```\n\nRun with `--blockhtp`\n\n```\n$ pytest tests/test_requests.py --blockhttp\n======================================================== test session starts =========================================================\nplatform darwin -- Python 3.6.4, pytest-3.3.2, py-1.5.2, pluggy-0.6.0\nrootdir: /Users/laixintao/Program/pytest-network-mock-helper, inifile:\nplugins: mock-helper-0.0.2\ncollected 1 item\n\ntests/test_requests.py . [100%]\n\n====================================================== 1 passed in 1.38 seconds ======================================================\nCopy the following code to mock http call\n\n@httmock.urlmatch(netloc=\"httpbin.org\", path=\"/\")\ndef mock_item(url, request):\n return test_utils.fake_response(\n rel_path=\"/tmp/httpbin_org0\",\n url=\"https://httpbin.org/\",\n status_code=200\n )\n```\n\nAlso a downloaded file will be saved to your $PYTEST_NETOWRK_FILEPATH:\n\n```\n$ ls /tmp/httpbin_org0\nls /tmp/httpbin_org0\n```\n\n## In Production\n\nThe test server can't send any HTTP request by default:\n\n```\npytest tests/test_requests.py --blockhttp\n======================================================== test session starts =========================================================\nplatform darwin -- Python 3.6.4, pytest-3.3.2, py-1.5.2, pluggy-0.6.0\nrootdir: /Users/laixintao/Program/pytest-network-mock-helper, inifile:\nplugins: mock-helper-0.0.2\ncollected 1 item\n\ntests/test_requests.py F [100%]\n\n============================================================== FAILURES ==============================================================\n_________________________________________________________ test_requests_send _________________________________________________________\n\ncapsys = <_pytest.capture.CaptureFixture object at 0x10a3c3898>\n\n def test_requests_send(capsys):\n> requests.get(\"https://httpbin.org\")\n\ntests/test_requests.py:7:\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\n../../.virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/api.py:72: in get\n return request('get', url, params=params, **kwargs)\n../../.virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/api.py:58: in request\n return session.request(method=method, url=url, **kwargs)\n../../.virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/sessions.py:508: in request\n resp = self.send(prep, **send_kwargs)\n../../.virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/sessions.py:618: in send\n r = adapter.send(request, **kwargs)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\n\nself = , request = , args = ()\nkwargs = {'cert': None, 'proxies': OrderedDict(), 'stream': False, 'timeout': None, ...}\nparsed = ParseResult(scheme='https', netloc='httpbin.org', path='/', params='', query='', fragment=''), netloc = 'httpbin.org'\npath = '/'\n\n def whitelisted(self, request, *args, **kwargs):\n global summaries\n parsed = urlparse(request.url)\n netloc = parsed.netloc\n path = parsed.path\n if isinstance(netloc, str) and netloc in whitelist:\n return self.old_send(request, *args, **kwargs)\n\n if not is_develop:\n logger.warning('Denied HTTP connection to: %s' % netloc)\n> raise MockHttpCall(netloc)\nE pytest_mock_helper.MockHttpCall: httpbin.org\n\npytest_mock_helper.py:53: MockHttpCall\n-------------------------------------------------------- Captured stderr call --------------------------------------------------------\npytest_mock_helper.py \n```\n\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "pytest-mock-helper", "package_url": "https://pypi.org/project/pytest-mock-helper/", "platform": "", "project_url": "https://pypi.org/project/pytest-mock-helper/", "project_urls": null, "release_url": "https://pypi.org/project/pytest-mock-helper/0.2.1/", "requires_dist": [ "pytest" ], "requires_python": "", "summary": "Help you mock HTTP call and generate mock code", "version": "0.2.1" }, "last_serial": 3516763, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "7433aca7473726619ed8bf9bf15b3a98", "sha256": "ac05c0dce5dacc17be8063d13c7a37cb4ca7ba3c9a1d5997702c199c7707562b" }, "downloads": -1, "filename": "pytest_mock_helper-0.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "7433aca7473726619ed8bf9bf15b3a98", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 6257, "upload_time": "2018-01-23T09:59:22", "url": "https://files.pythonhosted.org/packages/6a/e9/55706193d16686311b580b0acc5d5b17b6735c5a99248db669d807123911/pytest_mock_helper-0.1.0-py2-none-any.whl" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "635542cd4b86496fee3c5e6b32a00eb0", "sha256": "1addeb62c95789d719337a34a9e55dad401c2f114f183188607071950a7c5dc8" }, "downloads": -1, "filename": "pytest_mock_helper-0.2.0-py2-none-any.whl", "has_sig": false, "md5_digest": "635542cd4b86496fee3c5e6b32a00eb0", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 6255, "upload_time": "2018-01-23T10:05:05", "url": "https://files.pythonhosted.org/packages/2a/af/345aede7ab19eb32e54ab54310852bc48f42c140d0a3ec352cf5eb4e0d49/pytest_mock_helper-0.2.0-py2-none-any.whl" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "b1f7da602176b770988f19e50c6ae1e9", "sha256": "5adffffaee0f5134286da3050251b3677bc65da3ee829a9bba6754437bae615c" }, "downloads": -1, "filename": "pytest_mock_helper-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b1f7da602176b770988f19e50c6ae1e9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6338, "upload_time": "2018-01-24T10:14:57", "url": "https://files.pythonhosted.org/packages/66/74/2c1ec8b028df6f3a1b98458e9961ef547f702a92be9d98b4f9dace1d2158/pytest_mock_helper-0.2.1-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b1f7da602176b770988f19e50c6ae1e9", "sha256": "5adffffaee0f5134286da3050251b3677bc65da3ee829a9bba6754437bae615c" }, "downloads": -1, "filename": "pytest_mock_helper-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b1f7da602176b770988f19e50c6ae1e9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6338, "upload_time": "2018-01-24T10:14:57", "url": "https://files.pythonhosted.org/packages/66/74/2c1ec8b028df6f3a1b98458e9961ef547f702a92be9d98b4f9dace1d2158/pytest_mock_helper-0.2.1-py3-none-any.whl" } ] }