@@ -18,18 +18,39 @@ def app_nr(app):
18
18
19
19
class TestConfigKeys :
20
20
21
- def test_defaults (self , app , recwarn ):
21
+ def test_default_error_without_uri_or_binds (self , app , recwarn ):
22
22
"""
23
- Test all documented config values in the order they appear in our
24
- documentation: http://flask-sqlalchemy.pocoo.org/dev/config/
23
+ Test that default configuration throws an error because
24
+ SQLALCHEMY_DATABASE_URI and SQLALCHEMY_BINDS are unset
25
25
"""
26
26
27
27
fsa .SQLAlchemy (app )
28
28
29
- # Expecting no warnings for default config
29
+ # Our pytest fixture for creating the app sets
30
+ # SQLALCHEMY_DATABASE_URI, so undo that here so that we
31
+ # can inspect what FSA does below:
32
+ del app .config ['SQLALCHEMY_DATABASE_URI' ]
33
+
34
+ with pytest .raises (RuntimeError ) as exc_info :
35
+ fsa .SQLAlchemy (app )
36
+
37
+ expected = 'Either SQLALCHEMY_DATABASE_URI ' \
38
+ 'or SQLALCHEMY_BINDS needs to be set.'
39
+ assert exc_info .value .args [0 ] == expected
40
+
41
+ def test_defaults_with_uri (self , app , recwarn ):
42
+ """
43
+ Test default config values when URI is provided, in the order they
44
+ appear in the documentation: http://flask-sqlalchemy.pocoo.org/dev/config/
45
+
46
+ Our pytest fixture for creating the app sets SQLALCHEMY_DATABASE_URI
47
+ """
48
+
49
+ fsa .SQLAlchemy (app )
50
+
51
+ # Expecting no warnings for default config with URI
30
52
assert len (recwarn ) == 0
31
53
32
- assert app .config ['SQLALCHEMY_DATABASE_URI' ] == 'sqlite:///:memory:'
33
54
assert app .config ['SQLALCHEMY_BINDS' ] is None
34
55
assert app .config ['SQLALCHEMY_ECHO' ] is False
35
56
assert app .config ['SQLALCHEMY_RECORD_QUERIES' ] is None
@@ -41,18 +62,6 @@ def test_defaults(self, app, recwarn):
41
62
assert app .config ['SQLALCHEMY_TRACK_MODIFICATIONS' ] is False
42
63
assert app .config ['SQLALCHEMY_ENGINE_OPTIONS' ] == {}
43
64
44
- def test_uri_binds_warning (self , app , recwarn ):
45
- # Let's trigger the warning
46
- del app .config ['SQLALCHEMY_DATABASE_URI' ]
47
- fsa .SQLAlchemy (app )
48
-
49
- # and verify it showed up as expected
50
- assert len (recwarn ) == 1
51
- expect = 'Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS' \
52
- ' is set. Defaulting SQLALCHEMY_DATABASE_URI to' \
53
- ' "sqlite:///:memory:".'
54
- assert recwarn [0 ].message .args [0 ] == expect
55
-
56
65
def test_engine_creation_ok (self , app , recwarn ):
57
66
""" create_engine() isn't called until needed. Let's make sure we can do that without
58
67
errors or warnings.
0 commit comments