Jeroen Vloothuis committed 22c4001

Fixed handling of forms with method="get"

Comments (0)

Files changed (5)


         return response
     def get(self, url, params=None, headers=None, extra_environ=None,
-            status=None, expect_errors=False, user=None, auto_follow=False):
+            status=None, expect_errors=False, user=None, auto_follow=False,
+            content_type=None):
         extra_environ = self._update_environ(extra_environ, user)
         response = super(DjangoTestApp, self).get(
                   url, params, headers, extra_environ, status, expect_errors)


+<!DOCTYPE html>
+    <form action='' method='get'>
+        {{ form.as_p }}
+        <input type='submit'>
+        You searched for:
+        {{ q }}
+    </form>


         page_with_errors.form.submit().follow() # check for 302 response
+class GetFormSubmitTest(WebTest):
+    def test_form_submit(self):
+        page ='search'))
+        page.form['q'] = 'bar'
+        response = page.form.submit()
+        self.assertEqual(response.context['q'], 'bar')
 class TemplateContextTest(WebTest):
     def test_rendered_templates(self):
         response ='/template/index.html')


         return HttpResponseRedirect('/')
     return direct_to_template(request, 'form.html', {'form': form})
+class SearchForm(forms.Form):
+    q = forms.CharField(required=False)
+def search(request):
+    form = SearchForm(request.GET)
+    q = None
+    if form.is_valid():
+        q = form.cleaned_data['q']
+    return direct_to_template(request, 'get_form.html', 
+                              {'form': form, 'q': q})
 def set_session(request):
     request.session['test'] = 'foo'
-    return HttpResponseRedirect('/')
+    return HttpResponseRedirect('/')


     url(r'^$', simple_method_test, name='simple-method-test'),
     url(r'^template/(.*)$', simple_template_render, name='simple-template-test'),
     url(r'^check-password/$', 'testapp_tests.views.check_password', name='check_password'),
+    url(r'^search/$', '', name='search'),
     url(r'^login/$', 'django.contrib.auth.views.login', name='auth_login'),
     url(r'^set-session/$', 'testapp_tests.views.set_session', name='set_session')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.