-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: sqlalchemy server version info without request
- Loading branch information
Showing
6 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
15 changes: 15 additions & 0 deletions
15
lib/dl_sqlalchemy_postgres/dl_sqlalchemy_postgres_tests/db/conftest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
import sqlalchemy | ||
|
||
|
||
from dl_testing.containers import get_test_container_hostport | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def engine_url(): | ||
return f'bi_postgresql://datalens:qwerty@{get_test_container_hostport("db-postgres", fallback_port=52301).as_pair()}/test_data' | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sa_engine(engine_url): | ||
return sqlalchemy.create_engine(engine_url) |
16 changes: 16 additions & 0 deletions
16
lib/dl_sqlalchemy_postgres/dl_sqlalchemy_postgres_tests/db/test_server_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import sqlalchemy | ||
import sqlalchemy.orm as sqlalchemy_orm | ||
|
||
|
||
SERVER_VERSION_INFO = (123, 45, 67, 89) | ||
SERVER_VERSION = ".".join(map(str, SERVER_VERSION_INFO)) | ||
|
||
|
||
def test_server_version(engine_url: str): | ||
engine = sqlalchemy.create_engine(engine_url, connect_args=dict(server_version=SERVER_VERSION)) | ||
session_maker = sqlalchemy_orm.sessionmaker(bind=engine) | ||
engine_session = session_maker() | ||
# Connection and version get initialized on first query: | ||
engine_session.scalar("select 1") | ||
ver = engine_session.get_bind().dialect.server_version_info | ||
assert ver == SERVER_VERSION_INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3.7' | ||
|
||
services: | ||
db-postgres: | ||
image: "postgres:13-alpine@sha256:b9f66c57932510574fb17bccd175776535cec9abcfe7ba306315af2f0b7bfbb4" | ||
environment: | ||
- POSTGRES_DB=test_data | ||
- POSTGRES_USER=datalens | ||
- POSTGRES_PASSWORD=qwerty | ||
ports: | ||
- "50319:5432" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters