Permalink
Browse files

Getting CSRF done

  • Loading branch information...
1 parent d1f0c9e commit 06f5b7d2a70833df49203b3cca282711286e4369 @pydanny pydanny committed Apr 17, 2010
Showing with 9 additions and 17 deletions.
  1. +3 −0 test_project/settings.py
  2. +6 −17 uni_form/tests/tests.py
View
@@ -74,9 +74,12 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
+# TODO: remove when pre-CSRF token templatetags are no longer supported
django_version = get_version()
+OLD_DJANGO = True
if django_version.startswith('1.1.2') or django_version.startswith('1.2'):
MIDDLEWARE_CLASSES += ('django.middleware.csrf.CsrfViewMiddleware',)
+ OLD_DJANGO = False
ROOT_URLCONF = 'test_project.urls'
View
@@ -1,4 +1,5 @@
from django import forms
+from django.conf import settings
from django.template import Context, Template
from django.template.loader import get_template_from_string
from django.test import TestCase
@@ -128,21 +129,9 @@ def test_uni_form_helper_form_attributes(self):
self.assertFalse("""method="get" """ in html)
self.assertFalse("""id="this-form-rocks">""" in html)
- """
+
def test_csrf_token(self):
-
- template = get_template_from_string("""
- {% load uni_form_tags %}
- {% uni_form form form_helper %}
- """)
-
- # First we build a standard form helper
- form_helper = FormHelper()
-
- # Now we set the CSRF token to bew true
- form_helper.use_csrf_protection = True
-
- # Render the text
- c = Context({'form':TestForm(),'form_helper':form_helper})
- html = template.render(c)
- """
+ is_old_django = getattr(settings, 'OLD_DJANGO', False) # TODO: remove when pre-CSRF token templatetags are no longer supported
+ if not is_old_django: # TODO: remove when pre-CSRF token templatetags are no longer supported
+ response = self.client.get('/more/csrf_token_test/')
+ self.assertContains(response, "<input type='hidden' name='csrfmiddlewaretoken'")

0 comments on commit 06f5b7d

Please sign in to comment.