Commits

Tim Savage  committed 53267e1

FileResponse had a missing include, fixed bug and added tests to prevent in future.

  • Participants
  • Parent commits 7463f2f

Comments (0)

Files changed (5)

File django_extras/http/__init__.py

 import os.path
-
+from email.utils import formatdate as format_http_date
 from django.core.serializers import json
 from django.utils import simplejson
 from django.http import *

File django_extras/tests/__init__.py

 from django_extras.tests.core.types import *
 from django_extras.tests.core.validators import *
 from django_extras.tests.forms.fields import *
+from django_extras.tests.http.responses import *

File django_extras/tests/http/__init__.py

Empty file added.

File django_extras/tests/http/data/example.txt

+This is a test file
+
+for use in responses.

File django_extras/tests/http/responses.py

+import os.path
+import datetime
+from django import test
+from django_extras.http import FileResponse, JsonResponse
+
+
+class FileResponseTestCase(test.TestCase):
+    def test_with_file_handle(self):
+        path = os.path.dirname(__file__)
+        f = file(os.path.join(path, 'data/example.txt'))
+        target = FileResponse(f, 'test/plain')
+
+        self.assertEqual(target['Content-Type'], 'test/plain')
+
+
+class JsonResponseTestCase(test.TestCase):
+    def test_simple_dictionary(self):
+        target = JsonResponse({
+            'foo': 'bar',
+            'eek': 123
+        })
+
+        actual = ''.join(target)
+        self.assertEqual(actual, '{"foo": "bar", "eek": 123}')
+        self.assertEqual(target['Content-Type'], 'application/json')
+
+    def test_with_dates(self):
+        target = JsonResponse({
+            'foo': 'bar',
+            'eek': datetime.datetime(2012, 6, 25, 11, 9, 48)
+        })
+
+        actual = ''.join(target)
+        self.assertEqual(actual, '{"foo": "bar", "eek": "2012-06-25 11:09:48"}')
+        self.assertEqual(target['Content-Type'], 'application/json')