Skip to content

Commit

Permalink
Merge branch 'release/0.9.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ri-gilfanov committed Jun 9, 2021
2 parents 0bc247e + b4b9700 commit fc8cd3d
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 72 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: python
python:
- 3.8
before_install:
- pip install poetry
install:
- poetry install
script:
- pytest --cov=aiohttp_sqlalchemy tests/
17 changes: 17 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
==================
aiohttp-sqlalchemy
==================
.. image:: https://readthedocs.org/projects/aiohttp-sqlalchemy/badge/?version=latest
:target: https://aiohttp-sqlalchemy.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://badge.fury.io/py/aiohttp-sqlalchemy.svg
:target: https://badge.fury.io/py/aiohttp-sqlalchemy

.. image:: https://img.shields.io/pypi/dm/aiohttp-sqlalchemy
:target: https://pypistats.org/packages/aiohttp-sqlalchemy
:alt: Downloads count

.. image:: https://travis-ci.com/ri-gilfanov/aiohttp-sqlalchemy.svg?branch=master
:target: https://travis-ci.com/ri-gilfanov/aiohttp-sqlalchemy

.. image:: https://coveralls.io/repos/github/ri-gilfanov/aiohttp-sqlalchemy/badge.svg?branch=master
:target: https://coveralls.io/github/ri-gilfanov/aiohttp-sqlalchemy?branch=master

SQLAlchemy 1.4 / 2.0 support for aiohttp.

Library forward a ``sqlalchemy.ext.asyncio.AsyncSession`` object as
Expand Down
11 changes: 6 additions & 5 deletions aiohttp_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
from sqlalchemy.ext.asyncio import AsyncSession
from typing import TYPE_CHECKING

from aiohttp_sqlalchemy.constants import DEFAULT_KEY
from aiohttp_sqlalchemy.decorators import sa_decorator
from aiohttp_sqlalchemy.exceptions import DuplicateAppKeyError, DuplicateRequestKeyError
from aiohttp_sqlalchemy.middlewares import sa_middleware
from aiohttp_sqlalchemy.views import SABaseView, SAView
from aiohttp_sqlalchemy.views import SAAbstractView, SABaseView, SAView


if TYPE_CHECKING:
from aiohttp.web import Application
from sqlalchemy.ext.asyncio import AsyncSession
from typing import Callable, Iterable, Tuple

TSessionFactory = Callable[..., AsyncSession]
TSABinding = Tuple[TSessionFactory, str, bool]


__version__ = '0.9.1'
__version__ = '0.9.2'

__all__ = ['DuplicateAppKeyError', 'DuplicateRequestKeyError', 'SABaseView',
'sa_bind', 'sa_decorator', 'sa_middleware', 'SAView', 'setup',]
__all__ = ['DuplicateAppKeyError', 'DuplicateRequestKeyError',
'SAAbstractView', 'SABaseView', 'sa_bind', 'sa_decorator',
'sa_middleware', 'SAView', 'setup',]


