Skip to content

Commit

Permalink
test(aiodbc): Support for the Microsoft SQL Server database via the a…
Browse files Browse the repository at this point in the history
…ioodbc driver. (#94)

Co-authored-by: Alc-Alc <alc@localhost>
  • Loading branch information
Alc-Alc and Alc-Alc committed Nov 8, 2023
1 parent a255c03 commit f6d4330
Show file tree
Hide file tree
Showing 6 changed files with 364 additions and 284 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ test-duckdb:
test-spanner:
$(ENV_PREFIX)pytest tests -m='integration and spanner'

.PHONY: test-mssql
test-mssql:
$(ENV_PREFIX)pytest tests -m='integration and mssql'
.PHONY: test-mssql-sync
test-mssql-sync:
$(ENV_PREFIX)pytest tests -m='integration and mssql_sync'

.PHONY: test-mssql-async
test-mssql-async:
$(ENV_PREFIX)pytest tests -m='integration and mssql_async'

.PHONY: test-cockroachdb-sync
test-cockroachdb-sync:
Expand Down
579 changes: 302 additions & 277 deletions pdm.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dev = [
"pyodbc>=4.0.39",
"duckdb>=0.9.0",
"asgi-lifespan>=2.1.0",
"aioodbc>=0.5.0",
]
docs = [
"sphinx>=7.1.2",
Expand Down Expand Up @@ -139,7 +140,8 @@ markers = [
"oracledb: SQLAlchemy Oracle (oracledb) Tests",
"spanner: SQLAlchemy Google Cloud Spanner (sqlalchemy-spanner) Tests",
"duckdb: SQLAlchemy DuckDB (duckdb-engine) Tests",
"mssql: SQLAlchemy Microsoft SQL Server (pyodbc) Tests",
"mssql_sync: SQLAlchemy Microsoft SQL Server (pyodbc) Tests",
"mssql_async: SQLAlchemy Microsoft SQL Server (aioodbc) Tests",
"cockroachdb_sync: SQLAlchemy CockroachDB (psycopg2) Tests",
"cockroachdb_async: SQLAlchemy CockroachDB (asyncpg) Tests",
]
Expand Down
35 changes: 34 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def cockroachdb_engine(docker_ip: str, cockroachdb_service: None) -> Engine:
pytest.param(
"mssql_engine",
marks=[
pytest.mark.mssql,
pytest.mark.mssql_sync,
pytest.mark.integration,
pytest.mark.xdist_group("mssql"),
],
Expand Down Expand Up @@ -331,6 +331,31 @@ async def cockroachdb_async_engine(docker_ip: str, cockroachdb_service: None) ->
)


@pytest.fixture()
async def mssql_async_engine(docker_ip: str, mssql_service: None) -> AsyncEngine:
"""MS SQL instance for end-to-end testing."""
return create_async_engine(
URL(
drivername="mssql+aioodbc",
username="sa",
password="Super-secret1",
host=docker_ip,
port=1344,
database="master",
query={
"driver": "ODBC Driver 18 for SQL Server",
"encrypt": "no",
"TrustServerCertificate": "yes",
# NOTE: MARS_Connection is only needed for the concurrent async tests
# lack of this causes some tests to fail
# https://github.com/jolt-org/advanced-alchemy/actions/runs/6800623970/job/18493034767?pr=94
"MARS_Connection": "yes",
}, # type:ignore[arg-type]
),
poolclass=NullPool,
)


@pytest.fixture(
name="async_engine",
params=[
Expand Down Expand Up @@ -373,6 +398,14 @@ async def cockroachdb_async_engine(docker_ip: str, cockroachdb_service: None) ->
pytest.mark.xdist_group("cockroachdb"),
],
),
pytest.param(
"mssql_async_engine",
marks=[
pytest.mark.mssql_async,
pytest.mark.integration,
pytest.mark.xdist_group("mssql"),
],
),
],
)
def async_engine(request: FixtureRequest) -> AsyncEngine:
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/test_alembic_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
pytest.param(
"mssql_engine",
marks=[
pytest.mark.mssql,
pytest.mark.mssql_sync,
pytest.mark.integration,
pytest.mark.xdist_group("mssql"),
],
Expand Down Expand Up @@ -141,6 +141,14 @@ def sync_sqlalchemy_config(request: FixtureRequest) -> SQLAlchemySyncConfig:
pytest.mark.xdist_group("cockroachdb"),
],
),
pytest.param(
"mssql_async_engine",
marks=[
pytest.mark.mssql_async,
pytest.mark.integration,
pytest.mark.xdist_group("mssql"),
],
),
],
)
def async_sqlalchemy_config(
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def first_author_id(raw_authors: RawRecordData) -> Any:
pytest.param(
"mssql_engine",
marks=[
pytest.mark.mssql,
pytest.mark.mssql_sync,
pytest.mark.integration,
pytest.mark.xdist_group("mssql"),
],
Expand Down Expand Up @@ -513,6 +513,14 @@ def session(
pytest.mark.xdist_group("cockroachdb"),
],
),
pytest.param(
"mssql_async_engine",
marks=[
pytest.mark.mssql_async,
pytest.mark.integration,
pytest.mark.xdist_group("mssql"),
],
),
],
)
def async_engine(request: FixtureRequest, repository_pk_type: RepositoryPKType) -> AsyncEngine:
Expand Down

0 comments on commit f6d4330

Please sign in to comment.