-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add duplicated key exceptions and some tests
- Loading branch information
1 parent
4592eda
commit a084021
Showing
3 changed files
with
48 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
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,10 @@ | ||
class DuplicatedAppKeyError(ValueError): | ||
def __init__(self, key): | ||
self.message = f'Duplicated app key `{key}`. Check `engines` argument in `aiohttp_sqlalchemy.setup()` call.' | ||
super().__init__(self.message) | ||
|
||
|
||
class DuplicatedRequestKeyError(ValueError): | ||
def __init__(self, key): | ||
self.message = f'Duplicated request key `{key}`. Check middlewares and decorators from `aiohttp_sqlalchemy`.' | ||
super().__init__(self.message) |
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,30 @@ | ||
from aiohttp import web | ||
import aiohttp_sqlalchemy | ||
from aiohttp_sqlalchemy import sa_engine | ||
import pytest | ||
from sqlalchemy.ext.asyncio import create_async_engine | ||
from aiohttp_sqlalchemy.exceptions import DuplicatedAppKeyError, DuplicatedRequestKeyError | ||
|
||
|
||
def test_aiohttp_sqlalchemy_setup(): | ||
engine = create_async_engine('sqlite+aiosqlite:///') | ||
|
||
app = web.Application() | ||
with pytest.raises(DuplicatedAppKeyError): | ||
aiohttp_sqlalchemy.setup(app, [ | ||
sa_engine(engine), | ||
sa_engine(engine), | ||
]) | ||
|
||
app = web.Application() | ||
with pytest.raises(DuplicatedAppKeyError): | ||
aiohttp_sqlalchemy.setup(app, [ | ||
sa_engine(engine, 'sa_secondary'), | ||
sa_engine(engine, 'sa_secondary'), | ||
]) | ||
|
||
app = web.Application() | ||
aiohttp_sqlalchemy.setup(app, [ | ||
sa_engine(engine), | ||
sa_engine(engine, 'sa_secondary'), | ||
]) |