# reqMock
Mock requests library like HTTPToolkit in python3
# Installation
```bash
pip install reqMock
```
# Example:
## Original code
```python3
import requests
print(requests.get("https://google.com").text)
```
## Import in first line of code
```python3
from reqMock import mockControl as mock
```
## Enable mock
```python3
# To enable mock
mock.set(enable = True)
# To disable mock
mock.set(enable = False)
```
## Mock `https://google.com` to another website
```python3
mock.add(
url = "https://google.com", # mock 'from'
method = "GET", # method 'from'
mockCheck = "url", # method mock ('host', 'url', 'match')
mockMethod = "url", # mock to 'url' or 'text'
to = "https://youtube.com", # data
)
```
## Mock `https://youtube.com` to custom result
```python3
mock.add(
url = "https://youtube.com",
method = "GET",
mockCheck = "url",
mockMethod = "text",
to = "Hello World!"
)
```
## Enable `showQuery` to print info from requests
```python3
mock.set(showQuery = True) # Default is False
# You will see output requests like this
# ">> requests: GET: https://google.com (headers={'abc': 'def'})" and below is result output
```
## Enable `showResult` to print result output from requests
```python3
mock.set(showResult = True) # Default is False
# You will see output requests like this
# ">> result: GET: https://google.com" and below is result output
```
## Redirect output of `show` to file
```python3
mock.set(stdout = open('out.txt', 'w'))
# Output of 'show' option will write to file instead of write to output
```
# If you want to rename this module for hide from check
```python3
# Open a python3 shell
from reqMock import mockControl as mock
# Example change module name from 'reqMock' to 'Khanh'
mock.set(moduleName = "Khanh")
# Choose 'y' and new name will applied in new session
# For new session, import it by using new name
from Khanh import mockControl as mock
```
Raw data
{
"_id": null,
"home_page": "https://github.com/KhanhNguyen9872/reqMock",
"name": "reqMock",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "reqMock",
"author": "KhanhNguyen9872",
"author_email": "KhanhNguyen9872 <khanhvuinguyenvan800983609@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/52/51/71ccdb9a20e0196c7f38397b39903da31cce0f44180a28c955a1797b2fca/reqMock-0.0.0.4.tar.gz",
"platform": "any",
"description": "# reqMock\r\nMock requests library like HTTPToolkit in python3\r\n\r\n# Installation\r\n```bash\r\npip install reqMock\r\n```\r\n\r\n# Example:\r\n## Original code\r\n```python3\r\nimport requests\r\nprint(requests.get(\"https://google.com\").text)\r\n```\r\n\r\n## Import in first line of code\r\n```python3\r\nfrom reqMock import mockControl as mock\r\n```\r\n\r\n## Enable mock\r\n```python3\r\n# To enable mock\r\nmock.set(enable = True)\r\n\r\n# To disable mock\r\nmock.set(enable = False)\r\n```\r\n\r\n## Mock `https://google.com` to another website\r\n```python3\r\nmock.add(\r\n\turl = \"https://google.com\",\t# mock 'from'\r\n\tmethod = \"GET\",\t\t\t# method 'from'\r\n\tmockCheck = \"url\",\t\t\t# method mock ('host', 'url', 'match')\r\n\tmockMethod = \"url\",\t\t\t# mock to 'url' or 'text'\r\n\tto = \"https://youtube.com\",\t# data\r\n)\r\n```\r\n\r\n## Mock `https://youtube.com` to custom result\r\n```python3\r\nmock.add(\r\n\turl = \"https://youtube.com\",\r\n\tmethod = \"GET\",\t\r\n\tmockCheck = \"url\",\t\r\n\tmockMethod = \"text\",\r\n\tto = \"Hello World!\"\r\n)\r\n```\r\n\r\n## Enable `showQuery` to print info from requests\r\n```python3\r\nmock.set(showQuery = True)\t\t# Default is False\r\n\r\n# You will see output requests like this \r\n# \">> requests: GET: https://google.com (headers={'abc': 'def'})\" and below is result output\r\n```\r\n\r\n## Enable `showResult` to print result output from requests\r\n```python3\r\nmock.set(showResult = True)\t\t# Default is False\r\n\r\n# You will see output requests like this \r\n# \">> result: GET: https://google.com\" and below is result output\r\n```\r\n\r\n## Redirect output of `show` to file\r\n```python3\r\nmock.set(stdout = open('out.txt', 'w'))\r\n\r\n# Output of 'show' option will write to file instead of write to output\r\n```\r\n\r\n# If you want to rename this module for hide from check\r\n```python3\r\n# Open a python3 shell\r\nfrom reqMock import mockControl as mock\r\n\r\n# Example change module name from 'reqMock' to 'Khanh'\r\nmock.set(moduleName = \"Khanh\")\r\n# Choose 'y' and new name will applied in new session\r\n\r\n# For new session, import it by using new name\r\nfrom Khanh import mockControl as mock\r\n```\r\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "Mock requests in python3",
"version": "0.0.0.4",
"project_urls": {
"Documentation": "https://github.com/KhanhNguyen9872/reqMock#readme",
"Download": "https://github.com/KhanhNguyen9872/reqMock",
"Homepage": "https://github.com/KhanhNguyen9872/reqMock",
"Issue Tracker": "https://github.com/KhanhNguyen9872/reqMock/issues",
"Source Code": "https://github.com/KhanhNguyen9872/reqMock"
},
"split_keywords": [
"reqmock"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ad3edf9087fae5e80c8ecde50364b8be3de6af599261dc86f824e1eebc1ff0b7",
"md5": "e0c6758556955cab9a077c40fe29ab1a",
"sha256": "bf36bc761c924fc5ce166693f20ae2ffff02e1f8fa2a27b61e1334853a49ea2d"
},
"downloads": -1,
"filename": "reqMock-0.0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e0c6758556955cab9a077c40fe29ab1a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 5079,
"upload_time": "2024-06-29T14:07:56",
"upload_time_iso_8601": "2024-06-29T14:07:56.489389Z",
"url": "https://files.pythonhosted.org/packages/ad/3e/df9087fae5e80c8ecde50364b8be3de6af599261dc86f824e1eebc1ff0b7/reqMock-0.0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "525171ccdb9a20e0196c7f38397b39903da31cce0f44180a28c955a1797b2fca",
"md5": "e0d706afdad9dc941dcb2761d97d27d6",
"sha256": "e4f936831674728ad2e687c3d88da40cd1e60191bd409a249dcbf0fe4a4a1274"
},
"downloads": -1,
"filename": "reqMock-0.0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "e0d706afdad9dc941dcb2761d97d27d6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 5489,
"upload_time": "2024-06-29T14:07:57",
"upload_time_iso_8601": "2024-06-29T14:07:57.737966Z",
"url": "https://files.pythonhosted.org/packages/52/51/71ccdb9a20e0196c7f38397b39903da31cce0f44180a28c955a1797b2fca/reqMock-0.0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-29 14:07:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "KhanhNguyen9872",
"github_project": "reqMock",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "reqmock"
}