Ticket #16222: ticket16222.diff

File ticket16222.diff, 1.6 KB (added by Jure Cuhalev <gandalf@…>, 13 years ago)

Test was failing because of the race condition that occurred now that there's a higher time precision. Fixed the test to check unsigned values and added additional asserts so that max_age condition gets checked.

  • django/contrib/formtools/wizard/tests/cookiestoragetests.py

    diff --git a/django/contrib/formtools/wizard/tests/cookiestoragetests.py b/django/contrib/formtools/wizard/tests/cookiestoragetests.py
    index 74c7e82..6ad9bce 100644
    a b class TestCookieStorage(TestStorage, TestCase):  
    2525        self.assertRaises(SuspiciousOperation, storage.load_data)
    2626
    2727    def test_reset_cookie(self):
     28        from django.core.signing import SignatureExpired
    2829        request = get_request()
    2930        storage = self.get_storage()('wizard1', request, None)
    3031
    class TestCookieStorage(TestStorage, TestCase):  
    3536
    3637        cookie_signer = signing.get_cookie_signer(storage.prefix)
    3738        signed_cookie_data = cookie_signer.sign(storage.encoder.encode(storage.data))
    38         self.assertEqual(response.cookies[storage.prefix].value, signed_cookie_data)
     39
     40        # signing with different timestamps generates different signatures
     41        self.assertNotEqual(response.cookies[storage.prefix].value, signed_cookie_data)
     42        self.assertEqual(cookie_signer.unsign(response.cookies[storage.prefix].value),
     43                         cookie_signer.unsign(signed_cookie_data))
     44        self.assertRaises(SignatureExpired,
     45                          lambda: cookie_signer.unsign(value=response.cookies[storage.prefix].value, max_age=0))
     46        self.assertEqual(cookie_signer.unsign(value=response.cookies[storage.prefix].value, max_age=10),
     47                         cookie_signer.unsign(signed_cookie_data))
    3948
    4049        storage.init_data()
    4150        storage.update_response(response)
Back to Top