Ticket #17055: fix_mysql_test_errors.diff

File fix_mysql_test_errors.diff, 8.0 KB (added by Jim Dalton, 13 years ago)
  • django/contrib/auth/tokens.py

    diff --git a/django/contrib/auth/tokens.py b/django/contrib/auth/tokens.py
    index a75ef61..735e95b 100644
    a b  
    1 from datetime import date
     1from datetime import date, timedelta
    22from django.conf import settings
    33from django.utils.http import int_to_base36, base36_to_int
    44from django.utils.crypto import constant_time_compare, salted_hmac
    class PasswordResetTokenGenerator(object):  
    5252        # invalid as soon as it is used.
    5353        # We limit the hash to 20 chars to keep URL short
    5454        key_salt = "django.contrib.auth.tokens.PasswordResetTokenGenerator"
     55
     56        # Ensure consistent timestamps across DB backends
     57        last_login = user.last_login - timedelta(microseconds=user.last_login.microsecond)
     58
    5559        value = (unicode(user.id) + user.password +
    56                 unicode(user.last_login) + unicode(timestamp))
     60                unicode(last_login) + unicode(timestamp))
    5761        hash = salted_hmac(key_salt, value).hexdigest()[::2]
    5862        return "%s-%s" % (ts_b36, hash)
    5963
  • django/core/management/commands/loaddata.py

    diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
    index 7b0e30f..0fe20ec 100644
    a b from __future__ import with_statement  
    55import sys
    66import os
    77import gzip
     8import warnings
    89import zipfile
    910from optparse import make_option
     11import MySQLdb
    1012
    1113from django.conf import settings
    1214from django.core import serializers
    class Command(BaseCommand):  
    179181                                            loaded_objects_in_fixture += 1
    180182                                            models.add(obj.object.__class__)
    181183                                            try:
    182                                                 obj.save(using=using)
    183                                             except (DatabaseError, IntegrityError), e:
     184                                                with warnings.catch_warnings():
     185                                                    warnings.filterwarnings('error', category=MySQLdb.Warning)
     186                                                    obj.save(using=using)
     187                                            except (DatabaseError, IntegrityError, Warning), e:
    184188                                                msg = "Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)s" % {
    185189                                                        'app_label': obj.object._meta.app_label,
    186190                                                        'object_name': obj.object._meta.object_name,
  • tests/modeltests/fixtures/tests.py

    diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py
    index 54ce470..46d231f 100644
    a b class FixtureLoadingTests(TestCase):  
    263263        new_io = StringIO.StringIO()
    264264        management.call_command('loaddata', 'invalid.json', verbosity=0, stderr=new_io, commit=False)
    265265        output = new_io.getvalue().strip().split('\n')
    266         self.assertRegexpMatches(output[-1], "IntegrityError: Could not load fixtures.Article\(pk=1\): .*$")
     266        self.assertRegexpMatches(output[-1], "(IntegrityError|Warning): Could not load fixtures.Article\(pk=1\): .*$")
    267267
    268268    def test_loading_using(self):
    269269        # Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
  • tests/regressiontests/admin_scripts/tests.py

    diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
    index 8580e36..b85f5d3 100644
    a b class ManageAlternateSettings(AdminScriptTestCase):  
    864864        "alternate: manage.py builtin commands work with settings provided as argument"
    865865        args = ['sqlall','--settings=alternate_settings', 'admin_scripts']
    866866        out, err = self.run_manage(args)
    867         self.assertOutput(out, 'CREATE TABLE "admin_scripts_article"')
     867        self.assertRegexpMatches(out,  'CREATE TABLE (`|")admin_scripts_article(`|")')
    868868        self.assertNoOutput(err)
    869869
    870870    def test_builtin_with_environment(self):
    871871        "alternate: manage.py builtin commands work if settings are provided in the environment"
    872872        args = ['sqlall','admin_scripts']
    873873        out, err = self.run_manage(args,'alternate_settings')
    874         self.assertOutput(out, 'CREATE TABLE "admin_scripts_article"')
     874        self.assertRegexpMatches(out,  'CREATE TABLE (`|")admin_scripts_article(`|")')
    875875        self.assertNoOutput(err)
    876876
    877877    def test_builtin_with_bad_settings(self):
  • tests/regressiontests/i18n/tests.py

    diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
    index fc69d9c..6180b49 100644
    a b from django.utils.translation import (ugettext, ugettext_lazy, activate,  
    2121    deactivate, gettext_lazy, pgettext, npgettext, to_locale,
    2222    get_language_info, get_language, get_language_from_request)
    2323
     24# Keep as a * import because of conditional imports in .commands.tests
     25from .commands.tests import *
    2426
    25 from .commands.tests import NoWrapExtractorTests, IgnoredExtractorTests, MessageCompilationTests, PoFileTests, BasicExtractorTests, JavascriptExtractorTests, CopyPluralFormsExtractorTests, SymlinkExtractorTests, ExtractorTests
    2627from .contenttypes.tests import ContentTypeTests
    2728from .forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm
    2829from .models import Company, TestModel
  • tests/regressiontests/multiple_database/tests.py

    diff --git a/tests/regressiontests/multiple_database/tests.py b/tests/regressiontests/multiple_database/tests.py
    index 741cba4..b8fab2e 100644
    a b from .models import Book, Person, Pet, Review, UserProfile  
    1717class QueryTestCase(TestCase):
    1818    multi_db = True
    1919
     20    def setUp(self):
     21        # Disable constraint checking
     22        for connection_name in connections:
     23            connection = connections[connection_name]
     24            connection.disable_constraint_checking()
     25
     26    def tearDown(self):
     27        # Re-enable constraint checking
     28        for connection_name in connections:
     29            connection = connections[connection_name]
     30            connection.enable_constraint_checking()
     31
    2032    def test_db_selection(self):
    2133        "Check that querysets will use the default database by default"
    2234        self.assertEqual(Book.objects.db, DEFAULT_DB_ALIAS)
    class RouterTestCase(TestCase):  
    976988        self.old_routers = router.routers
    977989        router.routers = [TestRouter()]
    978990
     991        # Disable constraint checking
     992        for connection_name in connections:
     993            connection = connections[connection_name]
     994            connection.disable_constraint_checking()
     995
    979996    def tearDown(self):
    980997        # Restore the 'other' database as an independent database
    981998        router.routers = self.old_routers
    982999
     1000        # Re-enable constraint checking
     1001        for connection_name in connections:
     1002            connection = connections[connection_name]
     1003            connection.enable_constraint_checking()
     1004
    9831005    def test_db_selection(self):
    9841006        "Check that querysets obey the router for db suggestions"
    9851007        self.assertEqual(Book.objects.db, 'other')
    class SignalTests(TestCase):  
    16951717    def setUp(self):
    16961718        self.old_routers = router.routers
    16971719
     1720        # Disable constraint checking
     1721        for connection_name in connections:
     1722            connection = connections[connection_name]
     1723            connection.disable_constraint_checking()
     1724
    16981725    def tearDown(self):
    16991726        router.routers = self.old_routers
    17001727
     1728        # Re-enable constraint checking
     1729        for connection_name in connections:
     1730            connection = connections[connection_name]
     1731            connection.enable_constraint_checking()
     1732
    17011733    def _write_to_other(self):
    17021734        "Sends all writes to 'other'."
    17031735        router.routers = [WriteToOtherRouter()]
Back to Top