diff options
| author | Gary Wilson Jr <gary.wilson@gmail.com> | 2008-08-02 05:56:57 +0000 |
|---|---|---|
| committer | Gary Wilson Jr <gary.wilson@gmail.com> | 2008-08-02 05:56:57 +0000 |
| commit | c85c8f88914cdba05813cc5768377841340bd09d (patch) | |
| tree | 58f61ee33072b70256a448f7df7333109adf1936 /tests | |
| parent | 8a58f2216cb2897db53ad166d71393fef1181c1a (diff) | |
Fixed #7919 -- md5 and sha modules are deprecated since Python 2.5, use hashlib module when available. Patch from Karen Tracey.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8193 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/cache/tests.py | 33 | ||||
| -rw-r--r-- | tests/regressiontests/file_uploads/tests.py | 6 | ||||
| -rw-r--r-- | tests/regressiontests/test_client_regress/models.py | 10 |
3 files changed, 24 insertions, 25 deletions
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index f050348c77..78c32288b6 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -3,11 +3,17 @@ # Unit tests for cache framework # Uses whatever cache backend is set in the test settings file. +import os +import shutil +import tempfile import time import unittest + from django.core.cache import cache -from django.utils.cache import patch_vary_headers +from django.core.cache.backends.filebased import CacheClass as FileCache from django.http import HttpResponse +from django.utils.cache import patch_vary_headers +from django.utils.hashcompat import md5_constructor # functions/classes for complex data type tests def f(): @@ -27,7 +33,7 @@ class Cache(unittest.TestCase): cache.add("addkey1", "value") cache.add("addkey1", "newvalue") self.assertEqual(cache.get("addkey1"), "value") - + def test_non_existent(self): # get with non-existent keys self.assertEqual(cache.get("does_not_exist"), None) @@ -80,9 +86,9 @@ class Cache(unittest.TestCase): cache.set('expire2', 'very quickly', 1) cache.set('expire3', 'very quickly', 1) - time.sleep(2) + time.sleep(2) self.assertEqual(cache.get("expire1"), None) - + cache.add("expire2", "newvalue") self.assertEqual(cache.get("expire2"), "newvalue") self.assertEqual(cache.has_key("expire3"), False) @@ -98,11 +104,6 @@ class Cache(unittest.TestCase): cache.set(key, value) self.assertEqual(cache.get(key), value) -import os -import md5 -import shutil -import tempfile -from django.core.cache.backends.filebased import CacheClass as FileCache class FileBasedCacheTests(unittest.TestCase): """ @@ -112,23 +113,23 @@ class FileBasedCacheTests(unittest.TestCase): self.dirname = tempfile.mktemp() os.mkdir(self.dirname) self.cache = FileCache(self.dirname, {}) - + def tearDown(self): shutil.rmtree(self.dirname) - + def test_hashing(self): """Test that keys are hashed into subdirectories correctly""" self.cache.set("foo", "bar") - keyhash = md5.new("foo").hexdigest() + keyhash = md5_constructor("foo").hexdigest() keypath = os.path.join(self.dirname, keyhash[:2], keyhash[2:4], keyhash[4:]) self.assert_(os.path.exists(keypath)) - + def test_subdirectory_removal(self): """ Make sure that the created subdirectories are correctly removed when empty. """ self.cache.set("foo", "bar") - keyhash = md5.new("foo").hexdigest() + keyhash = md5_constructor("foo").hexdigest() keypath = os.path.join(self.dirname, keyhash[:2], keyhash[2:4], keyhash[4:]) self.assert_(os.path.exists(keypath)) @@ -139,9 +140,9 @@ class FileBasedCacheTests(unittest.TestCase): class CacheUtils(unittest.TestCase): """TestCase for django.utils.cache functions.""" - + def test_patch_vary_headers(self): - headers = ( + headers = ( # Initial vary, new headers, resulting vary. (None, ('Accept-Encoding',), 'Accept-Encoding'), ('Accept-Encoding', ('accept-encoding',), 'Accept-Encoding'), diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py index aada1e1ff2..dd6b7c4181 100644 --- a/tests/regressiontests/file_uploads/tests.py +++ b/tests/regressiontests/file_uploads/tests.py @@ -1,6 +1,5 @@ import os import errno -import sha import shutil import unittest @@ -8,6 +7,7 @@ from django.core.files import temp as tempfile from django.core.files.uploadedfile import SimpleUploadedFile from django.test import TestCase, client from django.utils import simplejson +from django.utils.hashcompat import sha_constructor from models import FileModel, UPLOAD_ROOT, UPLOAD_TO @@ -45,10 +45,10 @@ class FileUploadTests(TestCase): for key in post_data.keys(): try: - post_data[key + '_hash'] = sha.new(post_data[key].read()).hexdigest() + post_data[key + '_hash'] = sha_constructor(post_data[key].read()).hexdigest() post_data[key].seek(0) except AttributeError: - post_data[key + '_hash'] = sha.new(post_data[key]).hexdigest() + post_data[key + '_hash'] = sha_constructor(post_data[key]).hexdigest() response = self.client.post('/file_uploads/verify/', post_data) diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py index 47e34641fb..3518df3b9f 100644 --- a/tests/regressiontests/test_client_regress/models.py +++ b/tests/regressiontests/test_client_regress/models.py @@ -1,12 +1,10 @@ """ Regression tests for the Test Client, especially the customized assertions. - """ + from django.test import Client, TestCase from django.core.urlresolvers import reverse from django.core.exceptions import SuspiciousOperation -import os -import sha class AssertContainsTests(TestCase): def test_contains(self): @@ -24,7 +22,7 @@ class AssertContainsTests(TestCase): self.assertNotContains(response, 'once') except AssertionError, e: self.assertEquals(str(e), "Response should not contain 'once'") - + try: self.assertContains(response, 'never', 1) except AssertionError, e: @@ -287,7 +285,7 @@ class URLEscapingTests(TestCase): class ExceptionTests(TestCase): fixtures = ['testdata.json'] - + def test_exception_cleared(self): "#5836 - A stale user exception isn't re-raised by the test client." @@ -300,7 +298,7 @@ class ExceptionTests(TestCase): pass # At this point, an exception has been raised, and should be cleared. - + # This next operation should be successful; if it isn't we have a problem. login = self.client.login(username='staff', password='password') self.failUnless(login, 'Could not log in') |
