MCPcopy Index your code
hub / github.com/python/cpython / test_setter

Method test_setter

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

Source from the content-addressed store, hash-verified

374 M.__setitem__, i, '%s_value' % i)
375
376 def test_setter(self):
377 M = cookies.Morsel()
378 # tests the .set method to set keys and their values
379 for i in M._reserved:
380 # Makes sure that all reserved keys can't be set this way
381 self.assertRaises(cookies.CookieError,
382 M.set, i, '%s_value' % i, '%s_value' % i)
383 for i in "thou cast _the- !holy! ^hand| +*grenade~".split():
384 # Try typical use case. Setting decent values.
385 # Check output and js_output.
386 M['path'] = '/foo' # Try a reserved key as well
387 M.set(i, "%s_val" % i, "%s_coded_val" % i)
388 self.assertEqual(M.key, i)
389 self.assertEqual(M.value, "%s_val" % i)
390 self.assertEqual(M.coded_value, "%s_coded_val" % i)
391 self.assertEqual(
392 M.output(),
393 "Set-Cookie: %s=%s; Path=/foo" % (i, "%s_coded_val" % i))
394 expected_js_output = """
395 <script type="text/javascript">
396 <!-- begin hiding
397 document.cookie = "%s=%s; Path=/foo";
398 // end hiding -->
399 </script>
400 """ % (i, "%s_coded_val" % i)
401 self.assertEqual(M.js_output(), expected_js_output)
402 for i in ["foo bar", "foo@bar"]:
403 # Try some illegal characters
404 self.assertRaises(cookies.CookieError,
405 M.set, i, '%s_value' % i, '%s_value' % i)
406
407 def test_set_properties(self):
408 morsel = cookies.Morsel()

Callers

nothing calls this directly

Calls 6

setMethod · 0.95
outputMethod · 0.95
js_outputMethod · 0.95
assertRaisesMethod · 0.45
splitMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected