コード例 #1
0
def test_compact():
    assert u.compact({}) == {}
    assert u.compact({'foo': 1}) == {'foo': 1}
    assert u.compact({
        'foo': 1,
        'bar': None,
        'baz': [],
        'bla': ''
    }) == {
        'foo': 1
    }
コード例 #2
0
def get(url, params={}, headers={}, valid_codes={200, 404}):
    headers = compact(headers)
    print("\nhttp get '%s' %s " % (url, header_str(headers)))
    response = requests.get(url, params=params, headers=headers)
    check_status_code(response, valid_codes)
    if config.boolean('LOG_RESPONSE'):
        print_response_body(response)
    return response
コード例 #3
0
def delete(url, headers={}, valid_codes={200, 204}):
    headers = compact(headers)
    print("\nhttp delete '%s' %s " % (url, header_str(headers)))
    response = requests.delete(url, headers=headers)
    check_status_code(response, valid_codes)
    return response
コード例 #4
0
def patch(url, data, headers={}, valid_codes={200, 204}):
    headers = compact(headers)
    print("\necho '%s' | http patch '%s' %s " % (json.dumps(data), url, header_str(headers)))
    response = requests.patch(url, json=data, headers=headers)
    check_status_code(response, valid_codes)
    return response