|
1 |
| -import flask_sqlalchemy as fsa |
2 |
| - |
3 | 1 | import mock
|
4 | 2 | import pytest
|
| 3 | +from sqlalchemy.pool import NullPool |
| 4 | + |
| 5 | +import flask_sqlalchemy as fsa |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class TestConfigKeys:
|
@@ -65,6 +66,12 @@ def test_uri_binds_warning(self, app, recwarn):
|
65 | 66 | ' "sqlite:///:memory:".'
|
66 | 67 | assert recwarn[0].message.args[0] == expect
|
67 | 68 |
|
| 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 | + |
68 | 75 |
|
69 | 76 | @pytest.fixture
|
70 | 77 | def app_nr(app):
|
@@ -114,3 +121,24 @@ def test_config_from_init(self, m_create_engine, app_nr):
|
114 | 121 |
|
115 | 122 | args, options = m_create_engine.call_args
|
116 | 123 | 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