def test_implicit_post(): request = Request('API endpoint', url='http://example.com', data={'arg1': True, 'arg2': 42}) serialized = request.serialize() assert serialized['method'] == 'POST' assert serialized['dataMode'] == 'urlencoded' assert len(serialized['data']) == 2
def test_simple_request(): request = Request('Simple Request', 'http://example.com') serialized = request.serialize() assert serialized['name'] == 'Simple Request' assert serialized['url'] == 'http://example.com' assert serialized['method'] == 'GET' assert serialized['headers'] == '' assert serialized.get('id') assert len(serialized) == 5
def test_json_data(): request = Request('JSON POST request', url='http://example.com', json={'bool': True, 'string': 'nice', 'number': 42}) serialized = request.serialize() assert serialized['method'] == 'POST' assert serialized['url'] == 'http://example.com' assert serialized['dataMode'] == 'raw' headers = serialized['headers'].split('\n') assert 'Content-Type: application/json' in headers serialized_body = json.loads(serialized['rawModeData']) assert serialized_body['bool'] == True assert serialized_body['string'] == 'nice' assert serialized_body['number'] == 42
def test_form_data(): request = Request('Form POST request', url='http://example.com', data={'bool': True, 'string': 'nice', 'number': 42}) serialized = request.serialize()
def test_query_params_to_url(): request = Request('Query params', url='http://example.com', params=[('valid', 'true'), ('q', 'search string')]) serialized = request.serialize() assert serialized['method'] == 'GET' assert serialized['url'] == 'http://example.com?valid=true&q=search+string'