MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_basic

Method test_basic

Lib/test/test_http_cookies.py:13–60  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

11class CookieTests(unittest.TestCase):
12
13 def test_basic(self):
14 cases = [
15 {'data': 'chips=ahoy; vienna=finger',
16 'dict': {'chips':'ahoy', 'vienna':'finger'},
17 'repr': "<SimpleCookie: chips='ahoy' vienna='finger'>",
18 'output': 'Set-Cookie: chips=ahoy\nSet-Cookie: vienna=finger'},
19
20 {'data': 'keebler="E=mc2; L=\\"Loves\\"; fudge=;"',
21 'dict': {'keebler' : 'E=mc2; L="Loves"; fudge=;'},
22 'repr': '''<SimpleCookie: keebler='E=mc2; L="Loves"; fudge=;'>''',
23 'output': 'Set-Cookie: keebler="E=mc2; L=\\"Loves\\"; fudge=;"'},
24
25 # Check illegal cookies that have an '=' char in an unquoted value
26 {'data': 'keebler=E=mc2',
27 'dict': {'keebler' : 'E=mc2'},
28 'repr': "<SimpleCookie: keebler='E=mc2'>",
29 'output': 'Set-Cookie: keebler=E=mc2'},
30
31 # Cookies with ':' character in their name. Though not mentioned in
32 # RFC, servers / browsers allow it.
33
34 {'data': 'key:term=value:term',
35 'dict': {'key:term' : 'value:term'},
36 'repr': "<SimpleCookie: key:term='value:term'>",
37 'output': 'Set-Cookie: key:term=value:term'},
38
39 # issue22931 - Adding '[' and ']' as valid characters in cookie
40 # values as defined in RFC 6265
41 {
42 'data': 'a=b; c=[; d=r; f=h',
43 'dict': {'a':'b', 'c':'[', 'd':'r', 'f':'h'},
44 'repr': "<SimpleCookie: a='b' c='[' d='r' f='h'>",
45 'output': '\n'.join((
46 'Set-Cookie: a=b',
47 'Set-Cookie: c=[',
48 'Set-Cookie: d=r',
49 'Set-Cookie: f=h'
50 ))
51 }
52 ]
53
54 for case in cases:
55 C = cookies.SimpleCookie()
56 C.load(case['data'])
57 self.assertEqual(repr(C), case['repr'])
58 self.assertEqual(C.output(sep='\n'), case['output'])
59 for k, v in sorted(case['dict'].items()):
60 self.assertEqual(C[k].value, v)
61
62 def test_obsolete_rfc850_date_format(self):
63 # Test cases with different days and dates in obsolete RFC 850 format

Callers

nothing calls this directly

Calls 7

reprFunction · 0.85
sortedFunction · 0.85
joinMethod · 0.45
loadMethod · 0.45
assertEqualMethod · 0.45
outputMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected