
Research
PyPI Package Disguised as Instagram Growth Tool Harvests User Credentials
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
tornado-httpclient-mock
Advanced tools
A library for mocking requests in Tornado HTTP client
This library can be used to patch AsyncHTTPClient.fetch_impl
method to stub requests to external resources.
tornado_mock.httpclient.patch_http_client
does this patching on AsyncHTTPClient
instance.
After that you can use tornado_mock.httpclient.set_stub
method to setup an appropriate responses to the requests.
from tornado import gen
from tornado.httpclient import AsyncHTTPClient
from tornado.testing import AsyncHTTPTestCase
from tornado.web import Application, RequestHandler
from tornado_mock.httpclient import get_response_stub, patch_http_client, set_stub
class TestHandler(RequestHandler):
@gen.coroutine
def get(self, *args, **kwargs):
response1 = yield self.application.http_client.fetch('http://example.com/path?query')
self.write(response1.body)
response2 = yield self.application.http_client.fetch('http://test.com/path')
self.finish(response2.body)
class HTTPClientMockTest(AsyncHTTPTestCase):
def get_app(self):
app = Application([('/test', TestHandler)])
self.app_http_client = app.http_client = AsyncHTTPClient(force_instance=True)
return app
def test_mock(self):
patch_http_client(self.app_http_client)
def get_response(request):
return get_response_stub(request, buffer='STUB2')
set_stub(self.app_http_client, 'http://example.com/path', response_body='STUB1')
set_stub(self.app_http_client, 'http://test.com/path', response_function=get_response)
self.assertEqual(self.fetch('/test').body, b'STUB1STUB2')
For more information see docstrings in httpclient.py.
FAQs
A library for mocking requests in Tornado HTTP client
We found that tornado-httpclient-mock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.