-
-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Coverage for
repository
and SQLAlchemy (#2586)
* coverage: repository --------- Signed-off-by: Janek Nouvertné <[email protected]>
- Loading branch information
1 parent
5056928
commit 6973452
Showing
10 changed files
with
156 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
from __future__ import annotations | ||
from __future__ import annotations # pragma: no cover | ||
|
||
__all__ = ("ConflictError", "NotFoundError", "RepositoryError") | ||
__all__ = ("ConflictError", "NotFoundError", "RepositoryError") # pragma: no cover | ||
|
||
|
||
class RepositoryError(Exception): | ||
class RepositoryError(Exception): # pragma: no cover | ||
"""Base repository exception type.""" | ||
|
||
|
||
class ConflictError(RepositoryError): | ||
class ConflictError(RepositoryError): # pragma: no cover | ||
"""Data integrity error.""" | ||
|
||
|
||
class NotFoundError(RepositoryError): | ||
class NotFoundError(RepositoryError): # pragma: no cover | ||
"""An identity does not exist.""" |
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,6 +1,6 @@ | ||
try: | ||
from advanced_alchemy.exceptions import ConflictError, NotFoundError, RepositoryError | ||
except ImportError: | ||
except ImportError: # pragma: no cover | ||
from ._exceptions import ConflictError, NotFoundError, RepositoryError # type: ignore[assignment] | ||
|
||
__all__ = ("ConflictError", "NotFoundError", "RepositoryError") |
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
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,64 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
from advanced_alchemy import repository as advanced_alchemy_repo | ||
from advanced_alchemy import types as advanced_alchemy_types | ||
from advanced_alchemy.repository import typing as advanced_alchemy_typing | ||
from sqlalchemy import Engine, create_engine | ||
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine | ||
|
||
from litestar.contrib.sqlalchemy.plugins.init.config.asyncio import SQLAlchemyAsyncConfig | ||
from litestar.contrib.sqlalchemy.plugins.init.config.sync import SQLAlchemySyncConfig | ||
|
||
|
||
def test_create_engine_with_engine_instance() -> None: | ||
engine = create_engine("sqlite:///:memory:") | ||
config = SQLAlchemySyncConfig(engine_instance=engine) | ||
with pytest.deprecated_call(): | ||
assert engine is config.create_engine() | ||
|
||
|
||
def test_create_engine_with_connection_string() -> None: | ||
config = SQLAlchemySyncConfig(connection_string="sqlite:///:memory:") | ||
with pytest.deprecated_call(): | ||
engine = config.create_engine() | ||
assert isinstance(engine, Engine) | ||
|
||
|
||
def test_async_create_engine_with_engine_instance() -> None: | ||
engine = create_async_engine("sqlite+aiosqlite:///:memory:") | ||
config = SQLAlchemyAsyncConfig(engine_instance=engine) | ||
with pytest.deprecated_call(): | ||
assert engine is config.create_engine() | ||
|
||
|
||
def test_async_create_engine_with_connection_string() -> None: | ||
config = SQLAlchemyAsyncConfig(connection_string="sqlite+aiosqlite:///:memory:") | ||
with pytest.deprecated_call(): | ||
engine = config.create_engine() | ||
assert isinstance(engine, AsyncEngine) | ||
|
||
|
||
def test_repository_re_exports() -> None: | ||
from litestar.contrib.sqlalchemy import types | ||
from litestar.contrib.sqlalchemy.repository import ( | ||
SQLAlchemyAsyncRepository, | ||
SQLAlchemySyncRepository, | ||
wrap_sqlalchemy_exception, | ||
) | ||
from litestar.contrib.sqlalchemy.repository import types as repository_types | ||
|
||
assert SQLAlchemySyncRepository is advanced_alchemy_repo.SQLAlchemySyncRepository | ||
assert SQLAlchemyAsyncRepository is advanced_alchemy_repo.SQLAlchemyAsyncRepository | ||
assert wrap_sqlalchemy_exception is advanced_alchemy_repo._util.wrap_sqlalchemy_exception | ||
|
||
assert repository_types.ModelT is advanced_alchemy_typing.ModelT | ||
assert repository_types.RowT is advanced_alchemy_typing.RowT | ||
assert repository_types.SQLAlchemyAsyncRepositoryT is advanced_alchemy_typing.SQLAlchemyAsyncRepositoryT | ||
assert repository_types.SQLAlchemySyncRepositoryT is advanced_alchemy_typing.SQLAlchemySyncRepositoryT | ||
|
||
assert types.GUID is advanced_alchemy_types.GUID | ||
assert types.ORA_JSONB is advanced_alchemy_types.ORA_JSONB | ||
assert types.BigIntIdentity is advanced_alchemy_types.BigIntIdentity | ||
assert types.DateTimeUTC is advanced_alchemy_types.DateTimeUTC | ||
assert types.JsonB is advanced_alchemy_types.JsonB |
Empty file.
Empty file.
Empty file removed
0
tests/unit/test_contrib/test_sqlalchemy/test_init_plugin/test_config/__init__.py
Empty file.
20 changes: 0 additions & 20 deletions
20
tests/unit/test_contrib/test_sqlalchemy/test_init_plugin/test_config/test_asyncio.py
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
tests/unit/test_contrib/test_sqlalchemy/test_init_plugin/test_config/test_sync.py
This file was deleted.
Oops, something went wrong.