test wtf
This commit is contained in:
@ -234,12 +234,13 @@ def populate_meta_sqlalchemy_table_if_required(meta: "ModelMeta") -> None:
|
|||||||
if not hasattr(meta, "table") and check_for_null_type_columns_from_forward_refs(
|
if not hasattr(meta, "table") and check_for_null_type_columns_from_forward_refs(
|
||||||
meta
|
meta
|
||||||
):
|
):
|
||||||
meta.table = sqlalchemy.Table(
|
table = sqlalchemy.Table(
|
||||||
meta.tablename,
|
meta.tablename,
|
||||||
meta.metadata,
|
meta.metadata,
|
||||||
*[copy.deepcopy(col) for col in meta.columns],
|
*[copy.deepcopy(col) for col in meta.columns],
|
||||||
*meta.constraints,
|
*meta.constraints,
|
||||||
)
|
)
|
||||||
|
meta.table = table
|
||||||
|
|
||||||
|
|
||||||
def update_column_definition(
|
def update_column_definition(
|
||||||
|
|||||||
@ -3,7 +3,7 @@ from typing import Optional
|
|||||||
import databases
|
import databases
|
||||||
import pytest
|
import pytest
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import ForeignKeyConstraint, create_engine, inspect
|
||||||
from sqlalchemy.dialects import postgresql
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
import ormar
|
import ormar
|
||||||
@ -11,6 +11,7 @@ from tests.settings import DATABASE_URL
|
|||||||
|
|
||||||
database = databases.Database(DATABASE_URL, force_rollback=True)
|
database = databases.Database(DATABASE_URL, force_rollback=True)
|
||||||
metadata = sqlalchemy.MetaData()
|
metadata = sqlalchemy.MetaData()
|
||||||
|
engine = sqlalchemy.create_engine(DATABASE_URL, echo=True)
|
||||||
|
|
||||||
|
|
||||||
class Artist(ormar.Model):
|
class Artist(ormar.Model):
|
||||||
@ -28,6 +29,7 @@ class Album(ormar.Model):
|
|||||||
tablename = "albums"
|
tablename = "albums"
|
||||||
metadata = metadata
|
metadata = metadata
|
||||||
database = database
|
database = database
|
||||||
|
constraint = [ForeignKeyConstraint(['albums'],['albums.id'])]
|
||||||
|
|
||||||
id: int = ormar.Integer(primary_key=True)
|
id: int = ormar.Integer(primary_key=True)
|
||||||
name: str = ormar.String(max_length=100)
|
name: str = ormar.String(max_length=100)
|
||||||
@ -47,20 +49,19 @@ class Track(ormar.Model):
|
|||||||
|
|
||||||
@pytest.fixture(autouse=True, scope="module")
|
@pytest.fixture(autouse=True, scope="module")
|
||||||
def create_test_database():
|
def create_test_database():
|
||||||
engine = sqlalchemy.create_engine(DATABASE_URL)
|
|
||||||
if "sqlite" in DATABASE_URL:
|
if "sqlite" in DATABASE_URL:
|
||||||
with engine.connect() as connection:
|
with engine.connect() as connection:
|
||||||
connection.execute("PRAGMA foreign_keys = ON;")
|
connection.execute("PRAGMA foreign_keys = ON;")
|
||||||
metadata.drop_all(engine)
|
metadata.drop_all(engine)
|
||||||
metadata.create_all(engine)
|
metadata.create_all(engine)
|
||||||
yield
|
yield
|
||||||
# metadata.drop_all(engine)
|
metadata.drop_all(engine)
|
||||||
|
|
||||||
|
|
||||||
# def test_table_structures():
|
def test_table_structures():
|
||||||
# col = Album.Meta.table.columns.get('artist')
|
col = Album.Meta.table.columns.get('artist')
|
||||||
# breakpoint()
|
inspector = inspect(engine)
|
||||||
|
col2 = inspector.get_columns('albums')
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_simple_cascade():
|
async def test_simple_cascade():
|
||||||
|
|||||||
Reference in New Issue
Block a user