Ticket #18088: 18088.diff

File 18088.diff, 4.8 KB (added by Anssi Kääriäinen, 12 years ago)
  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index 6f1f4b9..f9527be 100644
    a b class BaseDatabaseFeatures(object):  
    405405    supports_transactions = None
    406406    supports_stddev = None
    407407    can_introspect_foreign_keys = None
     408    supports_foreign_keys = None
    408409
    409410    # Support for the DISTINCT ON clause
    410411    can_distinct_on_fields = False
    class BaseDatabaseFeatures(object):  
    418419        self.supports_transactions = self._supports_transactions()
    419420        self.supports_stddev = self._supports_stddev()
    420421        self.can_introspect_foreign_keys = self._can_introspect_foreign_keys()
     422        self.supports_foreign_keys = self._supports_foreign_keys()
    421423
    422424    def _supports_transactions(self):
    423425        "Confirm support for transactions"
    class BaseDatabaseFeatures(object):  
    448450        # which can't do it for MyISAM tables
    449451        return True
    450452
     453    def _supports_foreign_keys(self):
     454        """
     455        Check support for foreign keys.
     456        """
     457        return True
     458
    451459
    452460class BaseDatabaseOperations(object):
    453461    """
  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    index faaefca..e37fc02 100644
    a b class DatabaseFeatures(BaseDatabaseFeatures):  
    187187        "Confirm support for introspected foreign keys"
    188188        return self._mysql_storage_engine() != 'MyISAM'
    189189
     190    def _supports_foreign_keys(self):
     191        "MyISAM does not support foreign keys."
     192        return self._mysql_storage_engine() != 'MyISAM'
     193
     194
    190195class DatabaseOperations(BaseDatabaseOperations):
    191196    compiler_module = "django.db.backends.mysql.compiler"
    192197
  • django/db/backends/sqlite3/base.py

    diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
    index 0b19442..57bb567 100644
    a b class DatabaseFeatures(BaseDatabaseFeatures):  
    103103        cursor.execute('DROP TABLE STDDEV_TEST')
    104104        return has_support
    105105
     106    def _supports_foreign_keys(self):
     107        """
     108        Standard SQLite does not support foreign key constraints. However,
     109        one can compile an edition which does. Currently we just return false,
     110        but we could check if a foreign key constraint is enforced by sqlite
     111        here.
     112        """
     113        return False
     114
    106115class DatabaseOperations(BaseDatabaseOperations):
    107116    def date_extract_sql(self, lookup_type, field_name):
    108117        # sqlite doesn't support extract, so we fake it with the user-defined
  • tests/regressiontests/backends/tests.py

    diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
    index d5b1ea8..cffc4ab 100644
    a b class BackendTestCase(TestCase):  
    379379        with self.assertRaises(DatabaseError):
    380380            cursor.execute(query)
    381381
    382 # We don't make these tests conditional because that means we would need to
    383 # check and differentiate between:
    384 # * MySQL+InnoDB, MySQL+MYISAM (something we currently can't do).
    385 # * if sqlite3 (if/once we get #14204 fixed) has referential integrity turned
    386 #   on or not, something that would be controlled by runtime support and user
    387 #   preference.
    388 # verify if its type is django.database.db.IntegrityError.
    389382
    390383class FkConstraintsTests(TransactionTestCase):
    391384
    class FkConstraintsTests(TransactionTestCase):  
    393386        # Create a Reporter.
    394387        self.r = models.Reporter.objects.create(first_name='John', last_name='Smith')
    395388
     389    @skipUnlessDBFeature('supports_foreign_keys')
    396390    def test_integrity_checks_on_creation(self):
    397391        """
    398392        Try to create a model instance that violates a FK constraint. If it
    399393        fails it should fail with IntegrityError.
    400394        """
    401395        a = models.Article(headline="This is a test", pub_date=datetime.datetime(2005, 7, 27), reporter_id=30)
    402         try:
     396        with self.assertRaises(IntegrityError):
    403397            a.save()
    404         except IntegrityError:
    405             return
    406         self.skipTest("This backend does not support integrity checks.")
    407398
     399    @skipUnlessDBFeature('supports_foreign_keys')
    408400    def test_integrity_checks_on_update(self):
    409401        """
    410402        Try to update a model instance introducing a FK constraint violation.
    class FkConstraintsTests(TransactionTestCase):  
    415407        # Retrive it from the DB
    416408        a = models.Article.objects.get(headline="Test article")
    417409        a.reporter_id = 30
    418         try:
     410        with self.assertRaises(IntegrityError):
    419411            a.save()
    420         except IntegrityError:
    421             return
    422         self.skipTest("This backend does not support integrity checks.")
    423412
    424413    def test_disable_constraint_checks_manually(self):
    425414        """
Back to Top