Author: ccahoon
Date: 2009-06-25 12:19:53 -0500 (Thu, 25 Jun 2009)
New Revision: 11110

Modified:
   
django/branches/soc2009/http-wsgi-improvements/tests/regressiontests/test_client_regress/models.py
   
django/branches/soc2009/http-wsgi-improvements/tests/regressiontests/test_client_regress/views.py
Log:
[soc2009/http-wsgi-improvements] Modified tests/test_client_regress to expect 
correct behavior, which also fixes conflicts with charset handling in 
HttpResponse.

The specific cases modified test if the test client will encode the data it 
posts such that when writers of test views try to use the request, the data 
will be in the encoding they expect from the tests cases they have written. We 
do not expect HttpRequest to decode the incoming content yet, so the test views 
have to be created beforehand so that they decode using the proper codec (which 
they can determine from the content-type header).

Therefore, once the data is in the view and decoded, we then encode it into 
settings.DEFAULT_CHARSET, so we can expect normal behavior from HttpResponse, 
which is for the data to be encoded in settings.DEFAULT_CHARSET. That is what 
the test cases now assert.

HttpResponse charset handling now passes the entire test suite.

Modified: 
django/branches/soc2009/http-wsgi-improvements/tests/regressiontests/test_client_regress/models.py
===================================================================
--- 
django/branches/soc2009/http-wsgi-improvements/tests/regressiontests/test_client_regress/models.py
  2009-06-25 15:42:51 UTC (rev 11109)
+++ 
django/branches/soc2009/http-wsgi-improvements/tests/regressiontests/test_client_regress/models.py
  2009-06-25 17:19:53 UTC (rev 11110)
@@ -648,7 +648,7 @@
         json = u'{"dog": "собака"}'
         response = 
self.client.post("/test_client_regress/parse_unicode_json/", json,
                                     content_type="application/json; 
charset=utf-16")
-        self.assertEqual(response.content, json.encode('utf-16'))
+        self.assertEqual(response.content, 
json.encode(settings.DEFAULT_CHARSET))
 
     def test_unicode_payload_non_utf(self):
         "A non-ASCII unicode data as a non-UTF based encoding can be POSTed"
@@ -656,4 +656,4 @@
         json = u'{"dog": "собака"}'
         response = 
self.client.post("/test_client_regress/parse_unicode_json/", json,
                                     content_type="application/json; 
charset=koi8-r")
-        self.assertEqual(response.content, json.encode('koi8-r'))
+        self.assertEqual(response.content, 
json.encode(settings.DEFAULT_CHARSET))

Modified: 
django/branches/soc2009/http-wsgi-improvements/tests/regressiontests/test_client_regress/views.py
===================================================================
--- 
django/branches/soc2009/http-wsgi-improvements/tests/regressiontests/test_client_regress/views.py
   2009-06-25 15:42:51 UTC (rev 11109)
+++ 
django/branches/soc2009/http-wsgi-improvements/tests/regressiontests/test_client_regress/views.py
   2009-06-25 17:19:53 UTC (rev 11110)
@@ -79,10 +79,11 @@
 
     # This just checks that the uploaded data is JSON
     obj_dict = simplejson.loads(request.raw_post_data.decode(charset))
-    obj_json = simplejson.dumps(obj_dict, encoding=charset,
+    obj_json = simplejson.dumps(obj_dict, encoding=settings.DEFAULT_CHARSET,
                                 cls=DjangoJSONEncoder,
                                 ensure_ascii=False)
-    response = HttpResponse(smart_str(obj_json, encoding=charset), status=200,
-                            mimetype='application/json; charset=' + charset)
+
+    response = HttpResponse(smart_str(obj_json), status=200,
+                            mimetype='application/json')
     response['Content-Disposition'] = 'attachment; filename=testfile.json'
     return response


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to