Reponses is a library that mock the requests module that performs HTTP communication. Made by Dropbox that seems to be reliable. The license is APL 2.0.
class APITestCase(TestCase):
@responses.activate
def test_api(self):
import api
# setup
responses.add(
responses.GET,
'https://example.com/api/v3/users',
status=200,
body="[{'user': {'id': 1, 'username': 'test'}}]",
content_type="application/json",
)
# test
api.get_users()
assert responses.calls[0].request.method == 'GET'
assert responses.calls[0].request.url == 'https://example.com/api/v3/users'
There is also httpretty because it is similar, but Responses was more suitable for me. I will try it for a while.
httpretty
.Recommended Posts