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
|
|
|
|
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)
|
2023-11-26 23:36:56 +00:00
|
|
|
|
|
|
|
def test_allows_group_by_selected_pks(self):
|
|
|
|
with mock.MagicMock() as _connection:
|
|
|
|
_connection.mysql_is_mariadb = False
|
|
|
|
database_features = DatabaseFeatures(_connection)
|
|
|
|
self.assertIs(database_features.allows_group_by_selected_pks, True)
|
|
|
|
|
|
|
|
with mock.MagicMock() as _connection:
|
|
|
|
_connection.mysql_is_mariadb = False
|
|
|
|
_connection.sql_mode = {}
|
|
|
|
database_features = DatabaseFeatures(_connection)
|
|
|
|
self.assertIs(database_features.allows_group_by_selected_pks, True)
|
|
|
|
|
|
|
|
with mock.MagicMock() as _connection:
|
|
|
|
_connection.mysql_is_mariadb = True
|
|
|
|
_connection.sql_mode = {"ONLY_FULL_GROUP_BY"}
|
|
|
|
database_features = DatabaseFeatures(_connection)
|
|
|
|
self.assertIs(database_features.allows_group_by_selected_pks, False)
|