Skip to content

Commit 4b514e1

Browse files
committed
add a tiny bit more test coverage
1 parent 0a27184 commit 4b514e1

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

django_object_actions/tests/tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,19 @@ def test_can_return_template(self):
5050
response = self.client.get(url)
5151
self.assertTemplateUsed(response, "clear_choices.html")
5252

53+
def test_message_user_sends_message(self):
54+
url = '/admin/polls/poll/1/tools/delete_all_choices/'
55+
self.assertNotIn('messages', self.client.cookies)
56+
self.client.get(url)
57+
self.assertIn('messages', self.client.cookies)
58+
5359
def test_intermediate_page_with_post_works(self):
5460
self.assertTrue(Choice.objects.filter(poll=1).count())
5561
url = '/admin/polls/poll/1/tools/delete_all_choices/'
5662
response = self.client.post(url)
5763
self.assertEqual(response.status_code, 302)
5864
self.assertEqual(Choice.objects.filter(poll=1).count(), 0)
65+
66+
def test_undefined_tool_404s(self):
67+
response = self.client.get('/admin/polls/choice/1/tools/weeeewoooooo/')
68+
self.assertEqual(response.status_code, 404)

django_object_actions/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,16 @@ def get(self, request, **kwargs):
116116
back = request.path.rsplit('/', 3)[0] + '/'
117117
return HttpResponseRedirect(back)
118118

119-
# Allow POST
119+
# HACK to allow POST requests too easily
120120
post = get
121121

122122
def message_user(self, request, message):
123+
"""
124+
Mimic Django admin actions's `message_user`.
125+
126+
Like the second example:
127+
https://docs.djangoproject.com/en/1.7/ref/contrib/admin/actions/#custom-admin-action
128+
"""
123129
# copied from django.contrib.admin.options
124130
# included to mimic admin actions
125131
messages.info(request, message)

example_project/polls/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def delete_all_choices(self, request, obj):
6868
obj.choice_set.all().delete()
6969
return
7070

71+
self.message_user(request, 'All choices deleted')
7172
return render_to_response('clear_choices.html',
7273
dict(object=obj), context_instance=RequestContext(request))
7374
delete_all_choices.label = "Delete All Choices"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{# DJANGO 1.4 compatibility #}

0 commit comments

Comments
 (0)