Mock requests library like HTTPToolkit in python3
pip install reqMock
import requests
print(requests.get("https://google.com").text)
from reqMock import mockControl as mock
# To enable mock
mock.set(enable = True)
# To disable mock
mock.set(enable = False)
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.add(
url = "https://youtube.com",
method = "GET",
mockCheck = "url",
mockMethod = "text",
to = "Hello World!"
)
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
mock.set(showResult = True) # Default is False
# You will see output requests like this
# ">> result: GET: https://google.com" and below is result output
mock.set(stdout = open('out.txt', 'w'))
# Output of 'show' option will write to file instead of write to output
# 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