Ejemplo n.º 1
0
def test_request_headers():
    r = create_request("GET",
                       "http://foo.com",
                       headers=("Foo: bar", "Baz: quux"))
    assert "Foo" in r.headers
    assert r.headers["Foo"] == "bar"
    assert "Baz" in r.headers
    assert r.headers["Baz"] == "quux"
Ejemplo n.º 2
0
def test_to_curl_cookies():
    r = create_request(
        "GET",
        "http://foo.com",
        cookies=(acurl_ng._Cookie(False, "foo.com", True, "/", False, 0, "123",
                                  "456").format(), ),
    )
    assert r.to_curl() == "curl -X GET --cookie 123=456 http://foo.com"
Ejemplo n.º 3
0
def test_to_curl_cookies_wrong_domain():
    # I'm not sure if this is a valid test case...Request objects should
    # probably only be constructed via Session.request, which always creates
    # cookies for the domain of the request.  So the case this is exercising
    # won't ever happen.
    r = create_request(
        "GET",
        "http://foo.com",
        # The domain doesn't match, the cookie should not be passed
        cookies=(acurl_ng._Cookie(False, "bar.com", True, "/", False, 0, "123",
                                  "456").format(), ),
    )
    assert r.to_curl() == "curl -X GET http://foo.com"
Ejemplo n.º 4
0
def test_to_curl_multiple_cookies():
    r = create_request(
        "GET",
        "http://foo.com",
        cookies=(
            acurl_ng._Cookie(False, "foo.com", True, "/", False, 0, "123",
                             "456").format(),
            acurl_ng._Cookie(False, "foo.com", True, "/", False, 0, "789",
                             "abc").format(),
        ),
    )
    assert r.to_curl(
    ) == "curl -X GET --cookie '123=456;789=abc' http://foo.com"
Ejemplo n.º 5
0
def test_request_cookies():
    session_mock = Mock()
    session_mock.get_cookie_list.return_value = ()
    r = create_request(
        "GET",
        "http://foo.com",
        cookies=(
            acurl_ng._Cookie(False, "foo.com", True, "/", False, 0, "foo",
                             "bar").format(),
            acurl_ng._Cookie(False, "foo.com", True, "/", False, 0,
                             "my_cookie", "my_value").format(),
        ),
    )
    assert "my_cookie" in r.cookies
    assert r.cookies["my_cookie"] == "my_value"
    assert "foo" in r.cookies
    assert r.cookies["foo"] == "bar"
Ejemplo n.º 6
0
def test_to_curl_auth():
    r = create_request("GET", "http://foo.com", auth=("user", "pass"))
    assert r.to_curl() == "curl -X GET --user user:pass http://foo.com"
Ejemplo n.º 7
0
def test_to_curl():
    r = create_request("GET", "http://foo.com")
    assert r.to_curl() == "curl -X GET http://foo.com"
Ejemplo n.º 8
0
def test_to_curl_headers():
    r = create_request("GET",
                       "http://foo.com",
                       headers=("Foo: bar", "My-Header: is-awesome"))
    assert (r.to_curl(
    ) == "curl -X GET -H 'Foo: bar' -H 'My-Header: is-awesome' http://foo.com")