def sa_bind(factory: 'TSessionFactory', key: str = DEFAULT_KEY, *,
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Ruslan Ilyasovich Gilfanov'

# The full version, including alpha/beta/rc tags
release = '0.9.1'
release = '0.9.2'


# -- General configuration ---------------------------------------------------
Expand Down
79 changes: 40 additions & 39 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,99 +181,100 @@ Version 0.9
^^^^^^^^^^^
Added
"""""
``sa_decorator(key)`` added support of `organized handlers in class
<https://docs.aiohttp.org/en/stable/web_quickstart.html#organizing-handlers-in-classes>`_.
* Support of `organized handlers in class
<https://docs.aiohttp.org/en/stable/web_quickstart.html#organizing-handlers-in-classes>`_
added to ``sa_decorator(key)``.

Removed
"""""""
Removed support of ``AsyncEngine`` type in ``sa_bind()`` signature. Use
``sessionmaker(engine, AsyncSession)`` or custom session factory returning
``AsyncSession`` instance.
* Removed support of ``AsyncEngine`` type in ``sa_bind()`` signature. Use
``sessionmaker(engine, AsyncSession)`` or custom session factory returning
``AsyncSession`` instance.

Version 0.8
^^^^^^^^^^^
Changed
"""""""
Rename first argument from ``arg`` to ``factory`` in ``sa_bind()`` signature.
* Rename first argument from ``arg`` to ``factory`` in ``sa_bind()``
signature.

Deprecated
""""""""""
``AsyncEngine`` type is deprecated in ``sa_bind()`` signature. Use
``sessionmaker(engine, AsyncSession)`` or custom session factory returning
``AsyncSession`` instance.
* ``AsyncEngine`` type is deprecated in ``sa_bind()`` signature. Use
``sessionmaker(engine, AsyncSession)`` or custom session factory returning
``AsyncSession`` instance.

Version 0.7
^^^^^^^^^^^
Changed
"""""""
Usage ``sqlalchemy.orm.sessionmaker`` instance is recomended as a first
argument for ``aiohttp_sqlalchemy.sa_bind()`` signature. See examples
in documetation.
* Usage ``sqlalchemy.orm.sessionmaker`` instance is recomended as a first
argument for ``aiohttp_sqlalchemy.sa_bind()`` signature. See examples
in documetation.

Removed
"""""""
Removed support of ``request.config_dict.get('sa_main')`` and
``request.app['sa_main']`` expressions. Use a ``request['sa_main'].bind``
expression.
* Removed support of ``request.config_dict.get('sa_main')`` and
``request.app['sa_main']`` expressions. Use a ``request['sa_main'].bind``
expression.

Version 0.6
^^^^^^^^^^^
Added
"""""
Add support ``sqlalchemy.orm.sessionmaker`` as a first argument in function
``sa_bind(arg, key, middleware)``.
* Add support ``sqlalchemy.orm.sessionmaker`` as a first argument in function
``sa_bind(arg, key, middleware)``.

Changed
"""""""
Argument ``engine: AsyncEngine`` changed to ``arg: Union[AsyncEngine,
sessionmaker]`` in ``sa_bind()`` signature.
* Argument ``engine: AsyncEngine`` changed to ``arg: Union[AsyncEngine,
sessionmaker]`` in ``sa_bind()`` signature.

Deprecated
""""""""""
Deprecated support of ``request.config_dict.get('sa_main')`` and
``request.app['sa_main']`` expressions. Use a ``request['sa_main'].bind``
expression.
* Deprecated support of ``request.config_dict.get('sa_main')`` and
``request.app['sa_main']`` expressions. Use a ``request['sa_main'].bind``
expression.

Removed
"""""""
Deprecated class ``views.SAViewMixin`` is removed. Use
``views.SAAbstractView``.

Deprecated attribute ``SAView.sa_main_session`` is removed. Use method
``SAView.sa_session(key: str = 'sa_main')``.
* Deprecated class ``views.SAViewMixin`` is removed. Use
``views.SAAbstractView``.
* Deprecated attribute ``SAView.sa_main_session`` is removed. Use method
``SAView.sa_session(key: str = 'sa_main')``.

Version 0.5
^^^^^^^^^^^
Removed
"""""""
Deprecated function ``aiohttp_sqlalchemy.sa_engine()`` is removed. Use
``aiohttp_sqlalchemy.sa_bind()``.
* Deprecated function ``aiohttp_sqlalchemy.sa_engine()`` is removed. Use
``aiohttp_sqlalchemy.sa_bind()``.

Deprecated
""""""""""
Undocumented class ``views.SAViewMixin`` is deprecated. Use
``views.SAAbstractView``.
* Undocumented class ``views.SAViewMixin`` is deprecated. Use
``views.SAAbstractView``.

Version 0.4
^^^^^^^^^^^
Added
"""""
``SAView.sa_session(key: str = 'sa_main')`` function is added instead
``SAView.sa_main_session``.
* ``SAView.sa_session(key: str = 'sa_main')`` function is added instead
``SAView.sa_main_session``.

Deprecated
""""""""""
``SAView.sa_main_session`` is deprecated. Use
``SAView.sa_session(key: str = 'sa_main')``.
* ``SAView.sa_main_session`` is deprecated. Use
``SAView.sa_session(key: str = 'sa_main')``.

Version 0.3
^^^^^^^^^^^
Added
"""""
``aiohttp_sqlalchemy.sa_bind()`` function is added instead
``aiohttp_sqlalchemy.sa_engine()``.
* ``aiohttp_sqlalchemy.sa_bind()`` function is added instead
``aiohttp_sqlalchemy.sa_engine()``.

Deprecated
""""""""""
``aiohttp_sqlalchemy.sa_engine()`` function is deprecated. Use
``aiohttp_sqlalchemy.sa_bind()``.
* ``aiohttp_sqlalchemy.sa_engine()`` function is deprecated. Use
``aiohttp_sqlalchemy.sa_bind()``.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aiohttp-sqlalchemy"
version = "0.9.1"
version = "0.9.2"
description = "SQLAlchemy 1.4 / 2.0 support for aiohttp."
authors = [
"Ruslan Ilyasovich Gilfanov <ri.gilfanov@yandex.ru>",
Expand Down
11 changes: 5 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from aiohttp_sqlalchemy.middlewares import sa_middleware
from aiohttp import web
from aiohttp.hdrs import METH_GET
from aiohttp.test_utils import make_mocked_request
import pytest
from sqlalchemy import orm
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine

import aiohttp_sqlalchemy
from aiohttp_sqlalchemy import sa_bind
from aiohttp_sqlalchemy import sa_bind, sa_middleware
from aiohttp_sqlalchemy.constants import DEFAULT_KEY


pytest_plugins = 'aiohttp.pytest_plugin'
Expand All @@ -24,11 +26,8 @@ def sa_session(sa_session_factory):

@pytest.fixture
def sa_main_middleware():
return sa_middleware('sa_main')

return sa_middleware(DEFAULT_KEY)

from aiohttp.hdrs import METH_GET
from aiohttp.test_utils import make_mocked_request

@pytest.fixture
def middlewared_app(sa_session_factory):
Expand Down
22 changes: 11 additions & 11 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import pytest
from sqlalchemy.ext.asyncio import AsyncSession

from aiohttp_sqlalchemy import sa_decorator
from aiohttp_sqlalchemy.exceptions import DuplicateRequestKeyError
from aiohttp_sqlalchemy import DuplicateRequestKeyError, sa_decorator
from aiohttp_sqlalchemy.constants import DEFAULT_KEY
from tests.conftest import ClassBasedView, ClassHandler, function_handler


async def test_duplicate_request_key_error(mocked_request, sa_session):
assert mocked_request.get('sa_main') is None
mocked_request['sa_main'] = sa_session
assert mocked_request.get('sa_main') is sa_session
assert mocked_request.get(DEFAULT_KEY) is None
mocked_request[DEFAULT_KEY] = sa_session
assert mocked_request.get(DEFAULT_KEY) is sa_session
with pytest.raises(DuplicateRequestKeyError):
await sa_decorator()(function_handler)(mocked_request)


async def test_decorated_class_based_view(mocked_request):
assert mocked_request.get('sa_main') is None
assert mocked_request.get(DEFAULT_KEY) is None
await sa_decorator()(ClassBasedView.get)(mocked_request)
assert isinstance(mocked_request.get('sa_main'), AsyncSession)
assert isinstance(mocked_request.get(DEFAULT_KEY), AsyncSession)


async def test_decorated_class_handler(mocked_request):
assert mocked_request.get('sa_main') is None
assert mocked_request.get(DEFAULT_KEY) is None
await sa_decorator()(ClassHandler.get)(mocked_request)
assert isinstance(mocked_request.get('sa_main'), AsyncSession)
assert isinstance(mocked_request.get(DEFAULT_KEY), AsyncSession)


async def test_decorated_function_handler(mocked_request):
assert mocked_request.get('sa_main') is None
assert mocked_request.get(DEFAULT_KEY) is None
await sa_decorator()(function_handler)(mocked_request)
assert isinstance(mocked_request.get('sa_main'), AsyncSession)
assert isinstance(mocked_request.get(DEFAULT_KEY), AsyncSession)
13 changes: 7 additions & 6 deletions tests/test_middlewares.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import pytest
from sqlalchemy.ext.asyncio import AsyncSession

from aiohttp_sqlalchemy.exceptions import DuplicateRequestKeyError
from aiohttp_sqlalchemy import DuplicateRequestKeyError
from aiohttp_sqlalchemy.constants import DEFAULT_KEY
from tests.conftest import function_handler


async def test_duplicate_request_key_error(sa_main_middleware, mocked_request, sa_session):
assert mocked_request.get('sa_main') is None
mocked_request['sa_main'] = sa_session
assert mocked_request.get('sa_main') is sa_session
assert mocked_request.get(DEFAULT_KEY) is None
mocked_request[DEFAULT_KEY] = sa_session
assert mocked_request.get(DEFAULT_KEY) is sa_session

with pytest.raises(DuplicateRequestKeyError):
await sa_main_middleware(mocked_request, function_handler)


async def test_sa_middleware(sa_main_middleware, mocked_request):
assert mocked_request.get('sa_main') is None
assert mocked_request.get(DEFAULT_KEY) is None
await sa_main_middleware(mocked_request, function_handler)
assert isinstance(mocked_request.get('sa_main'), AsyncSession)
assert isinstance(mocked_request.get(DEFAULT_KEY), AsyncSession)
3 changes: 1 addition & 2 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import pytest

import aiohttp_sqlalchemy
from aiohttp_sqlalchemy import sa_bind
from aiohttp_sqlalchemy.exceptions import DuplicateAppKeyError
from aiohttp_sqlalchemy import DuplicateAppKeyError, sa_bind


async def test_duplicate_app_key_error(sa_session_factory):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from aiohttp_sqlalchemy import SABaseView
from aiohttp_sqlalchemy.constants import DEFAULT_KEY


def test_sa_session(mocked_request, sa_session):
mocked_request['sa_main'] = sa_session
mocked_request[DEFAULT_KEY] = sa_session
view = SABaseView(mocked_request)
assert view.sa_session() is sa_session

0 comments on commit fc8cd3d

Please sign in to comment.