Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarson committed Jul 29, 2024
1 parent 2c4e7de commit cae3673
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions primed/tests/test_db_config.py
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"

0 comments on commit cae3673

Please sign in to comment.