Ticket #23947: 23947.diff

File 23947.diff, 10.3 KB (added by Diego Guimarães, 10 years ago)

initial patch

  • django/test/utils.py

    diff --git a/django/test/utils.py b/django/test/utils.py
    index 619f9cd..a79b9f3 100644
    a b def captured_stdin():  
    541541       self.assertEqual(captured, "hello")
    542542    """
    543543    return captured_output("stdin")
     544
     545
     546def reset_warning_registry(pattern=".*"):
     547    """clear warning registry for all match modules.
     548    This fixes unpexpected behavior from tests when running
     549    with --reverse option"""
     550    key = "__warningregistry__"
     551    for mod in sys.modules.values():
     552        if hasattr(mod, key) and re.match(pattern, mod.__name__):
     553            getattr(mod, key).clear()
  • tests/cache/tests.py

    diff --git a/tests/cache/tests.py b/tests/cache/tests.py
    index e3ad724..5140a73 100644
    a b class GetCacheTests(IgnoreDeprecationWarningsMixin, TestCase):  
    12371237
    12381238    def test_close(self):
    12391239        from django.core import signals
     1240        from django.core.cache import get_cache
     1241        cache = get_cache('cache.closeable_cache.CacheClass')
    12401242        self.assertFalse(cache.closed)
    12411243        signals.request_finished.send(self.__class__)
    12421244        self.assertTrue(cache.closed)
    class CacheUtils(TestCase):  
    13781380    def test_get_cache_key(self):
    13791381        request = self.factory.get(self.path)
    13801382        response = HttpResponse()
    1381         key_prefix = 'localprefix'
    13821383        # Expect None if no headers have been set yet.
    1383         self.assertIsNone(get_cache_key(request))
     1384        # it was missing the response parameter.
     1385        self.assertIsNone(get_cache_key(request, response))
    13841386        # Set headers to an empty list.
    13851387        learn_cache_key(request, response)
    13861388
    class CacheUtils(TestCase):  
    13901392            '18a03f9c9649f7d684af5db3524f5c99.d41d8cd98f00b204e9800998ecf8427e'
    13911393        )
    13921394        # Verify that a specified key_prefix is taken into account.
     1395        key_prefix = 'localprefix'
    13931396        learn_cache_key(request, response, key_prefix=key_prefix)
    13941397        self.assertEqual(
    13951398            get_cache_key(request, key_prefix=key_prefix),
  • tests/deprecation/tests.py

    diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py
    index 79a6284..e0fbe12 100644
    a b import unittest  
    55import warnings
    66
    77from django.test import SimpleTestCase, RequestFactory, override_settings
     8from django.test.utils import reset_warning_registry
    89from django.utils import six, translation
    910from django.utils.deprecation import RenameMethodsBase
    1011from django.utils.encoding import force_text
    class RenameMethodsTests(SimpleTestCase):  
    2324    to `get_queryset` across the code base following #15363.
    2425    """
    2526
     27    def setUp(self):
     28        super(RenameMethodsTests, self).setUp()
     29        reset_warning_registry()
     30
    2631    def test_class_definition_warnings(self):
    2732        """
    2833        Ensure a warning is raised upon class definition to suggest renaming
  • tests/mail/tests.py

    diff --git a/tests/mail/tests.py b/tests/mail/tests.py
    index e4b5689..6173ea5 100644
    a b class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):  
    966966        backend.close()
    967967        self.assertTrue(opened)
    968968
    969     def test_server_stopped(self):
    970         """
    971         Test that closing the backend while the SMTP server is stopped doesn't
    972         raise an exception.
    973         """
    974         backend = smtp.EmailBackend(username='', password='')
    975         backend.open()
    976         self.server.stop()
    977         try:
    978             backend.close()
    979         except Exception as e:
    980             self.fail("close() unexpectedly raised an exception: %s" % e)
    981 
    982969    @override_settings(EMAIL_USE_TLS=True)
    983970    def test_email_tls_use_settings(self):
    984971        backend = smtp.EmailBackend()
    class SMTPBackendTests(BaseEmailBackendTests, SimpleTestCase):  
    11101097
    11111098        finally:
    11121099            SMTP.send = send
     1100
     1101
     1102class SMTPBackendStoppedServerTest(SimpleTestCase):
     1103    email_backend = 'django.core.mail.backends.smtp.EmailBackend'
     1104
     1105    @classmethod
     1106    def setUpClass(cls):
     1107        super(SMTPBackendStoppedTest, cls).setUpClass()
     1108        cls.server = FakeSMTPServer(('127.0.0.1', 0), None)
     1109        cls._settings_override = override_settings(
     1110            EMAIL_HOST="127.0.0.1",
     1111            EMAIL_PORT=cls.server.socket.getsockname()[1])
     1112        cls._settings_override.enable()
     1113        cls.server.start()
     1114
     1115    @classmethod
     1116    def tearDownClass(cls):
     1117        cls._settings_override.disable()
     1118        cls.server.stop()
     1119        super(SMTPBackendStoppedTest, cls).tearDownClass()
     1120
     1121    def test_server_stopped(self):
     1122        """
     1123        Test that closing the backend while the SMTP server is stopped doesn't
     1124        raise an exception.
     1125        """
     1126        backend = smtp.EmailBackend(username='', password='')
     1127        backend.open()
     1128        self.server.stop()
     1129        try:
     1130            backend.close()
     1131        except Exception as e:
     1132            self.fail("close() unexpectedly raised an exception: %s" % e)
  • tests/modeladmin/tests.py

    diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
    index 93cb58a..9085f68 100644
    a b class ListDisplayEditableTests(CheckTestCase):  
    15461546
    15471547class ModelAdminPermissionTests(TestCase):
    15481548
     1549    def setUp(self):
     1550        """
     1551        When running tests with --reverse, the last test changes the app label,
     1552        what interferes with the following results
     1553        """
     1554        self.model_admin = ModelAdmin(Band, AdminSite())
     1555        self.model_admin.opts.app_label = 'modeladmin'
     1556
    15491557    class MockUser(object):
    15501558        def has_module_perms(self, app_label):
    15511559            if app_label == "modeladmin":
    class ModelAdminPermissionTests(TestCase):  
    15751583        Ensure that has_add_permission returns True for users who can add
    15761584        objects and False for users who can't.
    15771585        """
    1578         ma = ModelAdmin(Band, AdminSite())
    15791586        request = MockRequest()
    15801587        request.user = self.MockAddUser()
    1581         self.assertTrue(ma.has_add_permission(request))
     1588        self.assertTrue(self.model_admin.has_add_permission(request))
    15821589        request.user = self.MockChangeUser()
    1583         self.assertFalse(ma.has_add_permission(request))
     1590        self.assertFalse(self.model_admin.has_add_permission(request))
    15841591        request.user = self.MockDeleteUser()
    1585         self.assertFalse(ma.has_add_permission(request))
     1592        self.assertFalse(self.model_admin.has_add_permission(request))
    15861593
    15871594    def test_has_change_permission(self):
    15881595        """
    15891596        Ensure that has_change_permission returns True for users who can edit
    15901597        objects and False for users who can't.
    15911598        """
    1592         ma = ModelAdmin(Band, AdminSite())
    15931599        request = MockRequest()
    15941600        request.user = self.MockAddUser()
    1595         self.assertFalse(ma.has_change_permission(request))
     1601        self.assertFalse(self.model_admin.has_change_permission(request))
    15961602        request.user = self.MockChangeUser()
    1597         self.assertTrue(ma.has_change_permission(request))
     1603        self.assertTrue(self.model_admin.has_change_permission(request))
    15981604        request.user = self.MockDeleteUser()
    1599         self.assertFalse(ma.has_change_permission(request))
     1605        self.assertFalse(self.model_admin.has_change_permission(request))
    16001606
    16011607    def test_has_delete_permission(self):
    16021608        """
    16031609        Ensure that has_delete_permission returns True for users who can delete
    16041610        objects and False for users who can't.
    16051611        """
    1606         ma = ModelAdmin(Band, AdminSite())
    16071612        request = MockRequest()
    16081613        request.user = self.MockAddUser()
    1609         self.assertFalse(ma.has_delete_permission(request))
     1614        self.assertFalse(self.model_admin.has_delete_permission(request))
    16101615        request.user = self.MockChangeUser()
    1611         self.assertFalse(ma.has_delete_permission(request))
     1616        self.assertFalse(self.model_admin.has_delete_permission(request))
    16121617        request.user = self.MockDeleteUser()
    1613         self.assertTrue(ma.has_delete_permission(request))
     1618        self.assertTrue(self.model_admin.has_delete_permission(request))
    16141619
    16151620    def test_has_module_permission(self):
    16161621        """
    16171622        Ensure that has_module_permission returns True for users who have any
    16181623        permission for the module and False for users who don't.
    16191624        """
    1620         ma = ModelAdmin(Band, AdminSite())
    16211625        request = MockRequest()
    16221626        request.user = self.MockAddUser()
    1623         self.assertTrue(ma.has_module_permission(request))
     1627        self.assertTrue(self.model_admin.has_module_permission(request))
    16241628        request.user = self.MockChangeUser()
    1625         self.assertTrue(ma.has_module_permission(request))
     1629        self.assertTrue(self.model_admin.has_module_permission(request))
    16261630        request.user = self.MockDeleteUser()
    1627         self.assertTrue(ma.has_module_permission(request))
    1628         ma.opts.app_label = "anotherapp"
     1631        self.assertTrue(self.model_admin.has_module_permission(request))
     1632        self.model_admin.opts.app_label = 'anotherapp'
    16291633        request.user = self.MockAddUser()
    1630         self.assertFalse(ma.has_module_permission(request))
     1634        self.assertFalse(self.model_admin.has_module_permission(request))
    16311635        request.user = self.MockChangeUser()
    1632         self.assertFalse(ma.has_module_permission(request))
     1636        self.assertFalse(self.model_admin.has_module_permission(request))
    16331637        request.user = self.MockDeleteUser()
    1634         self.assertFalse(ma.has_module_permission(request))
     1638        self.assertFalse(self.model_admin.has_module_permission(request))
  • tests/utils_tests/test_text.py

    diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py
    index 4ef3031..a43870f 100644
    a b from unittest import skipUnless  
    55import warnings
    66
    77from django.test import SimpleTestCase
     8from django.test.utils import reset_warning_registry
    89from django.utils import six, text
    910from django.utils.deprecation import RemovedInDjango19Warning
    1011from django.utils.encoding import force_text
    IS_WIDE_BUILD = (len('\U0001F4A9') == 1)  
    1819
    1920class TestUtilsText(SimpleTestCase):
    2021
     22    def setUp(self):
     23        super(TestUtilsText, self).setUp()
     24        reset_warning_registry()
     25
    2126    def test_get_text_list(self):
    2227        self.assertEqual(text.get_text_list(['a', 'b', 'c', 'd']), 'a, b, c or d')
    2328        self.assertEqual(text.get_text_list(['a', 'b', 'c'], 'and'), 'a, b and c')
Back to Top