2017-01-19 17:16:04 +00:00
|
|
|
from unittest import mock, skipUnless
|
2016-09-29 19:05:35 +00:00
|
|
|
|
2015-09-14 16:19:19 +00:00
|
|
|
from django.db import connection
|
2018-05-18 23:37:36 +00:00
|
|
|
from django.db.backends.mysql.features import DatabaseFeatures
|
2017-01-19 17:16:04 +00:00
|
|
|
from django.test import TestCase
|
2015-09-14 16:19:19 +00:00
|
|
|
|
|
|
|
|
2017-02-11 20:37:49 +00:00
|
|
|
@skipUnless(connection.vendor == "mysql", "MySQL tests")
|
|
|
|
class TestFeatures(TestCase):
|
|
|
|
def test_supports_transactions(self):
|
2016-09-29 19:05:35 +00:00
|
|
|
"""
|
|
|
|
All storage engines except MyISAM support transactions.
|
|
|
|
"""
|
2022-04-14 07:53:31 +00:00
|
|
|
del connection.features.supports_transactions
|
2016-09-29 19:05:35 +00:00
|
|
|
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-18 23:37:36 +00:00
|
|
|
|
|
|
|
def test_skip_locked_no_wait(self):
|
|
|
|
with mock.MagicMock() as _connection:
|
|
|
|
_connection.mysql_version = (8, 0, 1)
|
2018-07-09 18:59:42 +00:00
|
|
|
_connection.mysql_is_mariadb = False
|
2018-05-18 23:37:36 +00: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-09 18:59:42 +00:00
|
|
|
_connection.mysql_is_mariadb = False
|
2018-05-18 23:37:36 +00:00
|
|
|
database_features = DatabaseFeatures(_connection)
|
|
|
|
self.assertFalse(database_features.has_select_for_update_skip_locked)
|
|
|
|
self.assertFalse(database_features.has_select_for_update_nowait)
|
2020-07-20 07:48:31 +00:00
|
|
|
|
|
|
|
def test_allows_auto_pk_0(self):
|
|
|
|
with mock.MagicMock() as _connection:
|
|
|
|
_connection.sql_mode = {"NO_AUTO_VALUE_ON_ZERO"}
|
|
|
|
database_features = DatabaseFeatures(_connection)
|
|
|
|
self.assertIs(database_features.allows_auto_pk_0, True)
|