Skip to content

Commit 16347ad

Browse files
committed
refs #387, add ssl parameters for all extensions
1 parent 13aed2f commit 16347ad

File tree

8 files changed

+52
-16
lines changed

8 files changed

+52
-16
lines changed

gino/ext/aiohttp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ async def before_server_start(app_):
130130
echo=config.setdefault('echo', False),
131131
min_size=config.setdefault('pool_min_size', 5),
132132
max_size=config.setdefault('pool_max_size', 10),
133-
ssl=config.setdefault("ssl"),
133+
ssl=config.setdefault('ssl'),
134134
loop=app_.loop,
135135
)
136136

gino/ext/quart.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import asyncio
22

3-
# noinspection PyPackageRequirements
43
from quart import Quart, request
5-
# noinspection PyPackageRequirements
64
from quart.exceptions import NotFound
75
from sqlalchemy.engine.url import URL
86

@@ -21,7 +19,6 @@ async def get_or_404(cls, *args, **kwargs):
2119
return rv
2220

2321

24-
# noinspection PyClassHasNoInit
2522
class GinoExecutor(_Executor):
2623
async def first_or_404(self, *args, **kwargs):
2724
rv = await self.first(*args, **kwargs)
@@ -30,7 +27,6 @@ async def first_or_404(self, *args, **kwargs):
3027
return rv
3128

3229

33-
# noinspection PyClassHasNoInit
3430
class GinoConnection(_Connection):
3531
async def first_or_404(self, *args, **kwargs):
3632
rv = await self.first(*args, **kwargs)
@@ -39,7 +35,6 @@ async def first_or_404(self, *args, **kwargs):
3935
return rv
4036

4137

42-
# noinspection PyClassHasNoInit
4338
class GinoEngine(_Engine):
4439
connection_cls = GinoConnection
4540

@@ -119,6 +114,7 @@ async def before_first_request():
119114
echo=app.config.setdefault('DB_ECHO', False),
120115
min_size=app.config.setdefault('DB_POOL_MIN_SIZE', 5),
121116
max_size=app.config.setdefault('DB_POOL_MAX_SIZE', 10),
117+
ssl=app.config.setdefault('DB_SSL'),
122118
loop=asyncio.get_event_loop(),
123119
)
124120

gino/ext/sanic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ async def before_server_start(_, loop):
111111
echo=app.config.setdefault('DB_ECHO', False),
112112
min_size=app.config.setdefault('DB_POOL_MIN_SIZE', 5),
113113
max_size=app.config.setdefault('DB_POOL_MAX_SIZE', 10),
114+
ssl=app.config.setdefault('DB_SSL'),
114115
loop=loop,
115116
)
116117

gino/ext/tornado.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
- ``'db_pool_max_inactive_conn_lifetime'`` -- number of seconds after which
7474
inactive connections in the pool will be closed. Pass ``0`` to disable this
7575
mechanism. Default is ``300``;
76-
- ``'db_pool_max_queries '`` -- number of queries after a connection is closed
76+
- ``'db_pool_max_queries'`` -- number of queries after a connection is closed
7777
and replaced with a new connection. Default is ``50000``.
7878
7979
@@ -343,7 +343,7 @@ async def late_init(self, db: Gino, *, loop=None, options=_options):
343343
options['db_pool_max_inactive_conn_lifetime']
344344
),
345345
max_queries=options['db_pool_max_queries'],
346-
loop=asyncio_loop
346+
loop=asyncio_loop,
347347
)
348348

349349

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import ssl
2+
13
import asyncpg
24
import pytest
35
import sqlalchemy
@@ -46,3 +48,11 @@ async def asyncpg_pool(sa_engine):
4648
await yield_(rv)
4749
await rv.execute('DELETE FROM gino_user_settings')
4850
await rv.execute('DELETE FROM gino_users')
51+
52+
53+
@pytest.fixture
54+
def ssl_ctx():
55+
ctx = ssl.create_default_context()
56+
ctx.check_hostname = False
57+
ctx.verify_mode = ssl.CERT_NONE
58+
return ctx

tests/test_aiohttp.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,8 @@ async def test_client_dsn():
8787

8888
@pytest.fixture
8989
@async_generator
90-
async def test_client_ssl():
91-
import ssl
92-
93-
ctx = ssl.create_default_context()
94-
ctx.check_hostname = False
95-
ctx.verify_mode = ssl.CERT_NONE
96-
97-
await _test_client(dict(dsn=PG_URL, ssl=ctx))
90+
async def test_client_ssl(ssl_ctx):
91+
await _test_client(dict(dsn=PG_URL, ssl=ssl_ctx))
9892

9993

10094
async def _test_index_returns_200(test_client):

tests/test_quart.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
23
import pytest
34

45
# Quart only supports Python 3.6 or later
@@ -110,6 +111,19 @@ async def app():
110111
})
111112

112113

114+
@pytest.fixture
115+
@async_generator
116+
async def app_ssl(ssl_ctx):
117+
await _app({
118+
'DB_HOST': DB_ARGS['host'],
119+
'DB_PORT': DB_ARGS['port'],
120+
'DB_USER': DB_ARGS['user'],
121+
'DB_PASSWORD': DB_ARGS['password'],
122+
'DB_DATABASE': DB_ARGS['database'],
123+
'DB_SSL': ssl_ctx,
124+
})
125+
126+
113127
@pytest.fixture
114128
@async_generator
115129
async def app_dsn():
@@ -152,6 +166,10 @@ async def test(app):
152166
await _test(app)
153167

154168

169+
async def test_ssl(app_ssl):
170+
await _test(app_ssl)
171+
172+
155173
async def test_dsn(app_dsn):
156174
await _test(app_dsn)
157175

tests/test_sanic.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ async def app():
7676
})
7777

7878

79+
@pytest.fixture
80+
@async_generator
81+
async def app_ssl(ssl_ctx):
82+
await _app({
83+
'DB_HOST': DB_ARGS['host'],
84+
'DB_PORT': DB_ARGS['port'],
85+
'DB_USER': DB_ARGS['user'],
86+
'DB_PASSWORD': DB_ARGS['password'],
87+
'DB_DATABASE': DB_ARGS['database'],
88+
'DB_SSL': ssl_ctx,
89+
})
90+
91+
7992
@pytest.fixture
8093
@async_generator
8194
async def app_dsn():
@@ -116,5 +129,9 @@ def test(app):
116129
_test(app)
117130

118131

132+
def test_ssl(app_ssl):
133+
_test(app_ssl)
134+
135+
119136
def test_dsn(app_dsn):
120137
_test(app_dsn)

0 commit comments

Comments
 (0)