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
|
2018-05-19 07:37:36 +08:00
|
|
|
from django.db.backends.mysql.features import DatabaseFeatures
|
2017-01-20 01:16:04 +08:00
|
|
|
from django.test import TestCase
|
2015-09-15 00:19:19 +08:00
|
|
|
|
|
|
|
|
2017-02-12 04:37:49 +08:00
|
|
|
@skipUnless(connection.vendor == 'mysql', 'MySQL tests')
|
|
|
|
class TestFeatures(TestCase):
|
2015-09-15 00:19:19 +08:00
|
|
|
|
2017-02-12 04:37:49 +08:00
|
|
|
def test_supports_transactions(self):
|
2016-09-30 03:05:35 +08:00
|
|
|
"""
|
|
|
|
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
|
2018-05-19 07:37:36 +08:00
|
|
|
|
|
|
|
def test_skip_locked_no_wait(self):
|
|
|
|
with mock.MagicMock() as _connection:
|
|
|
|
_connection.mysql_version = (8, 0, 1)
|
2018-07-10 02:59:42 +08:00
|
|
|
_connection.mysql_is_mariadb = False
|
2018-05-19 07:37:36 +08:00
|
|
|
database_features = DatabaseFeatures(_connection)
|
|
|
|
self.assertTrue(database_features.has_select_for_update_skip_locked)
|
|
|
|
self.assertTrue(database_features.has_select_for_update_nowait)
|
|
|
|
with mock.MagicMock() as _connection:
|
|
|
|
_connection.mysql_version = (8, 0, 0)
|
2018-07-10 02:59:42 +08:00
|
|
|
_connection.mysql_is_mariadb = False
|
2018-05-19 07:37:36 +08:00
|
|
|
database_features = DatabaseFeatures(_connection)
|
|
|
|
self.assertFalse(database_features.has_select_for_update_skip_locked)
|
|
|
|
self.assertFalse(database_features.has_select_for_update_nowait)
|