示例#1
0
def test_get_headers(monkeypatch):
    endpoint = '/foo/bar'
    headers = {'what': 'ever'}
    _mock_urllib(monkeypatch)
    response = methods.get(endpoint, None, headers)

    assert response['request_headers'] == headers
示例#2
0
def test_simple_get_request(monkeypatch):
    endpoint = '/simple/get/'
    _mock_urllib(monkeypatch)
    response = methods.get(endpoint)

    assert response['request_method'] == 'GET'
    assert response['request_url'] == endpoint
    assert response['request_body'] is None
示例#3
0
def test_complex_get_request(monkeypatch):
    endpoint = '/complex/get/'
    _mock_urllib(monkeypatch)
    response = methods.get(endpoint, {'a': 1, 'b': 2})

    assert response['request_method'] == 'GET'
    assert response['request_url'] == endpoint + '?a=1&b=2'
    assert response['request_body'] is None
示例#4
0
def test_url_encoding(monkeypatch):
    endpoint = '/complex/get/'
    params = {'a': 'url encoding', 'b': 'tést'}
    _mock_urllib(monkeypatch)
    response = methods.get(endpoint, params)

    # C3A9 -> hex representation of UTF-8 'é'
    # https://en.wikipedia.org/wiki/Percent-encoding
    expected = '/complex/get/?a=url+encoding&b=t%C3%83%C2%A9st'
    assert response['request_url'] == expected
示例#5
0
def get_hacker_gifs(params):
    url = f'{BASE_URL}/search'
    return get(url, params)