summaryrefslogtreecommitdiff
path: root/tests/admin_views/tests.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2013-05-29 10:55:56 -0400
committerTim Graham <timograham@gmail.com>2013-05-29 11:25:42 -0400
commitd727518ad61beda4d9c2b744c9c05a805aa23ed1 (patch)
treea451ad2b488bc1a466a522f5f183a8af7981c99a /tests/admin_views/tests.py
parent8010289ea2f30f0bb819feba7ec78e67c198023b (diff)
Fixed #20331 -- Allowed admin actions to serve StreamingHttpResponses
Thanks Edwin.
Diffstat (limited to 'tests/admin_views/tests.py')
-rw-r--r--tests/admin_views/tests.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 106b0a706a..8c8a65318c 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -2432,6 +2432,29 @@ class AdminActionsTest(TestCase):
response = self.client.post(url, action_data)
self.assertRedirects(response, url)
+ def test_custom_function_action_streaming_response(self):
+ """Tests a custom action that returns a StreamingHttpResponse."""
+ action_data = {
+ ACTION_CHECKBOX_NAME: [1],
+ 'action': 'download',
+ 'index': 0,
+ }
+ response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
+ content = b''.join(response.streaming_content)
+ self.assertEqual(content, b'This is the content of the file')
+ self.assertEqual(response.status_code, 200)
+
+ def test_custom_function_action_no_perm_response(self):
+ """Tests a custom action that returns an HttpResponse with 403 code."""
+ action_data = {
+ ACTION_CHECKBOX_NAME: [1],
+ 'action': 'no_perm',
+ 'index': 0,
+ }
+ response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
+ self.assertEqual(response.status_code, 403)
+ self.assertEqual(response.content, b'No permission to perform this action')
+
def test_actions_ordering(self):
"""
Ensure that actions are ordered as expected.
@@ -2440,9 +2463,13 @@ class AdminActionsTest(TestCase):
response = self.client.get('/test_admin/admin/admin_views/externalsubscriber/')
self.assertContains(response, '''<label>Action: <select name="action">
<option value="" selected="selected">---------</option>
-<option value="delete_selected">Delete selected external subscribers</option>
+<option value="delete_selected">Delete selected external
+subscribers</option>
<option value="redirect_to">Redirect to (Awesome action)</option>
-<option value="external_mail">External mail (Another awesome action)</option>
+<option value="external_mail">External mail (Another awesome
+action)</option>
+<option value="download">Download subscription</option>
+<option value="no_perm">No permission to run</option>
</select>''', html=True)
def test_model_without_action(self):