✨ Document indexes and make them opt-in (#205)
This commit is contained in:
committed by
GitHub
parent
3d7b74746c
commit
155c6178cd
@@ -1,4 +1,6 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy.engine.reflection import Inspector
|
||||
from sqlmodel import create_engine
|
||||
from sqlmodel.pool import StaticPool
|
||||
|
||||
@@ -166,3 +168,16 @@ def test_tutorial(clear_sqlmodel):
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
assert data == openapi_schema
|
||||
|
||||
# Test inherited indexes
|
||||
insp: Inspector = inspect(mod.engine)
|
||||
indexes = insp.get_indexes(str(mod.Hero.__tablename__))
|
||||
expected_indexes = [
|
||||
{"name": "ix_hero_name", "column_names": ["name"], "unique": 0},
|
||||
{"name": "ix_hero_age", "column_names": ["age"], "unique": 0},
|
||||
]
|
||||
for index in expected_indexes:
|
||||
assert index in indexes, "This expected index should be in the indexes in DB"
|
||||
# Now that this index was checked, remove it from the list of indexes
|
||||
indexes.pop(indexes.index(index))
|
||||
assert len(indexes) == 0, "The database should only have the expected indexes"
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy.engine.reflection import Inspector
|
||||
from sqlmodel import create_engine
|
||||
from sqlmodel.pool import StaticPool
|
||||
|
||||
@@ -166,3 +168,16 @@ def test_tutorial(clear_sqlmodel):
|
||||
assert response.status_code == 200, response.text
|
||||
|
||||
assert data == openapi_schema
|
||||
|
||||
# Test inherited indexes
|
||||
insp: Inspector = inspect(mod.engine)
|
||||
indexes = insp.get_indexes(str(mod.Hero.__tablename__))
|
||||
expected_indexes = [
|
||||
{"name": "ix_hero_age", "column_names": ["age"], "unique": 0},
|
||||
{"name": "ix_hero_name", "column_names": ["name"], "unique": 0},
|
||||
]
|
||||
for index in expected_indexes:
|
||||
assert index in indexes, "This expected index should be in the indexes in DB"
|
||||
# Now that this index was checked, remove it from the list of indexes
|
||||
indexes.pop(indexes.index(index))
|
||||
assert len(indexes) == 0, "The database should only have the expected indexes"
|
||||
|
||||
Reference in New Issue
Block a user