示例#1
0
    def _request(self, path, data=None, headers=None):
        default_headers = {"User-Agent": "py-gocd"}
        if self._session_id:
            default_headers["Cookie"] = "JSESSIONID={0}".format(self._session_id)
        default_headers.update(headers or {})

        data = self._inject_authenticity_token(data, path)
        return urllib2.Request(
            self._url(path),
            # GET is None, and anything that is a string is POST
            data=urlencode(data) if data else data,
            headers=default_headers,
        )
示例#2
0
def test_basic():
    """Verify that urlencode works with four levels."""
    d = {"a": {"b": {"c": "d"}}}
    expected = urllib.quote("a[b][c]=d", safe="=/&")
    assert urlencode(d) == expected
示例#3
0
def test_with_non_dict():
    """Verify that we raise an exception when passing a non-dict."""
    with pytest.raises(TypeError):
        urlencode("e")
示例#4
0
def test_with_list_value():
    """Verify that urlencode works with list value."""
    d = {'a': {"b": [1, 2, 3]}}
    expected = "a[b][]=1&a[b][]=2&a[b][]=3"
    assert urllib.unquote(urlencode(d)) == expected
示例#5
0
def test_two():
    """Verify that urlencode works with two params."""
    d = {'a': 'b', 'c': {'d': 'e'}}
    expected = urllib.quote("a=b&c[d]=e", safe="=/&")
    assert urlencode(d) == expected
示例#6
0
def test_key_types():
    """Verify that urlencode works with key type 'int'."""
    d = {1: {2: {3: 4}}}
    expected = urllib.quote("1[2][3]=4", safe="=/&")
    assert urlencode(d) == expected