Exemple #1
0
def test_to_curl_cookies():
    r = create_request(
        "GET",
        "http://foo.com",
        cookies=(acurl._Cookie(False, "foo.com", True, "/", False, 0, "123", "456"),),
    )
    assert r.to_curl() == "curl -X GET  --cookie 123=456   http://foo.com"
Exemple #2
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"
Exemple #3
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"
    )
Exemple #4
0
def test_to_curl_multiple_cookies():
    r = create_request(
        "GET",
        "http://foo.com",
        cookies=(
            acurl._Cookie(False, "foo.com", True, "/", False, 0, "123", "456"),
            acurl._Cookie(False, "foo.com", True, "/", False, 0, "789", "abc"),
        ),
    )
    assert r.to_curl() == "curl -X GET  --cookie '123=456;789=abc'   http://foo.com"
Exemple #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.parse_cookie_string(
                "foo.com\tFALSE\t/bar\tFALSE\t0\tmy_cookie\tmy_value"),
            acurl.parse_cookie_string(
                "foo.com\tFALSE\t/bar\tFALSE\t0\tfoo\tbar"),
        ),
    )
    assert "my_cookie" in r.cookies
    assert r.cookies["my_cookie"] == "my_value"
    assert "foo" in r.cookies
    assert r.cookies["foo"] == "bar"
Exemple #6
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",
        cookies=(
            acurl._Cookie(
                False,
                "bar.com",  # The domain doesn't match, the cookie should not be passed
                True,
                "/",
                False,
                0,
                "123",
                "456",
            ),
        ),
    )
    assert r.to_curl() == "curl -X GET http://foo.com"
Exemple #7
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"
Exemple #8
0
def test_to_curl():
    r = create_request("GET", "http://foo.com")
    assert r.to_curl() == "curl -X GET     http://foo.com"