mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Added configurable arguments to assertRedirects and assertContains to allow for other response status codes. Thanks for the suggestion, Jiri Barton.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5179 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -35,7 +35,7 @@ class ClientTest(TestCase):
|
||||
self.assertEqual(response.template.name, 'GET Template')
|
||||
|
||||
def test_no_template_view(self):
|
||||
"Check that template usage assersions work then templates aren't in use"
|
||||
"Template usage assertions work then templates aren't in use"
|
||||
response = self.client.get('/test_client/no_template_view/')
|
||||
|
||||
# Check that the no template case doesn't mess with the template assertions
|
||||
@@ -75,6 +75,7 @@ class ClientTest(TestCase):
|
||||
self.failUnless('Data received' in response.content)
|
||||
|
||||
def test_raw_post(self):
|
||||
"POST raw data (with a content type) to a view"
|
||||
test_doc = """<?xml version="1.0" encoding="utf-8"?><library><book><title>Blink</title><author>Malcolm Gladwell</author></book></library>"""
|
||||
response = self.client.post("/test_client/raw_post_view/", test_doc,
|
||||
content_type="text/xml")
|
||||
@@ -89,6 +90,28 @@ class ClientTest(TestCase):
|
||||
# Check that the response was a 302 (redirect)
|
||||
self.assertRedirects(response, '/test_client/get_view/')
|
||||
|
||||
def test_permanent_redirect(self):
|
||||
"GET a URL that redirects permanently elsewhere"
|
||||
response = self.client.get('/test_client/permanent_redirect_view/')
|
||||
|
||||
# Check that the response was a 301 (permanent redirect)
|
||||
self.assertRedirects(response, '/test_client/get_view/', status_code=301)
|
||||
|
||||
def test_redirect_to_strange_location(self):
|
||||
"GET a URL that redirects to a non-200 page"
|
||||
response = self.client.get('/test_client/double_redirect_view/')
|
||||
|
||||
# Check that the response was a 302, and that
|
||||
# the attempt to get the redirection location returned 301 when retrieved
|
||||
self.assertRedirects(response, '/test_client/permanent_redirect_view/', target_status_code=301)
|
||||
|
||||
def test_notfound_response(self):
|
||||
"GET a URL that responds as '404:Not Found'"
|
||||
response = self.client.get('/test_client/bad_view/')
|
||||
|
||||
# Check that the response was a 404, and that the content contains MAGIC
|
||||
self.assertContains(response, 'MAGIC', status_code=404)
|
||||
|
||||
def test_valid_form(self):
|
||||
"POST valid data to a form"
|
||||
post_data = {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django.conf.urls.defaults import *
|
||||
from django.views.generic.simple import redirect_to
|
||||
import views
|
||||
|
||||
urlpatterns = patterns('',
|
||||
@@ -7,6 +8,9 @@ urlpatterns = patterns('',
|
||||
(r'^post_view/$', views.post_view),
|
||||
(r'^raw_post_view/$', views.raw_post_view),
|
||||
(r'^redirect_view/$', views.redirect_view),
|
||||
(r'^permanent_redirect_view/$', redirect_to, { 'url': '/test_client/get_view/' }),
|
||||
(r'^double_redirect_view/$', views.double_redirect_view),
|
||||
(r'^bad_view/$', views.bad_view),
|
||||
(r'^form_view/$', views.form_view),
|
||||
(r'^form_view_with_template/$', views.form_view_with_template),
|
||||
(r'^login_protected_view/$', views.login_protected_view),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from xml.dom.minidom import parseString
|
||||
from django.core.mail import EmailMessage, SMTPConnection
|
||||
from django.template import Context, Template
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.newforms.forms import Form
|
||||
from django.newforms import fields
|
||||
@@ -54,6 +54,14 @@ def redirect_view(request):
|
||||
"A view that redirects all requests to the GET view"
|
||||
return HttpResponseRedirect('/test_client/get_view/')
|
||||
|
||||
def double_redirect_view(request):
|
||||
"A view that redirects all requests to a redirection view"
|
||||
return HttpResponseRedirect('/test_client/permanent_redirect_view/')
|
||||
|
||||
def bad_view(request):
|
||||
"A view that returns a 404 with some error content"
|
||||
return HttpResponseNotFound('Not found!. This page contains some MAGIC content')
|
||||
|
||||
TestChoices = (
|
||||
('a', 'First Choice'),
|
||||
('b', 'Second Choice'),
|
||||
|
||||
Reference in New Issue
Block a user