|
6 | 6 | from flask_sqlalchemy import _compat, utils
|
7 | 7 |
|
8 | 8 |
|
| 9 | +@pytest.fixture |
| 10 | +def app_nr(app): |
| 11 | + """ |
| 12 | + Signal/event registration with record queries breaks when |
| 13 | + sqlalchemy.create_engine() is mocked out. |
| 14 | + """ |
| 15 | + app.config['SQLALCHEMY_RECORD_QUERIES'] = False |
| 16 | + return app |
| 17 | + |
| 18 | + |
9 | 19 | class TestConfigKeys:
|
10 | 20 |
|
11 | 21 | def test_defaults(self, app):
|
@@ -81,15 +91,68 @@ def test_engine_creation_ok(self, app, recwarn):
|
81 | 91 |
|
82 | 92 | assert len(recwarn) == expected_warnings
|
83 | 93 |
|
| 94 | + @mock.patch.object(fsa.sqlalchemy, 'create_engine', autospec=True, spec_set=True) |
| 95 | + def test_native_unicode_deprecation_config_opt(self, m_create_engine, app_nr, recwarn): |
| 96 | + app_nr.config['SQLALCHEMY_NATIVE_UNICODE'] = False |
| 97 | + assert fsa.SQLAlchemy(app_nr).get_engine() |
| 98 | + assert len(recwarn) == 1 |
84 | 99 |
|
85 |
| -@pytest.fixture |
86 |
| -def app_nr(app): |
87 |
| - """ |
88 |
| - Signal/event registration with record queries breaks when |
89 |
| - sqlalchemy.create_engine() is mocked out. |
90 |
| - """ |
91 |
| - app.config['SQLALCHEMY_RECORD_QUERIES'] = False |
92 |
| - return app |
| 100 | + warning_msg = recwarn[0].message.args[0] |
| 101 | + assert 'SQLALCHEMY_NATIVE_UNICODE' in warning_msg |
| 102 | + assert 'deprecated and will be removed in v3.0' in warning_msg |
| 103 | + |
| 104 | + @mock.patch.object(fsa.sqlalchemy, 'create_engine', autospec=True, spec_set=True) |
| 105 | + def test_native_unicode_deprecation_init_opt(self, m_create_engine, app_nr, recwarn): |
| 106 | + assert fsa.SQLAlchemy(app_nr, use_native_unicode=False).get_engine() |
| 107 | + assert len(recwarn) == 1 |
| 108 | + |
| 109 | + warning_msg = recwarn[0].message.args[0] |
| 110 | + assert 'use_native_unicode' in warning_msg |
| 111 | + assert 'deprecated and will be removed in v3.0' in warning_msg |
| 112 | + |
| 113 | + @mock.patch.object(fsa.sqlalchemy, 'create_engine', autospec=True, spec_set=True) |
| 114 | + def test_deprecation_config_opt_pool_size(self, m_create_engine, app_nr, recwarn): |
| 115 | + app_nr.config['SQLALCHEMY_POOL_SIZE'] = 5 |
| 116 | + assert fsa.SQLAlchemy(app_nr).get_engine() |
| 117 | + assert len(recwarn) == 1 |
| 118 | + |
| 119 | + warning_msg = recwarn[0].message.args[0] |
| 120 | + assert 'SQLALCHEMY_POOL_SIZE' in warning_msg |
| 121 | + assert 'deprecated and will be removed in v3.0.' in warning_msg |
| 122 | + assert 'pool_size' in warning_msg |
| 123 | + |
| 124 | + @mock.patch.object(fsa.sqlalchemy, 'create_engine', autospec=True, spec_set=True) |
| 125 | + def test_deprecation_config_opt_pool_timeout(self, m_create_engine, app_nr, recwarn): |
| 126 | + app_nr.config['SQLALCHEMY_POOL_TIMEOUT'] = 5 |
| 127 | + assert fsa.SQLAlchemy(app_nr).get_engine() |
| 128 | + assert len(recwarn) == 1 |
| 129 | + |
| 130 | + warning_msg = recwarn[0].message.args[0] |
| 131 | + assert 'SQLALCHEMY_POOL_TIMEOUT' in warning_msg |
| 132 | + assert 'deprecated and will be removed in v3.0.' in warning_msg |
| 133 | + assert 'pool_timeout' in warning_msg |
| 134 | + |
| 135 | + @mock.patch.object(fsa.sqlalchemy, 'create_engine', autospec=True, spec_set=True) |
| 136 | + def test_deprecation_config_opt_pool_recycle(self, m_create_engine, app_nr, recwarn): |
| 137 | + app_nr.config['SQLALCHEMY_POOL_RECYCLE'] = 5 |
| 138 | + assert fsa.SQLAlchemy(app_nr).get_engine() |
| 139 | + assert len(recwarn) == 1 |
| 140 | + |
| 141 | + warning_msg = recwarn[0].message.args[0] |
| 142 | + assert 'SQLALCHEMY_POOL_RECYCLE' in warning_msg |
| 143 | + assert 'deprecated and will be removed in v3.0.' in warning_msg |
| 144 | + assert 'pool_recycle' in warning_msg |
| 145 | + |
| 146 | + @mock.patch.object(fsa.sqlalchemy, 'create_engine', autospec=True, spec_set=True) |
| 147 | + def test_deprecation_config_opt_max_overflow(self, m_create_engine, app_nr, recwarn): |
| 148 | + app_nr.config['SQLALCHEMY_MAX_OVERFLOW'] = 5 |
| 149 | + assert fsa.SQLAlchemy(app_nr).get_engine() |
| 150 | + assert len(recwarn) == 1 |
| 151 | + |
| 152 | + warning_msg = recwarn[0].message.args[0] |
| 153 | + assert 'SQLALCHEMY_MAX_OVERFLOW' in warning_msg |
| 154 | + assert 'deprecated and will be removed in v3.0.' in warning_msg |
| 155 | + assert 'max_overflow' in warning_msg |
93 | 156 |
|
94 | 157 |
|
95 | 158 | @mock.patch.object(fsa.sqlalchemy, 'create_engine', autospec=True, spec_set=True)
|
@@ -139,7 +202,7 @@ def test_pool_class_default(self, m_create_engine, app_nr):
|
139 | 202 | args, options = m_create_engine.call_args
|
140 | 203 | assert options['poolclass'].__name__ == 'StaticPool'
|
141 | 204 |
|
142 |
| - def test_pool_class_with_pool_size_zero(self, m_create_engine, app_nr): |
| 205 | + def test_pool_class_with_pool_size_zero(self, m_create_engine, app_nr, recwarn): |
143 | 206 | app_nr.config['SQLALCHEMY_POOL_SIZE'] = 0
|
144 | 207 | with pytest.raises(RuntimeError) as exc_info:
|
145 | 208 | fsa.SQLAlchemy(app_nr).get_engine()
|
|
0 commit comments