![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
A utility library for mocking out the urllib3
_ Python library.
This is an adaptation of the responses
_ library.
.. image:: https://travis-ci.org/florentx/urllib3-mock.png?branch=master :target: https://travis-ci.org/florentx/urllib3-mock
.. _urllib3: https://urllib3.readthedocs.org/ .. _responses: https://github.com/getsentry/responses
.. code-block:: python
from urllib3_mock import Responses
import requests
responses = Responses('requests.packages.urllib3')
@responses.activate
def test_my_api():
responses.add('GET', '/api/1/foobar',
body='{"error": "not found"}', status=404,
content_type='application/json')
resp = requests.get('http://twitter.com/api/1/foobar')
assert resp.json() == {"error": "not found"}
assert len(responses.calls) == 1
assert responses.calls[0].request.url == '/api/1/foobar'
assert responses.calls[0].request.host == 'twitter.com'
assert responses.calls[0].request.scheme == 'http'
.. code-block:: python
import json
from urllib3_mock import Responses
import requests
responses = Responses('requests.packages.urllib3')
@responses.activate
def test_calc_api():
def request_callback(request):
payload = json.loads(request.body)
resp_body = {'value': sum(payload['numbers'])}
headers = {'request-id': '728d329e-0e86-11e4-a748-0c84dc037c13'}
return (200, headers, json.dumps(resp_body))
responses.add_callback('POST', '/sum',
callback=request_callback,
content_type='application/json')
resp = requests.post(
'http://calc.com/sum',
json.dumps({'numbers': [1, 2, 3]}),
headers={'content-type': 'application/json'},
)
assert resp.json() == {'value': 6}
assert len(responses.calls) == 1
assert responses.calls[0].request.url == '/sum'
assert responses.calls[0].request.host == 'calc.com'
assert (
responses.calls[0].response.headers['request-id'] ==
'728d329e-0e86-11e4-a748-0c84dc037c13'
)
Instead of passing a string URL into responses.add
or responses.add_callback
you can also supply a compiled regular expression.
.. code-block:: python
import re
from urllib3_mock import Responses
import requests
responses = Responses('requests.packages.urllib3')
# Instead of
responses.add('GET', '/api/1/foobar',
body='{"error": "not found"}', status=404,
content_type='application/json')
# You can do the following
url_re = re.compile(r'/api/\d+/foobar')
responses.add('GET', url_re,
body='{"error": "not found"}', status=404,
content_type='application/json')
A response can also throw an exception as follows.
.. code-block:: python
from urllib3_mock import Responses
from requests.packages.urllib3.exceptions import HTTPError
exception = HTTPError('Something went wrong')
responses = Responses('requests.packages.urllib3')
responses.add('GET', '/api/1/foobar',
body=exception)
# All calls to 'http://twitter.com/api/1/foobar' will throw exception.
FAQs
A utility library for mocking out the `urllib3` Python library.
We found that urllib3-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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.