From 55aaddadf8ceaa4835efb0ed89d37f1c155569e1 Mon Sep 17 00:00:00 2001
From: Daniel Levy <daniell@aptivate.org>
Date: Wed, 10 Jun 2015 11:47:43 +0100
Subject: [PATCH] Fix issue with remaining logged in after logout

---
 django/website/hid/tests/fast_dispatch.py         | 14 +++++++++-----
 .../hid/tests/site_needs_authentication_tests.py  | 15 +++++++++++++++
 .../templates/registration/logged_out.html        | 12 ++++++++++++
 3 files changed, 36 insertions(+), 5 deletions(-)
 create mode 100644 django/website/templates/registration/logged_out.html

diff --git a/django/website/hid/tests/fast_dispatch.py b/django/website/hid/tests/fast_dispatch.py
index a6448738..27c76334 100644
--- a/django/website/hid/tests/fast_dispatch.py
+++ b/django/website/hid/tests/fast_dispatch.py
@@ -39,14 +39,18 @@ class FakeSession(collections.MutableMapping):
     def set_test_cookie(self):
         pass
 
+    def flush(self):
+        pass
+
+
 class FastDispatchMixin(object):
 
     default_cms_page = None
 
-    def get_fake_request(self, path, method='get', get_params=None, 
+    def get_fake_request(self, path, method='get', get_params=None,
         post_params=None, request_extras=None, file_params=None):
 
-        get_params  = get_params  if get_params  else {}
+        get_params = get_params  if get_params  else {}
         post_params = post_params if post_params else {}
         file_params = file_params if file_params else {}
 
@@ -107,12 +111,12 @@ class FastDispatchMixin(object):
 
         return request
 
-    def fast_dispatch(self, view_name, method='get', url_args=None, 
+    def fast_dispatch(self, view_name, method='get', url_args=None,
         url_kwargs=None, post_params=None, get_params=None, language=None,
         request_extras=None, file_params=None):
 
-        url_args    = url_args    if url_args    else []
-        url_kwargs  = url_kwargs  if url_kwargs  else {}
+        url_args = url_args    if url_args    else []
+        url_kwargs = url_kwargs  if url_kwargs  else {}
 
         from django.utils.translation import override
         with override(language):
diff --git a/django/website/hid/tests/site_needs_authentication_tests.py b/django/website/hid/tests/site_needs_authentication_tests.py
index 18ca6670..dd8dc443 100644
--- a/django/website/hid/tests/site_needs_authentication_tests.py
+++ b/django/website/hid/tests/site_needs_authentication_tests.py
@@ -18,3 +18,18 @@ class SiteNeedsAuthenticationTests(FastDispatchMixin, SimpleTestCase):
         response.render()
 
         self.assertIn('dashboard', response.content)
+
+    def test_logout_view_logs_user_out(self):
+        self.user = User()
+
+        self.fast_dispatch('dashboard')
+
+        # The user when logged out should be None or AnonymousUser
+        # We check that logout works by getting the user from the logout
+        # request and using it as the user for the next one.
+        response = self.fast_dispatch('logout')
+        self.user = response.view.request.user
+
+        response = self.fast_dispatch('dashboard')
+
+        self.assertEqual(settings.LOGIN_URL + '?next=' + reverse('dashboard'), response['Location'])
diff --git a/django/website/templates/registration/logged_out.html b/django/website/templates/registration/logged_out.html
new file mode 100644
index 00000000..2e883607
--- /dev/null
+++ b/django/website/templates/registration/logged_out.html
@@ -0,0 +1,12 @@
+{% extends "base.html" %}
+{% load i18n %}
+{% load bootstrap3 %}
+
+
+{% block content %}
+<h1>{% trans "Logged out" %}</h1>
+<p>
+	 You are logged out.
+	 <a href="{% url "login" %}">{% trans "Log in again." %}</a>
+</p>
+{% endblock content %}
\ No newline at end of file
-- 
GitLab