1
0
mirror of https://github.com/django/django.git synced 2025-01-20 07:13:44 +00:00
django/tests/backends/mysql/test_features.py
Nathaniel Conroy d9ba8fa397 [5.0.x] Fixed #34992 -- Fixed DatabaseFeatures.allows_group_by_selected_pks on MariaDB with ONLY_FULL_GROUP_BY sql mode.
Regression in 041551d716b69ee7c81199eee86a2d10a72e15ab.

Backport of 0257426fe1fe9d146fd5813f09d909917ff59360 from main
2023-11-27 10:34:42 +01:00

49 lines
2.0 KiB
Python

from unittest import mock, skipUnless
from django.db import connection
from django.db.backends.mysql.features import DatabaseFeatures
from django.test import TestCase
@skipUnless(connection.vendor == "mysql", "MySQL tests")
class TestFeatures(TestCase):
def test_supports_transactions(self):
"""
All storage engines except MyISAM support transactions.
"""
del connection.features.supports_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
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)
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)