Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[soc2009/http-wsgi-improvements] Adds http.HttpResponseStreaming, wit…
…h docs, tests, and support in four built-in middleware classes. Refs #7581. git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/http-wsgi-improvements@11449 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
Showing
14 changed files
with
183 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import urllib, os | ||
|
||
from django.test import TestCase | ||
from django.conf import settings | ||
from django.core.files import temp as tempfile | ||
|
||
def x(): | ||
for i in range(0, 10): | ||
yield unicode(i) + u'\n' | ||
|
||
class ResponseStreamingTests(TestCase): | ||
def test_streaming(self): | ||
response = self.client.get('/streaming/stream_file/') | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response['Content-Disposition'], | ||
'attachment; filename=test.csv') | ||
self.assertEqual(response['Content-Type'], 'text/csv') | ||
self.assertTrue(not response._is_string) | ||
self.assertEqual("".join(iter(response)), "".join(x())) | ||
self.assertTrue(not response._is_string) | ||
|
||
def test_bad_streaming(self): | ||
response = self.client.get('/streaming/stream_file/') | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response['Content-Disposition'], | ||
'attachment; filename=test.csv') | ||
self.assertEqual(response['Content-Type'], 'text/csv') | ||
self.assertTrue(not response._is_string) | ||
self.assertEqual(response.content, "".join(x())) | ||
self.assertTrue(response._is_string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.conf.urls.defaults import patterns | ||
|
||
import views | ||
|
||
urlpatterns = patterns('', | ||
(r'^stream_file/$', views.test_streaming), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import urllib | ||
|
||
from django.http import HttpResponseStreaming | ||
from time import sleep | ||
|
||
def x(): | ||
for i in range(0, 10): | ||
yield unicode(i) + u'\n' | ||
|
||
def test_streaming(request): | ||
response = HttpResponseStreaming(content=x(), mimetype='text/csv') | ||
response['Content-Disposition'] = 'attachment; filename=test.csv' | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters