-
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.
- Loading branch information
Showing
1 changed file
with
11 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,40 +1,41 @@ | ||
# test_db_settings.py | ||
import pytest | ||
from django.db import connection | ||
from django.conf import settings | ||
from django.db import connection | ||
|
||
|
||
@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': | ||
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 table[1] == "InnoDB" | ||
|
||
assert charset[1] == 'utf8mb4' | ||
assert collation[1] == 'utf8mb4_general_ci' | ||
assert charset[1] == "utf8mb4" | ||
assert collation[1] == "utf8mb4_general_ci" | ||
|
||
elif settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3': | ||
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' | ||
assert charset[0].lower() == "utf-8" |