Back to index

python3.2  3.2.2
Public Member Functions | Private Attributes
test.test_http_cookies.CookieTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_basic
def test_load
def test_extended_encode
def test_special_attrs
def test_quoted_meta

Private Attributes

 _warnings_manager

Detailed Description

Definition at line 9 of file test_http_cookies.py.


Member Function Documentation

Definition at line 11 of file test_http_cookies.py.

00011 
00012     def setUp(self):
00013         self._warnings_manager = check_warnings()
00014         self._warnings_manager.__enter__()
00015         warnings.filterwarnings("ignore", ".* class is insecure.*",
00016                                 DeprecationWarning)

Here is the caller graph for this function:

Definition at line 17 of file test_http_cookies.py.

00017 
00018     def tearDown(self):
00019         self._warnings_manager.__exit__(None, None, None)

Here is the caller graph for this function:

Definition at line 20 of file test_http_cookies.py.

00020 
00021     def test_basic(self):
00022         cases = [
00023             {'data': 'chips=ahoy; vienna=finger',
00024              'dict': {'chips':'ahoy', 'vienna':'finger'},
00025              'repr': "<SimpleCookie: chips='ahoy' vienna='finger'>",
00026              'output': 'Set-Cookie: chips=ahoy\nSet-Cookie: vienna=finger'},
00027 
00028             {'data': 'keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;"',
00029              'dict': {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'},
00030              'repr': '''<SimpleCookie: keebler='E=mc2; L="Loves"; fudge=\\n;'>''',
00031              'output': 'Set-Cookie: keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;"'},
00032 
00033             # Check illegal cookies that have an '=' char in an unquoted value
00034             {'data': 'keebler=E=mc2',
00035              'dict': {'keebler' : 'E=mc2'},
00036              'repr': "<SimpleCookie: keebler='E=mc2'>",
00037              'output': 'Set-Cookie: keebler=E=mc2'},
00038         ]
00039 
00040         for case in cases:
00041             C = cookies.SimpleCookie()
00042             C.load(case['data'])
00043             self.assertEqual(repr(C), case['repr'])
00044             self.assertEqual(C.output(sep='\n'), case['output'])
00045             for k, v in sorted(case['dict'].items()):
00046                 self.assertEqual(C[k].value, v)

Here is the call graph for this function:

Definition at line 72 of file test_http_cookies.py.

00072 
00073     def test_extended_encode(self):
00074         # Issue 9824: some browsers don't follow the standard; we now
00075         # encode , and ; to keep them from tripping up.
00076         C = cookies.SimpleCookie()
00077         C['val'] = "some,funky;stuff"
00078         self.assertEqual(C.output(['val']),
00079             'Set-Cookie: val="some\\054funky\\073stuff"')

Here is the call graph for this function:

Definition at line 47 of file test_http_cookies.py.

00047 
00048     def test_load(self):
00049         C = cookies.SimpleCookie()
00050         C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
00051 
00052         self.assertEqual(C['Customer'].value, 'WILE_E_COYOTE')
00053         self.assertEqual(C['Customer']['version'], '1')
00054         self.assertEqual(C['Customer']['path'], '/acme')
00055 
00056         self.assertEqual(C.output(['path']),
00057             'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme')
00058         self.assertEqual(C.js_output(), r"""
00059         <script type="text/javascript">
00060         <!-- begin hiding
00061         document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1";
00062         // end hiding -->
00063         </script>
00064         """)
00065         self.assertEqual(C.js_output(['path']), r"""
00066         <script type="text/javascript">
00067         <!-- begin hiding
00068         document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme";
00069         // end hiding -->
00070         </script>
00071         """)

Here is the call graph for this function:

Definition at line 110 of file test_http_cookies.py.

00110 
00111     def test_quoted_meta(self):
00112         # Try cookie with quoted meta-data
00113         C = cookies.SimpleCookie()
00114         C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
00115         self.assertEqual(C['Customer'].value, 'WILE_E_COYOTE')
00116         self.assertEqual(C['Customer']['version'], '1')
00117         self.assertEqual(C['Customer']['path'], '/acme')
00118 
00119         self.assertEqual(C.output(['path']),
00120                          'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme')
00121         self.assertEqual(C.js_output(), r"""
00122         <script type="text/javascript">
00123         <!-- begin hiding
00124         document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1";
00125         // end hiding -->
00126         </script>
00127         """)
00128         self.assertEqual(C.js_output(['path']), r"""
00129         <script type="text/javascript">
00130         <!-- begin hiding
00131         document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme";
00132         // end hiding -->
00133         </script>
00134         """)

Here is the call graph for this function:

Definition at line 80 of file test_http_cookies.py.

00080 
00081     def test_special_attrs(self):
00082         # 'expires'
00083         C = cookies.SimpleCookie('Customer="WILE_E_COYOTE"')
00084         C['Customer']['expires'] = 0
00085         # can't test exact output, it always depends on current date/time
00086         self.assertTrue(C.output().endswith('GMT'))
00087 
00088         # loading 'expires'
00089         C = cookies.SimpleCookie()
00090         C.load('Customer="W"; expires=Wed, 01-Jan-2010 00:00:00 GMT')
00091         self.assertEqual(C['Customer']['expires'],
00092                          'Wed, 01-Jan-2010 00:00:00 GMT')
00093         C = cookies.SimpleCookie()
00094         C.load('Customer="W"; expires=Wed, 01-Jan-98 00:00:00 GMT')
00095         self.assertEqual(C['Customer']['expires'],
00096                          'Wed, 01-Jan-98 00:00:00 GMT')
00097 
00098         # 'max-age'
00099         C = cookies.SimpleCookie('Customer="WILE_E_COYOTE"')
00100         C['Customer']['max-age'] = 10
00101         self.assertEqual(C.output(),
00102                          'Set-Cookie: Customer="WILE_E_COYOTE"; Max-Age=10')
00103 
00104         # others
00105         C = cookies.SimpleCookie('Customer="WILE_E_COYOTE"')
00106         C['Customer']['secure'] = True
00107         C['Customer']['httponly'] = True
00108         self.assertEqual(C.output(),
00109             'Set-Cookie: Customer="WILE_E_COYOTE"; httponly; secure')

Here is the call graph for this function:


Member Data Documentation

Definition at line 12 of file test_http_cookies.py.


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