From fd0bb61e25b078b4cee150bed4efd5aa3b088bd8 Mon Sep 17 00:00:00 2001 From: lchen-2101 <73617864+lchen-2101@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:53:36 -0500 Subject: [PATCH] fix alembic migration scripts and tests, add additional custom test (#52) closes #50 --- db_revisions/env.py | 16 ++--- db_revisions/utils.py | 8 ++- ...9_create_financial_institution_domains.py} | 2 +- ...98b11074c54_create_denied_domains_table.py | 2 +- ...93f_create_financial_institutions_table.py | 2 +- poetry.lock | 66 +++++++++++++++++-- pyproject.toml | 1 + tests/migrations/conftest.py | 16 ----- tests/migrations/test_migrations.py | 16 ++++- 9 files changed, 93 insertions(+), 36 deletions(-) rename db_revisions/versions/{20e0d51d8be9_create_financial_institution_domains_.py => 20e0d51d8be9_create_financial_institution_domains.py} (97%) delete mode 100644 tests/migrations/conftest.py diff --git a/db_revisions/env.py b/db_revisions/env.py index 1a14900..fe8291e 100644 --- a/db_revisions/env.py +++ b/db_revisions/env.py @@ -12,7 +12,7 @@ # Interpret the config file for Python logging. # This line sets up loggers basically. if config.config_file_name is not None: - fileConfig(config.config_file_name) + fileConfig(config.config_file_name, disable_existing_loggers=False) # this specific to SBL configuration @@ -82,18 +82,18 @@ def run_migrations_online() -> None: if connectable is None: connectable = engine_from_config( - context.config.get_section(context.config.config_ini_section), + context.config.get_section(context.config.config_ini_section, {}), prefix="sqlalchemy.", poolclass=pool.NullPool, ) - with connectable.connect() as connection: - context.configure( - connection=connection, target_metadata=target_metadata, version_table_schema=target_metadata.schema - ) + with connectable.connect() as connection: + context.configure( + connection=connection, target_metadata=target_metadata, version_table_schema=target_metadata.schema + ) - with context.begin_transaction(): - context.run_migrations() + with context.begin_transaction(): + context.run_migrations() if context.is_offline_mode(): diff --git a/db_revisions/utils.py b/db_revisions/utils.py index a8c9d57..d84fa39 100644 --- a/db_revisions/utils.py +++ b/db_revisions/utils.py @@ -1,11 +1,13 @@ from alembic import op from sqlalchemy import engine_from_config -from sqlalchemy.engine import reflection +import sqlalchemy def table_exists(table_name): config = op.get_context().config - engine = engine_from_config(config.get_section(config.config_ini_section), prefix="sqlalchemy.") - inspector = reflection.Inspector.from_engine(engine) + engine = config.attributes.get("connection", None) + if engine is None: + engine = engine_from_config(config.get_section(config.config_ini_section), prefix="sqlalchemy.") + inspector = sqlalchemy.inspect(engine) tables = inspector.get_table_names() return table_name in tables diff --git a/db_revisions/versions/20e0d51d8be9_create_financial_institution_domains_.py b/db_revisions/versions/20e0d51d8be9_create_financial_institution_domains.py similarity index 97% rename from db_revisions/versions/20e0d51d8be9_create_financial_institution_domains_.py rename to db_revisions/versions/20e0d51d8be9_create_financial_institution_domains.py index 95336bc..5996553 100644 --- a/db_revisions/versions/20e0d51d8be9_create_financial_institution_domains_.py +++ b/db_revisions/versions/20e0d51d8be9_create_financial_institution_domains.py @@ -24,7 +24,7 @@ def upgrade() -> None: "financial_institution_domains", sa.Column("domain", sa.String(), nullable=False), sa.Column("lei", sa.String(), nullable=False), - sa.Column("event_time", sa.DateTime(), server_default=sa.text("now()"), nullable=False), + sa.Column("event_time", sa.DateTime(), server_default=sa.func.now(), nullable=False), sa.ForeignKeyConstraint( ["lei"], ["financial_institutions.lei"], diff --git a/db_revisions/versions/a98b11074c54_create_denied_domains_table.py b/db_revisions/versions/a98b11074c54_create_denied_domains_table.py index dbc2bae..4a5b207 100644 --- a/db_revisions/versions/a98b11074c54_create_denied_domains_table.py +++ b/db_revisions/versions/a98b11074c54_create_denied_domains_table.py @@ -24,7 +24,7 @@ def upgrade() -> None: op.create_table( "denied_domains", sa.Column("domain", sa.String(), nullable=False), - sa.Column("event_time", sa.DateTime(), server_default=sa.text("now()"), nullable=False), + sa.Column("event_time", sa.DateTime(), server_default=sa.func.now(), nullable=False), sa.PrimaryKeyConstraint("domain"), ) op.create_index(op.f("ix_denied_domains_domain"), "denied_domains", ["domain"], unique=False) diff --git a/db_revisions/versions/f76c5004993f_create_financial_institutions_table.py b/db_revisions/versions/f76c5004993f_create_financial_institutions_table.py index a77f031..747f405 100644 --- a/db_revisions/versions/f76c5004993f_create_financial_institutions_table.py +++ b/db_revisions/versions/f76c5004993f_create_financial_institutions_table.py @@ -25,7 +25,7 @@ def upgrade() -> None: "financial_institutions", sa.Column("lei", sa.String(), nullable=False), sa.Column("name", sa.String(), nullable=False), - sa.Column("event_time", sa.DateTime(), server_default=sa.text("now()"), nullable=False), + sa.Column("event_time", sa.DateTime(), server_default=sa.func.now(), nullable=False), sa.PrimaryKeyConstraint("lei"), ) op.create_index(op.f("ix_financial_institutions_lei"), "financial_institutions", ["lei"], unique=True) diff --git a/poetry.lock b/poetry.lock index 5d71239..3814613 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,9 +1,10 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. [[package]] name = "aiosqlite" version = "0.19.0" description = "asyncio bridge to the standard sqlite3 module" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -19,6 +20,7 @@ docs = ["sphinx (==6.1.3)", "sphinx-mdinclude (==0.5.3)"] name = "alembic" version = "1.12.1" description = "A database migration tool for SQLAlchemy." +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -38,6 +40,7 @@ tz = ["python-dateutil"] name = "annotated-types" version = "0.6.0" description = "Reusable constraint types to use with typing.Annotated" +category = "main" optional = false python-versions = ">=3.8" files = [ @@ -49,6 +52,7 @@ files = [ name = "anyio" version = "3.7.1" description = "High level compatibility layer for multiple asynchronous event loop implementations" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -69,6 +73,7 @@ trio = ["trio (<0.22)"] name = "asyncpg" version = "0.27.0" description = "An asyncio PostgreSQL driver" +category = "main" optional = false python-versions = ">=3.7.0" files = [ @@ -119,6 +124,7 @@ test = ["flake8 (>=5.0.4,<5.1.0)", "uvloop (>=0.15.3)"] name = "black" version = "23.10.1" description = "The uncompromising code formatter." +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -159,6 +165,7 @@ uvloop = ["uvloop (>=0.15.2)"] name = "certifi" version = "2023.7.22" description = "Python package for providing Mozilla's CA Bundle." +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -170,6 +177,7 @@ files = [ name = "charset-normalizer" version = "3.3.2" description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +category = "main" optional = false python-versions = ">=3.7.0" files = [ @@ -269,6 +277,7 @@ files = [ name = "click" version = "8.1.7" description = "Composable command line interface toolkit" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -283,6 +292,7 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""} name = "colorama" version = "0.4.6" description = "Cross-platform colored terminal text." +category = "main" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" files = [ @@ -294,6 +304,7 @@ files = [ name = "coverage" version = "7.3.2" description = "Code coverage measurement for Python" +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -358,6 +369,7 @@ toml = ["tomli"] name = "deprecation" version = "2.1.0" description = "A library to handle automated deprecations" +category = "main" optional = false python-versions = "*" files = [ @@ -372,6 +384,7 @@ packaging = "*" name = "ecdsa" version = "0.18.0" description = "ECDSA cryptographic signature library (pure python)" +category = "main" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" files = [ @@ -390,6 +403,7 @@ gmpy2 = ["gmpy2"] name = "fastapi" version = "0.103.2" description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -410,6 +424,7 @@ all = ["email-validator (>=2.0.0)", "httpx (>=0.23.0)", "itsdangerous (>=1.1.0)" name = "greenlet" version = "3.0.1" description = "Lightweight in-process concurrent programming" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -480,6 +495,7 @@ test = ["objgraph", "psutil"] name = "h11" version = "0.14.0" description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -491,6 +507,7 @@ files = [ name = "httpcore" version = "0.17.3" description = "A minimal low-level HTTP client." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -502,16 +519,17 @@ files = [ anyio = ">=3.0,<5.0" certifi = "*" h11 = ">=0.13,<0.15" -sniffio = "==1.*" +sniffio = ">=1.0.0,<2.0.0" [package.extras] http2 = ["h2 (>=3,<5)"] -socks = ["socksio (==1.*)"] +socks = ["socksio (>=1.0.0,<2.0.0)"] [[package]] name = "httpx" version = "0.24.1" description = "The next generation HTTP client." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -527,14 +545,15 @@ sniffio = "*" [package.extras] brotli = ["brotli", "brotlicffi"] -cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"] +cli = ["click (>=8.0.0,<9.0.0)", "pygments (>=2.0.0,<3.0.0)", "rich (>=10,<14)"] http2 = ["h2 (>=3,<5)"] -socks = ["socksio (==1.*)"] +socks = ["socksio (>=1.0.0,<2.0.0)"] [[package]] name = "idna" version = "3.4" description = "Internationalized Domain Names in Applications (IDNA)" +category = "main" optional = false python-versions = ">=3.5" files = [ @@ -546,6 +565,7 @@ files = [ name = "iniconfig" version = "2.0.0" description = "brain-dead simple config-ini parsing" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -557,6 +577,7 @@ files = [ name = "mako" version = "1.2.4" description = "A super-fast templating language that borrows the best ideas from the existing templating languages." +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -576,6 +597,7 @@ testing = ["pytest"] name = "markupsafe" version = "2.1.3" description = "Safely add untrusted strings to HTML/XML markup." +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -645,6 +667,7 @@ files = [ name = "mypy-extensions" version = "1.0.0" description = "Type system extensions for programs checked with the mypy type checker." +category = "dev" optional = false python-versions = ">=3.5" files = [ @@ -656,6 +679,7 @@ files = [ name = "packaging" version = "23.2" description = "Core utilities for Python packages" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -667,6 +691,7 @@ files = [ name = "pathspec" version = "0.11.2" description = "Utility library for gitignore style pattern matching of file paths." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -678,6 +703,7 @@ files = [ name = "platformdirs" version = "3.11.0" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -693,6 +719,7 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-co name = "pluggy" version = "1.3.0" description = "plugin and hook calling mechanisms for python" +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -708,6 +735,7 @@ testing = ["pytest", "pytest-benchmark"] name = "psycopg2-binary" version = "2.9.9" description = "psycopg2 - Python-PostgreSQL Database Adapter" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -786,6 +814,7 @@ files = [ name = "pyasn1" version = "0.5.0" description = "Pure-Python implementation of ASN.1 types and DER/BER/CER codecs (X.208)" +category = "main" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7" files = [ @@ -797,6 +826,7 @@ files = [ name = "pydantic" version = "2.4.2" description = "Data validation using Python type hints" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -816,6 +846,7 @@ email = ["email-validator (>=2.0.0)"] name = "pydantic-core" version = "2.10.1" description = "" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -934,6 +965,7 @@ typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" name = "pydantic-settings" version = "2.0.3" description = "Settings management using Pydantic" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -949,6 +981,7 @@ python-dotenv = ">=0.21.0" name = "pytest" version = "7.4.3" description = "pytest: simple powerful testing with Python" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -969,6 +1002,7 @@ testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "no name = "pytest-alembic" version = "0.10.7" description = "A pytest plugin for verifying alembic migrations." +category = "dev" optional = false python-versions = ">=3.6,<4" files = [ @@ -985,6 +1019,7 @@ sqlalchemy = "*" name = "pytest-asyncio" version = "0.21.1" description = "Pytest support for asyncio" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1003,6 +1038,7 @@ testing = ["coverage (>=6.2)", "flaky (>=3.5.0)", "hypothesis (>=5.7.1)", "mypy name = "pytest-cov" version = "4.1.0" description = "Pytest plugin for measuring coverage." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1021,6 +1057,7 @@ testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtuale name = "pytest-env" version = "1.1.1" description = "pytest plugin that allows you to add environment variables." +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -1038,6 +1075,7 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.3.2)", "pytest-mock (>=3.12)"] name = "pytest-mock" version = "3.12.0" description = "Thin-wrapper around the mock package for easier use with pytest" +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -1055,6 +1093,7 @@ dev = ["pre-commit", "pytest-asyncio", "tox"] name = "python-dotenv" version = "1.0.0" description = "Read key-value pairs from a .env file and set them as environment variables" +category = "main" optional = false python-versions = ">=3.8" files = [ @@ -1069,6 +1108,7 @@ cli = ["click (>=5.0)"] name = "python-jose" version = "3.3.0" description = "JOSE implementation in Python" +category = "main" optional = false python-versions = "*" files = [ @@ -1090,6 +1130,7 @@ pycryptodome = ["pyasn1", "pycryptodome (>=3.3.1,<4.0.0)"] name = "python-keycloak" version = "3.3.0" description = "python-keycloak is a Python package providing access to the Keycloak API." +category = "main" optional = false python-versions = ">=3.7,<4.0" files = [ @@ -1110,6 +1151,7 @@ docs = ["Sphinx (>=5.3.0,<6.0.0)", "alabaster (>=0.7.12,<0.8.0)", "commonmark (> name = "requests" version = "2.31.0" description = "Python HTTP for Humans." +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1131,6 +1173,7 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] name = "requests-toolbelt" version = "1.0.0" description = "A utility belt for advanced users of python-requests" +category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" files = [ @@ -1145,6 +1188,7 @@ requests = ">=2.0.1,<3.0.0" name = "rsa" version = "4.9" description = "Pure-Python RSA implementation" +category = "main" optional = false python-versions = ">=3.6,<4" files = [ @@ -1159,6 +1203,7 @@ pyasn1 = ">=0.1.3" name = "ruff" version = "0.0.278" description = "An extremely fast Python linter, written in Rust." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1185,6 +1230,7 @@ files = [ name = "six" version = "1.16.0" description = "Python 2 and 3 compatibility utilities" +category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" files = [ @@ -1196,6 +1242,7 @@ files = [ name = "sniffio" version = "1.3.0" description = "Sniff out which async library your code is running under" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1207,12 +1254,15 @@ files = [ name = "sqlalchemy" version = "2.0.23" description = "Database Abstraction Library" +category = "main" optional = false python-versions = ">=3.7" files = [ {file = "SQLAlchemy-2.0.23-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:638c2c0b6b4661a4fd264f6fb804eccd392745c5887f9317feb64bb7cb03b3ea"}, {file = "SQLAlchemy-2.0.23-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e3b5036aa326dc2df50cba3c958e29b291a80f604b1afa4c8ce73e78e1c9f01d"}, + {file = "SQLAlchemy-2.0.23-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:787af80107fb691934a01889ca8f82a44adedbf5ef3d6ad7d0f0b9ac557e0c34"}, {file = "SQLAlchemy-2.0.23-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c14eba45983d2f48f7546bb32b47937ee2cafae353646295f0e99f35b14286ab"}, + {file = "SQLAlchemy-2.0.23-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:0666031df46b9badba9bed00092a1ffa3aa063a5e68fa244acd9f08070e936d3"}, {file = "SQLAlchemy-2.0.23-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:89a01238fcb9a8af118eaad3ffcc5dedaacbd429dc6fdc43fe430d3a941ff965"}, {file = "SQLAlchemy-2.0.23-cp310-cp310-win32.whl", hash = "sha256:cabafc7837b6cec61c0e1e5c6d14ef250b675fa9c3060ed8a7e38653bd732ff8"}, {file = "SQLAlchemy-2.0.23-cp310-cp310-win_amd64.whl", hash = "sha256:87a3d6b53c39cd173990de2f5f4b83431d534a74f0e2f88bd16eabb5667e65c6"}, @@ -1249,7 +1299,9 @@ files = [ {file = "SQLAlchemy-2.0.23-cp38-cp38-win_amd64.whl", hash = "sha256:964971b52daab357d2c0875825e36584d58f536e920f2968df8d581054eada4b"}, {file = "SQLAlchemy-2.0.23-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:616fe7bcff0a05098f64b4478b78ec2dfa03225c23734d83d6c169eb41a93e55"}, {file = "SQLAlchemy-2.0.23-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:0e680527245895aba86afbd5bef6c316831c02aa988d1aad83c47ffe92655e74"}, + {file = "SQLAlchemy-2.0.23-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9585b646ffb048c0250acc7dad92536591ffe35dba624bb8fd9b471e25212a35"}, {file = "SQLAlchemy-2.0.23-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4895a63e2c271ffc7a81ea424b94060f7b3b03b4ea0cd58ab5bb676ed02f4221"}, + {file = "SQLAlchemy-2.0.23-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:cc1d21576f958c42d9aec68eba5c1a7d715e5fc07825a629015fe8e3b0657fb0"}, {file = "SQLAlchemy-2.0.23-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:967c0b71156f793e6662dd839da54f884631755275ed71f1539c95bbada9aaab"}, {file = "SQLAlchemy-2.0.23-cp39-cp39-win32.whl", hash = "sha256:0a8c6aa506893e25a04233bc721c6b6cf844bafd7250535abb56cb6cc1368884"}, {file = "SQLAlchemy-2.0.23-cp39-cp39-win_amd64.whl", hash = "sha256:f3420d00d2cb42432c1d0e44540ae83185ccbbc67a6054dcc8ab5387add6620b"}, @@ -1290,6 +1342,7 @@ sqlcipher = ["sqlcipher3-binary"] name = "starlette" version = "0.27.0" description = "The little ASGI library that shines." +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1307,6 +1360,7 @@ full = ["httpx (>=0.22.0)", "itsdangerous", "jinja2", "python-multipart", "pyyam name = "typing-extensions" version = "4.8.0" description = "Backported and Experimental Type Hints for Python 3.8+" +category = "main" optional = false python-versions = ">=3.8" files = [ @@ -1318,6 +1372,7 @@ files = [ name = "urllib3" version = "2.0.7" description = "HTTP library with thread-safe connection pooling, file post, and more." +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1335,6 +1390,7 @@ zstd = ["zstandard (>=0.18.0)"] name = "uvicorn" version = "0.22.0" description = "The lightning-fast ASGI server." +category = "main" optional = false python-versions = ">=3.7" files = [ diff --git a/pyproject.toml b/pyproject.toml index dabdcfa..cf6aeff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,7 @@ addopts = [ testpaths = ["tests"] env = [ "INST_CONN=postgresql+asyncpg://localhost", + "INST_DB_SCHEMA=main", "KC_URL=http://localhost", "KC_REALM=", "KC_ADMIN_CLIENT_ID=", diff --git a/tests/migrations/conftest.py b/tests/migrations/conftest.py deleted file mode 100644 index 9f0eb0f..0000000 --- a/tests/migrations/conftest.py +++ /dev/null @@ -1,16 +0,0 @@ -import pytest - -from pytest_alembic.config import Config -from sqlalchemy.ext.asyncio import create_async_engine - - -@pytest.fixture -def alembic_config(): - """Override this fixture to configure the exact alembic context setup required.""" - return Config() - - -@pytest.fixture -def alembic_engine(): - """Override this fixture to provide pytest-alembic powered tests with a database handle.""" - return create_async_engine("sqlite+aiosqlite://") diff --git a/tests/migrations/test_migrations.py b/tests/migrations/test_migrations.py index 5006479..33dda1a 100644 --- a/tests/migrations/test_migrations.py +++ b/tests/migrations/test_migrations.py @@ -1,6 +1,20 @@ from pytest_alembic.tests import ( - test_model_definitions_match_ddl, # noqa: F401 test_single_head_revision, # noqa: F401 test_up_down_consistency, # noqa: F401 test_upgrade, # noqa: F401 ) + +import sqlalchemy +from sqlalchemy.engine import Engine + +from pytest_alembic import MigrationContext + + +def test_tables_exist_after_migration(alembic_runner: MigrationContext, alembic_engine: Engine): + alembic_runner.migrate_up_to("20e0d51d8be9") + + inspector = sqlalchemy.inspect(alembic_engine) + tables = inspector.get_table_names() + assert "denied_domains" in tables + assert "financial_institutions" in tables + assert "financial_institution_domains" in tables