From 51427323e68c6fef19a72fad48dd44f933207811 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 29 Jun 2020 11:31:35 -0700 Subject: [PATCH] Add message when user logs out, refs #840 --- datasette/views/special.py | 1 + tests/fixtures.py | 3 ++- tests/test_auth.py | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/datasette/views/special.py b/datasette/views/special.py index 374ca9f2..51688f36 100644 --- a/datasette/views/special.py +++ b/datasette/views/special.py @@ -86,6 +86,7 @@ class LogoutView(BaseView): async def post(self, request): response = Response.redirect("/") response.set_cookie("ds_actor", "", expires=0, max_age=0) + self.ds.add_message(request, "You are now logged out", self.ds.WARNING) return response diff --git a/tests/fixtures.py b/tests/fixtures.py index d103fa35..94a3cce5 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -97,7 +97,8 @@ class TestResponse: @property def cookies(self): cookie = SimpleCookie() - cookie.load(self.headers.get("set-cookie") or "") + for header in self.headers.getlist("set-cookie"): + cookie.load(header) return {key: value.value for key, value in cookie.items()} @property diff --git a/tests/test_auth.py b/tests/test_auth.py index 96a8bef9..145a9a89 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -74,5 +74,7 @@ def test_logout(app_client): cookies={"ds_actor": app_client.actor_cookie({"id": "test"})}, allow_redirects=False, ) - assert {"ds_actor": ""} == response4.cookies - assert 302 == response4.status + assert "" == response4.cookies["ds_actor"] + # Should also have set a message + messages = app_client.ds.unsign(response4.cookies["ds_messages"], "messages") + assert [["You are now logged out", 2]] == messages