~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/contrib/formtools/tests/tests.py

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2014-09-17 14:15:11 UTC
  • mfrom: (1.3.17) (6.2.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140917141511-icneokthe9ww5sk4
Tags: 1.7-2
* Release to unstable.
* Add a migrate-south sample script to help users apply their South
  migrations. Thanks to Brian May.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
import datetime
5
5
import os
 
6
import unittest
6
7
import warnings
7
8
 
8
9
from django import http
9
10
from django.contrib.formtools import preview, utils
10
 
from django.test import TestCase
11
 
from django.test.utils import override_settings
 
11
from django.test import TestCase, override_settings
12
12
from django.utils._os import upath
13
 
from django.utils import unittest
14
13
 
15
 
from django.contrib.formtools.tests.forms import *
 
14
from django.contrib.formtools.tests.forms import (
 
15
    HashTestBlankForm, HashTestForm, TestForm,
 
16
)
16
17
 
17
18
success_string = "Done was called!"
18
19
success_string_encoded = success_string.encode()
19
20
 
 
21
 
20
22
class TestFormPreview(preview.FormPreview):
21
23
    def get_context(self, request, form):
22
24
        context = super(TestFormPreview, self).get_context(request, form)
29
31
    def done(self, request, cleaned_data):
30
32
        return http.HttpResponse(success_string)
31
33
 
 
34
 
32
35
@override_settings(
33
36
    TEMPLATE_DIRS=(
34
37
        os.path.join(os.path.dirname(upath(__file__)), 'templates'),
55
58
        """
56
59
        Test contrib.formtools.preview form retrieval.
57
60
 
58
 
        Use the client library to see if we can sucessfully retrieve
 
61
        Use the client library to see if we can successfully retrieve
59
62
        the form (mostly testing the setup ROOT_URLCONF
60
63
        process). Verify that an additional  hidden input field
61
64
        is created to manage the stage.
91
94
        Use the client library to POST to the form with stage set to 3
92
95
        to see if our forms done() method is called. Check first
93
96
        without the security hash, verify failure, retry with security
94
 
        hash and verify sucess.
 
97
        hash and verify success.
95
98
 
96
99
        """
97
100
        # Pass strings for form submittal and add stage variable to
117
120
        ``bool1``. We need to make sure the hashes are the same in both cases.
118
121
 
119
122
        """
120
 
        self.test_data.update({'stage':2})
 
123
        self.test_data.update({'stage': 2})
121
124
        hash = self.preview.security_hash(None, TestForm(self.test_data))
122
125
        self.test_data.update({'hash': hash, 'bool1': 'False'})
123
126
        with warnings.catch_warnings(record=True):
131
134
        """
132
135
        # Pass strings for form submittal and add stage variable to
133
136
        # show we previously saw first stage of the form.
134
 
        self.test_data.update({'stage':2})
 
137
        self.test_data.update({'stage': 2})
135
138
        response = self.client.post('/preview/', self.test_data)
136
139
        self.assertNotEqual(response.content, success_string_encoded)
137
140
        hash = utils.form_hmac(TestForm(self.test_data))
139
142
        response = self.client.post('/preview/', self.test_data)
140
143
        self.assertEqual(response.content, success_string_encoded)
141
144
 
142
 
 
143
145
    def test_form_submit_bad_hash(self):
144
146
        """
145
147
        Test contrib.formtools.preview form submittal does not proceed
147
149
        """
148
150
        # Pass strings for form submittal and add stage variable to
149
151
        # show we previously saw first stage of the form.
150
 
        self.test_data.update({'stage':2})
 
152
        self.test_data.update({'stage': 2})
151
153
        response = self.client.post('/preview/', self.test_data)
152
154
        self.assertEqual(response.status_code, 200)
153
155
        self.assertNotEqual(response.content, success_string_encoded)