Skip to content

Commit

Permalink
Removing CSRF tests.
Browse files Browse the repository at this point in the history
After removing old CSRF forgery from django-uni-form, testing the csrf_token
within context turned into something unnecessary and really hard to do.
Django already tests csrf_token, so we drop these tests.
  • Loading branch information
maraujop committed Apr 11, 2011
1 parent cac219f commit 3ab0099
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions uni_form/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,37 +181,6 @@ def test_uni_form_formset(self):
self.assertTrue('id="this-formset-rocks">' in html)
self.assertTrue('action="%s"' % reverse('simpleAction') in html)

def test_csrf_token_POST_form(self):
form_helper = FormHelper()
template = get_template_from_string(u"""
{% load uni_form_tags %}
{% uni_form form form_helper %}
""")

# The middleware only initializes the CSRF token when processing a real request
# So using RequestContext or csrf(request) here does not work.
# Instead I set the key `csrf_token` to a CSRF token manually, which `csrf_token` tag
# reads to put a hidden input in > django.template.defaulttags.CsrfTokenNode
# This way we don't need to use Django's client, have a test_app and urls
# I like self-contained tests :) CSRF could be any number, we don't care
c = Context({'form': TestForm(), 'form_helper': form_helper, 'csrf_token': _get_new_csrf_key()})
html = template.render(c)

self.assertTrue("<input type='hidden' name='csrfmiddlewaretoken'" in html)

def test_csrf_token_GET_form(self):
form_helper = FormHelper()
form_helper.form_method = 'GET'
template = get_template_from_string(u"""
{% load uni_form_tags %}
{% uni_form form form_helper %}
""")

c = Context({'form': TestForm(), 'form_helper': form_helper, 'csrf_token': _get_new_csrf_key()})
html = template.render(c)

self.assertFalse("<input type='hidden' name='csrfmiddlewaretoken'" in html)


class TestFormLayout(TestCase):
def test_layout_invalid_unicode_characters(self):
Expand Down

0 comments on commit 3ab0099

Please sign in to comment.