mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 17:32:38 +02:00
Migrate existing sessions after conversion to dict (#1194)
Migrate existing session after #1082 fix #1188
This commit is contained in:
parent
b150c7adc5
commit
23d912b703
2 changed files with 27 additions and 0 deletions
|
@ -1665,6 +1665,26 @@ class BudgetTestCase(IhatemoneyTestCase):
|
||||||
# No bills, the previous one was not added
|
# No bills, the previous one was not added
|
||||||
self.assertIn("No bills", resp.data.decode("utf-8"))
|
self.assertIn("No bills", resp.data.decode("utf-8"))
|
||||||
|
|
||||||
|
def test_session_projects_migration_to_list(self):
|
||||||
|
"""In https://github.com/spiral-project/ihatemoney/pull/1082, session["projects"]
|
||||||
|
was migrated from a list to a dict. We need to handle this.
|
||||||
|
"""
|
||||||
|
self.post_project("raclette")
|
||||||
|
self.client.get("/exit")
|
||||||
|
|
||||||
|
with self.client as c:
|
||||||
|
c.post("/authenticate", data={"id": "raclette", "password": "raclette"})
|
||||||
|
self.assertTrue(session["raclette"])
|
||||||
|
# New behavior
|
||||||
|
self.assertIsInstance(session["projects"], dict)
|
||||||
|
# Now, go back to the past
|
||||||
|
with c.session_transaction() as sess:
|
||||||
|
sess["projects"] = [("raclette", "raclette")]
|
||||||
|
# It should convert entry to dict
|
||||||
|
c.get("/")
|
||||||
|
self.assertIsInstance(session["projects"], dict)
|
||||||
|
self.assertIn("raclette", session["projects"])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -112,6 +112,13 @@ def add_project_id(endpoint, values):
|
||||||
values["project_id"] = g.project.id
|
values["project_id"] = g.project.id
|
||||||
|
|
||||||
|
|
||||||
|
@main.url_value_preprocessor
|
||||||
|
def migrate_session(endpoint, values):
|
||||||
|
if "projects" in session and isinstance(session["projects"], list):
|
||||||
|
# Migrate https://github.com/spiral-project/ihatemoney/pull/1082
|
||||||
|
session["projects"] = {id: name for (id, name) in session["projects"]}
|
||||||
|
|
||||||
|
|
||||||
@main.url_value_preprocessor
|
@main.url_value_preprocessor
|
||||||
def set_show_admin_dashboard_link(endpoint, values):
|
def set_show_admin_dashboard_link(endpoint, values):
|
||||||
"""Sets the "show_admin_dashboard_link" variable application wide
|
"""Sets the "show_admin_dashboard_link" variable application wide
|
||||||
|
|
Loading…
Reference in a new issue