~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to tests/regressiontests/httpwrappers/tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
465
465
[u'1', u'2', u'3', u'4']
466
466
"""
467
467
 
468
 
from django.http import QueryDict, HttpResponse
 
468
from django.http import QueryDict, HttpResponse, CompatCookie
 
469
from django.test import TestCase
 
470
 
 
471
 
 
472
class Cookies(TestCase):
 
473
 
 
474
    def test_encode(self):
 
475
        """
 
476
        Test that we don't output tricky characters in encoded value
 
477
        """
 
478
        # Python 2.4 compatibility note: Python 2.4's cookie implementation
 
479
        # always returns Set-Cookie headers terminating in semi-colons.
 
480
        # That's not the bug this test is looking for, so ignore it.
 
481
        c = CompatCookie()
 
482
        c['test'] = "An,awkward;value"
 
483
        self.assert_(";" not in c.output().rstrip(';')) # IE compat
 
484
        self.assert_("," not in c.output().rstrip(';')) # Safari compat
 
485
 
 
486
    def test_decode(self):
 
487
        """
 
488
        Test that we can still preserve semi-colons and commas
 
489
        """
 
490
        c = CompatCookie()
 
491
        c['test'] = "An,awkward;value"
 
492
        c2 = CompatCookie()
 
493
        c2.load(c.output())
 
494
        self.assertEqual(c['test'].value, c2['test'].value)
 
495
 
 
496
    def test_decode_2(self):
 
497
        """
 
498
        Test that we haven't broken normal encoding
 
499
        """
 
500
        c = CompatCookie()
 
501
        c['test'] = "\xf0"
 
502
        c2 = CompatCookie()
 
503
        c2.load(c.output())
 
504
        self.assertEqual(c['test'].value, c2['test'].value)
469
505
 
470
506
if __name__ == "__main__":
471
507
    import doctest