-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.3.0: 100% coverage + fix unit of work commit, rollback, close meth…
…ods, when not using via context manager
- Loading branch information
1 parent
8a1162d
commit 58827a4
Showing
10 changed files
with
150 additions
and
23 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
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
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,41 @@ | ||
import pytest | ||
from sqlalchemy.ext.asyncio import AsyncSession, async_scoped_session | ||
|
||
from sqlrepo.exc import NonContextManagerUOWUsageError | ||
from sqlrepo.uow import BaseAsyncUnitOfWork | ||
|
||
|
||
@pytest.mark.asyncio() | ||
async def test_skip_session_use( | ||
db_async_session_factory: async_scoped_session[AsyncSession], | ||
) -> None: | ||
class SkipUOW(BaseAsyncUnitOfWork): | ||
__skip_session_use__ = True | ||
session_factory = db_async_session_factory # type: ignore | ||
|
||
def init_repositories(self, session: AsyncSession) -> None: | ||
pass | ||
|
||
async with SkipUOW() as uow: | ||
await uow.commit() | ||
await uow.rollback() | ||
await uow.close() | ||
|
||
|
||
@pytest.mark.asyncio() | ||
async def test_incorrect_uow_usage( | ||
db_async_session_factory: async_scoped_session[AsyncSession], | ||
) -> None: | ||
class IncorrectUOW(BaseAsyncUnitOfWork): | ||
session_factory = db_async_session_factory # type: ignore | ||
|
||
def init_repositories(self, session: AsyncSession) -> None: | ||
pass | ||
|
||
instance = IncorrectUOW() | ||
with pytest.raises(NonContextManagerUOWUsageError): | ||
await instance.commit() | ||
with pytest.raises(NonContextManagerUOWUsageError): | ||
await instance.rollback() | ||
with pytest.raises(NonContextManagerUOWUsageError): | ||
await instance.close() |
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,35 @@ | ||
import pytest | ||
from sqlalchemy.orm import Session, scoped_session | ||
|
||
from sqlrepo.exc import NonContextManagerUOWUsageError | ||
from sqlrepo.uow import BaseSyncUnitOfWork | ||
|
||
|
||
def test_skip_session_use(db_sync_session_factory: scoped_session[Session]) -> None: | ||
class SkipUOW(BaseSyncUnitOfWork): | ||
__skip_session_use__ = True | ||
session_factory = db_sync_session_factory # type: ignore | ||
|
||
def init_repositories(self, session: Session) -> None: | ||
pass | ||
|
||
with SkipUOW() as uow: | ||
uow.commit() | ||
uow.rollback() | ||
uow.close() | ||
|
||
|
||
def test_incorrect_uow_usage(db_sync_session_factory: scoped_session[Session]) -> None: | ||
class IncorrectUOW(BaseSyncUnitOfWork): | ||
session_factory = db_sync_session_factory # type: ignore | ||
|
||
def init_repositories(self, session: Session) -> None: | ||
pass | ||
|
||
instance = IncorrectUOW() | ||
with pytest.raises(NonContextManagerUOWUsageError): | ||
instance.commit() | ||
with pytest.raises(NonContextManagerUOWUsageError): | ||
instance.rollback() | ||
with pytest.raises(NonContextManagerUOWUsageError): | ||
instance.close() |
Empty file.