initial commit of new version
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
Test script to verify the Alembic migration for the avdb_image table.
|
||||
"""
|
||||
import sqlalchemy
|
||||
from sqlalchemy import inspect, text
|
||||
|
||||
# Database URL from alembic.ini
|
||||
DATABASE_URL = "postgresql+psycopg2://postgres:pgRocks@localhost:5432/testdb"
|
||||
|
||||
def test_avdb_image_table_exists():
|
||||
"""Test if the avdb_image table exists in the database."""
|
||||
engine = sqlalchemy.create_engine(DATABASE_URL)
|
||||
inspector = inspect(engine)
|
||||
|
||||
# Print database and table configuration
|
||||
print("Database URL:", DATABASE_URL)
|
||||
print("\nChecking for avdb_image table...")
|
||||
|
||||
# Check if the table exists
|
||||
assert inspector.has_table("avdb_image"), "avdb_image table does not exist!"
|
||||
print("✓ avdb_image table exists.")
|
||||
|
||||
# Verify the table structure
|
||||
columns = inspector.get_columns("avdb_image")
|
||||
column_names = [column["name"] for column in columns]
|
||||
|
||||
print("\nColumns in avdb_image table:")
|
||||
for column in columns:
|
||||
print(f" - {column['name']}: {column['type']}, Nullable: {column['nullable']}")
|
||||
|
||||
expected_columns = ["img_id", "img_path", "img_name", "width", "height", "created_at"]
|
||||
for col in expected_columns:
|
||||
assert col in column_names, f"Column '{col}' not found in avdb_image table!"
|
||||
print("\n✓ All expected columns are present in the avdb_image table.")
|
||||
|
||||
# Verify primary key
|
||||
primary_key = inspector.get_pk_constraint("avdb_image")
|
||||
assert primary_key is not None, "Primary key not found in avdb_image table!"
|
||||
assert primary_key["constrained_columns"] == ["img_id"], "Primary key is not set on img_id!"
|
||||
print("✓ Primary key is correctly set on img_id.")
|
||||
|
||||
# Verify nullable constraints
|
||||
nullable_columns = [col["name"] for col in columns if col["nullable"]]
|
||||
non_nullable_columns = ["img_path", "img_name", "width", "height"]
|
||||
for col in non_nullable_columns:
|
||||
assert col not in nullable_columns, f"Column '{col}' should not be nullable!"
|
||||
print("✓ Non-nullable constraints are correctly set.")
|
||||
|
||||
print("\nAll tests passed! The avdb_image table was created successfully.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_avdb_image_table_exists()
|
||||
Reference in New Issue
Block a user