2017-01-20 01:16:04 +08:00
|
|
|
from unittest import mock, skipUnless
|
2016-09-30 03:05:35 +08:00
|
|
|
|
2015-09-15 00:19:19 +08:00
|
|
|
from django.db import connection
|
2017-01-20 01:16:04 +08:00
|
|
|
from django.test import TestCase
|
2015-09-15 00:19:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
class TestDatabaseFeatures(TestCase):
|
|
|
|
|
|
|
|
def test_nonexistent_feature(self):
|
|
|
|
self.assertFalse(hasattr(connection.features, 'nonexistent'))
|
2016-09-30 03:05:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
@skipUnless(connection.vendor == 'mysql', 'MySQL backend tests')
|
|
|
|
class TestMySQLFeatures(TestCase):
|
|
|
|
|
|
|
|
def test_mysql_supports_transactions(self):
|
|
|
|
"""
|
|
|
|
All storage engines except MyISAM support transactions.
|
|
|
|
"""
|
|
|
|
with mock.patch('django.db.connection.features._mysql_storage_engine', 'InnoDB'):
|
|
|
|
self.assertTrue(connection.features.supports_transactions)
|
|
|
|
del connection.features.supports_transactions
|
|
|
|
with mock.patch('django.db.connection.features._mysql_storage_engine', 'MyISAM'):
|
|
|
|
self.assertFalse(connection.features.supports_transactions)
|
|
|
|
del connection.features.supports_transactions
|