Back to index

python3.2  3.2.2
Public Member Functions
test.test_http_cookies.MorselTests Class Reference

List of all members.

Public Member Functions

def test_reserved_keys
def test_setter

Detailed Description

Tests for the Morsel object.

Definition at line 135 of file test_http_cookies.py.


Member Function Documentation

Definition at line 138 of file test_http_cookies.py.

00138 
00139     def test_reserved_keys(self):
00140         M = cookies.Morsel()
00141         # tests valid and invalid reserved keys for Morsels
00142         for i in M._reserved:
00143             # Test that all valid keys are reported as reserved and set them
00144             self.assertTrue(M.isReservedKey(i))
00145             M[i] = '%s_value' % i
00146         for i in M._reserved:
00147             # Test that valid key values come out fine
00148             self.assertEqual(M[i], '%s_value' % i)
00149         for i in "the holy hand grenade".split():
00150             # Test that invalid keys raise CookieError
00151             self.assertRaises(cookies.CookieError,
00152                               M.__setitem__, i, '%s_value' % i)

Here is the call graph for this function:

Definition at line 153 of file test_http_cookies.py.

00153 
00154     def test_setter(self):
00155         M = cookies.Morsel()
00156         # tests the .set method to set keys and their values
00157         for i in M._reserved:
00158             # Makes sure that all reserved keys can't be set this way
00159             self.assertRaises(cookies.CookieError,
00160                               M.set, i, '%s_value' % i, '%s_value' % i)
00161         for i in "thou cast _the- !holy! ^hand| +*grenade~".split():
00162             # Try typical use case. Setting decent values.
00163             # Check output and js_output.
00164             M['path'] = '/foo' # Try a reserved key as well
00165             M.set(i, "%s_val" % i, "%s_coded_val" % i)
00166             self.assertEqual(
00167                 M.output(),
00168                 "Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i))
00169             expected_js_output = """
00170         <script type="text/javascript">
00171         <!-- begin hiding
00172         document.cookie = "%s=%s; Path=/foo";
00173         // end hiding -->
00174         </script>
00175         """ % (i, "%s_coded_val" % i)
00176             self.assertEqual(M.js_output(), expected_js_output)
00177         for i in ["foo bar", "foo@bar"]:
00178             # Try some illegal characters
00179             self.assertRaises(cookies.CookieError,
00180                               M.set, i, '%s_value' % i, '%s_value' % i)
00181 

Here is the call graph for this function:


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