Skip to content

Commit ead0dce

Browse files
committed
Add additional tests for pool related engine args
refs pallets-eco#426
1 parent e507833 commit ead0dce

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tests/test_config.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import flask_sqlalchemy as fsa
2-
31
import mock
42
import pytest
3+
from sqlalchemy.pool import NullPool
4+
5+
import flask_sqlalchemy as fsa
56

67

78
class TestConfigKeys:
@@ -65,6 +66,12 @@ def test_uri_binds_warning(self, app, recwarn):
6566
' "sqlite:///:memory:".'
6667
assert recwarn[0].message.args[0] == expect
6768

69+
def test_engine_creation_ok(self, app):
70+
""" create_engine() isn't called until needed. Let's make sure we can do that without
71+
errors.
72+
"""
73+
assert fsa.SQLAlchemy(app).get_engine()
74+
6875

6976
@pytest.fixture
7077
def app_nr(app):
@@ -114,3 +121,24 @@ def test_config_from_init(self, m_create_engine, app_nr):
114121

115122
args, options = m_create_engine.call_args
116123
assert options['bar'] == 'baz'
124+
125+
def test_pool_class_default(self, m_create_engine, app_nr):
126+
fsa.SQLAlchemy(app_nr).get_engine()
127+
128+
args, options = m_create_engine.call_args
129+
assert options['poolclass'].__name__ == 'StaticPool'
130+
131+
def test_pool_class_with_pool_size_zero(self, m_create_engine, app_nr):
132+
app_nr.config['SQLALCHEMY_POOL_SIZE'] = 0
133+
with pytest.raises(RuntimeError) as exc_info:
134+
fsa.SQLAlchemy(app_nr).get_engine()
135+
expected = 'SQLite in memory database with an empty queue not possible due to data loss.'
136+
assert exc_info.value.args[0] == expected
137+
138+
def test_pool_class_nullpool(self, m_create_engine, app_nr):
139+
engine_options = {'poolclass': NullPool}
140+
fsa.SQLAlchemy(app_nr, engine_options=engine_options).get_engine()
141+
142+
args, options = m_create_engine.call_args
143+
assert options['poolclass'].__name__ == 'NullPool'
144+
assert 'pool_size' not in options

0 commit comments

Comments
 (0)