Skip to content

Commit

Permalink
Add additional tests for pool related engine args
Browse files Browse the repository at this point in the history
refs #426
  • Loading branch information
rsyring committed Mar 14, 2019
1 parent 3d9616b commit 9a882ee
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tests/test_config.py
@@ -1,7 +1,8 @@
import flask_sqlalchemy as fsa

import mock
import pytest
from sqlalchemy.pool import NullPool

import flask_sqlalchemy as fsa


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

def test_engine_creation_ok(self, app):
""" create_engine() isn't called until needed. Let's make sure we can do that without
errors.
"""
assert fsa.SQLAlchemy(app).get_engine()


@pytest.fixture
def app_nr(app):
Expand Down Expand Up @@ -114,3 +121,24 @@ def test_config_from_init(self, m_create_engine, app_nr):

args, options = m_create_engine.call_args
assert options['bar'] == 'baz'

def test_pool_class_default(self, m_create_engine, app_nr):
fsa.SQLAlchemy(app_nr).get_engine()

args, options = m_create_engine.call_args
assert options['poolclass'].__name__ == 'StaticPool'

def test_pool_class_with_pool_size_zero(self, m_create_engine, app_nr):
app_nr.config['SQLALCHEMY_POOL_SIZE'] = 0
with pytest.raises(RuntimeError) as exc_info:
fsa.SQLAlchemy(app_nr).get_engine()
expected = 'SQLite in memory database with an empty queue not possible due to data loss.'
assert exc_info.value.args[0] == expected

def test_pool_class_nullpool(self, m_create_engine, app_nr):
engine_options = {'poolclass': NullPool}
fsa.SQLAlchemy(app_nr, engine_options=engine_options).get_engine()

args, options = m_create_engine.call_args
assert options['poolclass'].__name__ == 'NullPool'
assert 'pool_size' not in options

0 comments on commit 9a882ee

Please sign in to comment.