The library to help test your HTTP requests using unittests
Project description
Used to mock response and validate that the requests happened in the right order with right data
Usage example:
import requests
from unittests import TestCase
def get_likes_on_post(username, password, post_id):
access_token = requests.post('http://my.site/login',
json={'username': username, 'password': password}).json()['access_token']
likes = requests.get(f'http://my.site/posts/{post_id}',
headers={'Accept': 'application/json',
'Authorization': f'Bearer {access_token}'}).json()['likes']
return likes
class TestGetLikesOnPost(TestCase):
@RequestMock.assert_requests([
RequestMock(
request_url='http://my.site/login',
request_json={'username': 'the name', 'password': 'the password'},
request_method=RequestMock.Method.POST,
response_json={"access_token": 'the-token'}
),
RequestMock(
request_url='http://my.site/posts/3',
request_headers_contains={'Authorization': 'Bearer the-token'},
response_json={'name': 'The cool story', 'likes': 42}
)
])
def test_get_likes_on_post(self):
self.assertEqual(42, get_likes_on_post('the name', 'the password', 3))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
requests-asserts-0.1.1.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for requests_asserts-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e328c7bfae043c02afa66333c45e764484175afd17083a62fe0cb144672234d |
|
MD5 | 3614b679bb9e24ff22a4a5d4f0e6aa8a |
|
BLAKE2b-256 | 352f4e51e8a02a7b7cff518cafca8d1eea508d6dd6f6901bb5d09734e6e0cd0a |