Control: tag -1 + patch

On Wed, 13 Aug 2014, Thomas Goirand wrote:
> Hi,
> 
> It doesn't look like just calling django.setup() is enough to fix the
> unit tests. There's lots of other errors appearing like this one:

In fact, everything comes down to a simple fix. I have attached
the required patches.

Cheers,
-- 
Raphaël Hertzog ◈ Debian Developer

Discover the Debian Administrator's Handbook:
→ http://debian-handbook.info/get/
>From 26c0fbc8e85a59e25feb3414f5504f98de14d47e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= <[email protected]>
Date: Fri, 5 Sep 2014 17:20:49 +0200
Subject: [PATCH 1/2] Call django.setup() before running tests for Django 1.7
 compatibility

---
 openstack_auth/tests/run_tests.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/openstack_auth/tests/run_tests.py b/openstack_auth/tests/run_tests.py
index 0252903..46c474c 100644
--- a/openstack_auth/tests/run_tests.py
+++ b/openstack_auth/tests/run_tests.py
@@ -21,6 +21,10 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'openstack_auth.tests.settings'
 
 from django.test import simple as test_simple
 
+import django
+if hasattr(django, 'setup'):
+    django.setup()
+
 
 def run(*test_args):
     if not test_args:
-- 
2.1.0

>From c745084604baa04b904047074409a6ad63a5238e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= <[email protected]>
Date: Fri, 5 Sep 2014 17:30:20 +0200
Subject: [PATCH 2/2] Don't call check_for_test_cookie with Django 1.7

The Django doc says this for this method:

    The undocumented check_for_test_cookie method in AuthenticationForm will be
    removed following an accelerated deprecation. Users subclassing this form
    should remove calls to this method, and instead ensure that their auth related
    views are CSRF protected, which ensures that cookies are enabled.

The login view in openstack_auth/views.py is CSRF protected so it should be
fine to just drop the call with Django 1.7.
---
 openstack_auth/forms.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/openstack_auth/forms.py b/openstack_auth/forms.py
index 5e46ad8..71cb4e2 100644
--- a/openstack_auth/forms.py
+++ b/openstack_auth/forms.py
@@ -100,5 +100,6 @@ class Login(django_auth_forms.AuthenticationForm):
             LOG.warning(msg)
             self.request.session.flush()
             raise forms.ValidationError(exc)
-        self.check_for_test_cookie()
+        if hasattr(self, 'check_for_test_cookie'):  # Dropped in django 1.7
+            self.check_for_test_cookie()
         return self.cleaned_data
-- 
2.1.0

Reply via email to