-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sqlalchemy): updates to documentation based on upstream changes (#…
…3917) * fix(sqlalchemy): updates to documentation based on upstream changes
- Loading branch information
Showing
5 changed files
with
51 additions
and
28 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
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
24 changes: 21 additions & 3 deletions
24
tests/examples/test_contrib/test_sqlalchemy/test_sqlalchemy_examples.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 |
---|---|---|
@@ -1,14 +1,32 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from pytest import MonkeyPatch | ||
from sqlalchemy.ext.asyncio import create_async_engine | ||
from sqlalchemy.pool import NullPool | ||
|
||
from litestar.plugins.sqlalchemy import AsyncSessionConfig, SQLAlchemyAsyncConfig | ||
from litestar.testing import TestClient | ||
|
||
pytestmark = pytest.mark.xdist_group("sqlalchemy_examples") | ||
|
||
|
||
def test_sqlalchemy_declarative_models() -> None: | ||
from docs.examples.contrib.sqlalchemy.sqlalchemy_declarative_models import app | ||
async def test_sqlalchemy_declarative_models(tmp_path: Path, monkeypatch: MonkeyPatch) -> None: | ||
engine = create_async_engine("sqlite+aiosqlite:///test.sqlite", poolclass=NullPool) | ||
|
||
session_config = AsyncSessionConfig(expire_on_commit=False) | ||
sqlalchemy_config = SQLAlchemyAsyncConfig( | ||
session_config=session_config, | ||
create_all=True, | ||
engine_instance=engine, | ||
) # Create 'async_session' dependency. | ||
from docs.examples.contrib.sqlalchemy import sqlalchemy_declarative_models | ||
|
||
with TestClient(app) as client: | ||
monkeypatch.setattr(sqlalchemy_declarative_models, "sqlalchemy_config", sqlalchemy_config) | ||
async with engine.begin() as connection: | ||
await connection.run_sync(sqlalchemy_declarative_models.Author.metadata.create_all) | ||
await connection.commit() | ||
with TestClient(sqlalchemy_declarative_models.app) as client: | ||
response = client.get("/authors") | ||
assert response.status_code == 200 | ||
assert len(response.json()) > 0 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.