Back to index

python3.2  3.2.2
Public Member Functions
test.test_http_cookiejar.HeaderTests Class Reference

List of all members.

Public Member Functions

def test_parse_ns_headers
def test_parse_ns_headers_version
def test_parse_ns_headers_special_names
def test_join_header_words
def test_split_header_words
def test_roundtrip

Detailed Description

Definition at line 102 of file test_http_cookiejar.py.


Member Function Documentation

Definition at line 131 of file test_http_cookiejar.py.

00131 
00132     def test_join_header_words(self):
00133         joined = join_header_words([[("foo", None), ("bar", "baz")]])
00134         self.assertEqual(joined, "foo; bar=baz")
00135 
00136         self.assertEqual(join_header_words([[]]), "")

Here is the call graph for this function:

Definition at line 104 of file test_http_cookiejar.py.

00104 
00105     def test_parse_ns_headers(self):
00106         # quotes should be stripped
00107         expected = [[('foo', 'bar'), ('expires', 2209069412), ('version', '0')]]
00108         for hdr in [
00109             'foo=bar; expires=01 Jan 2040 22:23:32 GMT',
00110             'foo=bar; expires="01 Jan 2040 22:23:32 GMT"',
00111             ]:
00112             self.assertEqual(parse_ns_headers([hdr]), expected)

Here is the call graph for this function:

Definition at line 123 of file test_http_cookiejar.py.

00123 
00124     def test_parse_ns_headers_special_names(self):
00125         # names such as 'expires' are not special in first name=value pair
00126         # of Set-Cookie: header
00127         # Cookie with name 'expires'
00128         hdr = 'expires=01 Jan 2040 22:23:32 GMT'
00129         expected = [[("expires", "01 Jan 2040 22:23:32 GMT"), ("version", "0")]]
00130         self.assertEqual(parse_ns_headers([hdr]), expected)

Here is the call graph for this function:

Definition at line 113 of file test_http_cookiejar.py.

00113 
00114     def test_parse_ns_headers_version(self):
00115 
00116         # quotes should be stripped
00117         expected = [[('foo', 'bar'), ('version', '1')]]
00118         for hdr in [
00119             'foo=bar; version="1"',
00120             'foo=bar; Version="1"',
00121             ]:
00122             self.assertEqual(parse_ns_headers([hdr]), expected)

Here is the call graph for this function:

Definition at line 171 of file test_http_cookiejar.py.

00171 
00172     def test_roundtrip(self):
00173         tests = [
00174             ("foo", "foo"),
00175             ("foo=bar", "foo=bar"),
00176             ("   foo   ", "foo"),
00177             ("foo=", 'foo=""'),
00178             ("foo=bar bar=baz", "foo=bar; bar=baz"),
00179             ("foo=bar;bar=baz", "foo=bar; bar=baz"),
00180             ('foo bar baz', "foo; bar; baz"),
00181             (r'foo="\"" bar="\\"', r'foo="\""; bar="\\"'),
00182             ('foo,,,bar', 'foo, bar'),
00183             ('foo=bar,bar=baz', 'foo=bar, bar=baz'),
00184 
00185             ('text/html; charset=iso-8859-1',
00186              'text/html; charset="iso-8859-1"'),
00187 
00188             ('foo="bar"; port="80,81"; discard, bar=baz',
00189              'foo=bar; port="80,81"; discard, bar=baz'),
00190 
00191             (r'Basic realm="\"foo\\\\bar\""',
00192              r'Basic; realm="\"foo\\\\bar\""')
00193             ]
00194 
00195         for arg, expect in tests:
00196             input = split_header_words([arg])
00197             res = join_header_words(input)
00198             self.assertEqual(res, expect, """
00199 When parsing: '%s'
00200 Expected:     '%s'
00201 Got:          '%s'
00202 Input was:    '%s'
00203 """ % (arg, expect, res, input))
00204 

Here is the call graph for this function:

Definition at line 137 of file test_http_cookiejar.py.

00137 
00138     def test_split_header_words(self):
00139         tests = [
00140             ("foo", [[("foo", None)]]),
00141             ("foo=bar", [[("foo", "bar")]]),
00142             ("   foo   ", [[("foo", None)]]),
00143             ("   foo=   ", [[("foo", "")]]),
00144             ("   foo=", [[("foo", "")]]),
00145             ("   foo=   ; ", [[("foo", "")]]),
00146             ("   foo=   ; bar= baz ", [[("foo", ""), ("bar", "baz")]]),
00147             ("foo=bar bar=baz", [[("foo", "bar"), ("bar", "baz")]]),
00148             # doesn't really matter if this next fails, but it works ATM
00149             ("foo= bar=baz", [[("foo", "bar=baz")]]),
00150             ("foo=bar;bar=baz", [[("foo", "bar"), ("bar", "baz")]]),
00151             ('foo bar baz', [[("foo", None), ("bar", None), ("baz", None)]]),
00152             ("a, b, c", [[("a", None)], [("b", None)], [("c", None)]]),
00153             (r'foo; bar=baz, spam=, foo="\,\;\"", bar= ',
00154              [[("foo", None), ("bar", "baz")],
00155               [("spam", "")], [("foo", ',;"')], [("bar", "")]]),
00156             ]
00157 
00158         for arg, expect in tests:
00159             try:
00160                 result = split_header_words([arg])
00161             except:
00162                 import traceback, io
00163                 f = io.StringIO()
00164                 traceback.print_exc(None, f)
00165                 result = "(error -- traceback follows)\n\n%s" % f.getvalue()
00166             self.assertEqual(result,  expect, """
00167 When parsing: '%s'
00168 Expected:     '%s'
00169 Got:          '%s'
00170 """ % (arg, expect, result))

Here is the call graph for this function:


The documentation for this class was generated from the following file: