From 8b54a5fde65298aa6aa7cac2b9a47225f0e07366 Mon Sep 17 00:00:00 2001 From: Lee Goolsbee Date: Tue, 16 Apr 2024 10:35:41 -0500 Subject: [PATCH] Update docs and add test for new config key SESSION_SQLALCHEMY_CREATE_TABLE --- docs/config_reference.rst | 6 ++++++ tests/test_sqlalchemy.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/docs/config_reference.rst b/docs/config_reference.rst index e3ace977..e5f8354a 100644 --- a/docs/config_reference.rst +++ b/docs/config_reference.rst @@ -174,6 +174,12 @@ SqlAlchemy Default: ``'sessions'`` +.. py:data:: SESSION_SQLALCHEMY_CREATE_TABLE + + Whether (or not) Flask-Session should manage creation of the table for storing session data. + + Default: ``True`` + .. py:data:: SESSION_SQLALCHEMY_SEQUENCE The name of the sequence you want to use for the primary key. diff --git a/tests/test_sqlalchemy.py b/tests/test_sqlalchemy.py index e8c34b9e..036d24a5 100644 --- a/tests/test_sqlalchemy.py +++ b/tests/test_sqlalchemy.py @@ -57,3 +57,22 @@ def test_use_signer(self, app_utils): json.loads(byte_string.decode("utf-8")) if byte_string else {} ) assert stored_session.get("value") == "44" + + @pytest.mark.filterwarnings("ignore:No valid SQLAlchemy instance provided") + def test_database_not_created_automatically(self, app_utils): + app = app_utils.create_app( + { + "SESSION_TYPE": "sqlalchemy", + "SQLALCHEMY_DATABASE_URI": "sqlite:///", + "SESSION_SQLALCHEMY_CREATE_TABLE": False, + } + ) + with app.app_context() and self.setup_sqlalchemy( + app + ) and app.test_request_context(): + assert isinstance( + flask.session, + SqlAlchemySession, + ) + with pytest.raises(AssertionError): + app_utils.test_session(app)