Beispiel #1
0
 def test_view_urlencoded(self):
     d = url.encode([("one", "two"), ("three", "four")]).encode()
     v = cv.ViewURLEncoded()
     assert v(d)
     d = url.encode([("adsfa", "")]).encode()
     v = cv.ViewURLEncoded()
     assert v(d)
Beispiel #2
0
def test_empty_key_trailing_equal_sign():
    """
    Some HTTP clients don't send trailing equal signs for parameters without assigned value, e.g. they send
        foo=bar&baz&qux=quux
    instead of
        foo=bar&baz=&qux=quux
    The respective behavior of encode() should be driven by a reference string given in similar_to parameter
    """
    reference_without_equal = "key1=val1&key2&key3=val3"
    reference_with_equal = "key1=val1&key2=&key3=val3"

    post_data_empty_key_middle = [('one', 'two'), ('emptykey', ''),
                                  ('three', 'four')]
    post_data_empty_key_end = [('one', 'two'), ('three', 'four'),
                               ('emptykey', '')]

    assert url.encode(
        post_data_empty_key_middle,
        similar_to=reference_with_equal) == "one=two&emptykey=&three=four"
    assert url.encode(
        post_data_empty_key_end,
        similar_to=reference_with_equal) == "one=two&three=four&emptykey="
    assert url.encode(
        post_data_empty_key_middle,
        similar_to=reference_without_equal) == "one=two&emptykey&three=four"
    assert url.encode(
        post_data_empty_key_end,
        similar_to=reference_without_equal) == "one=two&three=four&emptykey"
def test_view_urlencoded():
    v = full_eval(urlencoded.ViewURLEncoded())

    d = url.encode([("one", "two"), ("three", "four")]).encode()
    assert v(d)

    d = url.encode([("adsfa", "")]).encode()
    assert v(d)

    assert not v(b"\xFF\x00")
def test_view_urlencoded():
    v = full_eval(urlencoded.ViewURLEncoded())

    d = url.encode([("one", "two"), ("three", "four")]).encode()
    assert v(d)

    d = url.encode([("adsfa", "")]).encode()
    assert v(d)

    assert not v(b"\xFF\x00")
Beispiel #5
0
 def _set_urlencoded_form(self, form_data):
     """
     Sets the body to the URL-encoded form data, and adds the appropriate content-type header.
     This will overwrite the existing content if there is one.
     """
     self.headers["content-type"] = "application/x-www-form-urlencoded"
     self.content = url.encode(form_data,
                               self.get_text(strict=False)).encode()
Beispiel #6
0
def test_empty_key_trailing_equal_sign():
    """
    Some HTTP clients don't send trailing equal signs for parameters without assigned value, e.g. they send
        foo=bar&baz&qux=quux
    instead of
        foo=bar&baz=&qux=quux
    The respective behavior of encode() should be driven by a reference string given in similar_to parameter
    """
    reference_without_equal = "key1=val1&key2&key3=val3"
    reference_with_equal = "key1=val1&key2=&key3=val3"

    post_data_empty_key_middle = [('one', 'two'), ('emptykey', ''), ('three', 'four')]
    post_data_empty_key_end = [('one', 'two'), ('three', 'four'), ('emptykey', '')]

    assert url.encode(post_data_empty_key_middle, similar_to = reference_with_equal) == "one=two&emptykey=&three=four"
    assert url.encode(post_data_empty_key_end, similar_to = reference_with_equal) == "one=two&three=four&emptykey="
    assert url.encode(post_data_empty_key_middle, similar_to = reference_without_equal) == "one=two&emptykey&three=four"
    assert url.encode(post_data_empty_key_end, similar_to = reference_without_equal) == "one=two&three=four&emptykey"
Beispiel #7
0
 def _set_query(self, query_data):
     query = url.encode(query_data)
     _, _, path, params, _, fragment = urllib.parse.urlparse(self.url)
     self.path = urllib.parse.urlunparse(
         ["", "", path, params, query, fragment])
Beispiel #8
0
def test_encode():
    assert url.encode([('foo', 'bar')])
    assert url.encode([('foo', surrogates)])
Beispiel #9
0
def test_encode():
    assert url.encode([('foo', 'bar')])
    assert url.encode([('foo', surrogates)])
    assert not url.encode([], similar_to="justatext")
Beispiel #10
0
def test_encode():
    assert url.encode([('foo', 'bar')])
    assert url.encode([('foo', surrogates)])
    assert not url.encode([], similar_to="justatext")
Beispiel #11
0
def test_encode():
    assert url.encode([('foo', 'bar')])
    assert url.encode([('foo', surrogates)])