Skip to content

Commit

Permalink
Update docs and add test for new config key SESSION_SQLALCHEMY_CREATE…
Browse files Browse the repository at this point in the history
…_TABLE
  • Loading branch information
Lee Goolsbee committed Apr 17, 2024
1 parent b2db95f commit 78df10e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,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.
Expand Down
19 changes: 19 additions & 0 deletions tests/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 78df10e

Please sign in to comment.