mirror of
https://github.com/django/django.git
synced 2025-07-24 05:36:15 +00:00
Refs #31331 -- Added DatabaseWrapper.sql_mode to MySQL.
This commit is contained in:
parent
7b8fa1653f
commit
a19505eb2e
3 changed files with 17 additions and 6 deletions
|
@ -2,7 +2,7 @@ import unittest
|
|||
from unittest import mock
|
||||
|
||||
from django.core.checks.database import check_database_backends
|
||||
from django.db import connection
|
||||
from django.db import connection, connections
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
|
@ -18,6 +18,12 @@ class DatabaseCheckTests(TestCase):
|
|||
|
||||
@unittest.skipUnless(connection.vendor == 'mysql', 'Test only for MySQL')
|
||||
def test_mysql_strict_mode(self):
|
||||
def _clean_sql_mode():
|
||||
for alias in self.databases:
|
||||
if hasattr(connections[alias], 'sql_mode'):
|
||||
del connections[alias].sql_mode
|
||||
|
||||
_clean_sql_mode()
|
||||
good_sql_modes = [
|
||||
'STRICT_TRANS_TABLES,STRICT_ALL_TABLES',
|
||||
'STRICT_TRANS_TABLES',
|
||||
|
@ -29,6 +35,7 @@ class DatabaseCheckTests(TestCase):
|
|||
return_value=(response,)
|
||||
):
|
||||
self.assertEqual(check_database_backends(databases=self.databases), [])
|
||||
_clean_sql_mode()
|
||||
|
||||
bad_sql_modes = ['', 'WHATEVER']
|
||||
for response in bad_sql_modes:
|
||||
|
@ -40,3 +47,4 @@ class DatabaseCheckTests(TestCase):
|
|||
result = check_database_backends(databases=self.databases)
|
||||
self.assertEqual(len(result), 2)
|
||||
self.assertEqual([r.id for r in result], ['mysql.W002', 'mysql.W002'])
|
||||
_clean_sql_mode()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue