-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to verify charset, collation and engines match
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# test_db_settings.py | ||
import pytest | ||
from django.db import connection | ||
from django.conf import settings | ||
|
||
@pytest.mark.django_db | ||
def test_character_set_and_storage_engine(): | ||
with connection.cursor() as cursor: | ||
if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.mysql': | ||
# For MariaDB/MySQL | ||
cursor.execute("SHOW VARIABLES LIKE 'character_set_server';") | ||
charset = cursor.fetchone() | ||
print(f"Character set: {charset[1]}") | ||
|
||
cursor.execute("SHOW VARIABLES LIKE 'collation_server';") | ||
collation = cursor.fetchone() | ||
print(f"Collation: {collation[1]}") | ||
|
||
cursor.execute("SHOW TABLE STATUS;") | ||
tables = cursor.fetchall() | ||
for table in tables: | ||
print(f"Table: {table[0]}, Engine: {table[1]}") | ||
assert table[1] == 'InnoDB' | ||
|
||
assert charset[1] == 'utf8mb4' | ||
assert collation[1] == 'utf8mb4_general_ci' | ||
|
||
elif settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3': | ||
# For SQLite | ||
cursor.execute("PRAGMA encoding;") | ||
charset = cursor.fetchone() | ||
print(f"Character set: {charset[0]}") | ||
|
||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") | ||
tables = cursor.fetchall() | ||
for table in tables: | ||
print(f"Table: {table[0]}, Engine: SQLite") | ||
|
||
# SQLite always uses UTF-8 encoding | ||
assert charset[0].lower() == 'utf-8' |