1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #3160 -- Added the ability to control the content type in a test client POST request. This is to allow easier testing of json-rpc/xml-rpc/soap etc interfaces. Thanks to Mikeal Rogers for the suggestion, and Ben <afternoon@uk2.net> for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4529 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2007-02-17 00:23:09 +00:00
parent 4a85a75fb0
commit d6d51c9546
5 changed files with 60 additions and 21 deletions

View File

@@ -43,7 +43,7 @@ class ClientTest(unittest.TestCase):
# Check some response details
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template.name, 'Empty POST Template')
self.assertEqual(response.template.name, 'Empty GET Template')
def test_empty_post(self):
"POST an empty dictionary to a view"
@@ -53,7 +53,7 @@ class ClientTest(unittest.TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template.name, 'Empty POST Template')
def test_post_view(self):
def test_post(self):
"POST some data to a view"
post_data = {
'value': 37
@@ -66,6 +66,14 @@ class ClientTest(unittest.TestCase):
self.assertEqual(response.template.name, 'POST Template')
self.failUnless('Data received' in response.content)
def test_raw_post(self):
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")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template.name, "Book template")
self.assertEqual(response.content, "Blink - Malcolm Gladwell")
def test_redirect(self):
"GET a URL that redirects elsewhere"
response = self.client.get('/test_client/redirect_view/')