Skip to content

Commit

Permalink
add test for a tool with an intermediate/POST
Browse files Browse the repository at this point in the history
  • Loading branch information
crccheck committed Feb 24, 2013
1 parent 13431b0 commit 41ca626
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions example_project/polls/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class PollAdmin(DjangoObjectActions, admin.ModelAdmin):
def delete_all_choices(self, request, obj):
from django.shortcuts import render_to_response
from django.template import RequestContext

if request.method == 'POST':
obj.choice_set.all().delete()
return

return render_to_response('clear_choices.html',
dict(object=obj), context_instance=RequestContext(request))
delete_all_choices.label = "Delete All Choices"
Expand Down
4 changes: 3 additions & 1 deletion example_project/test_app/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def test_tool_can_return_httpresponse(self):
self.assertTrue(response['location'].endswith('/admin/polls/poll/1/'))

def test_intermediate_page_with_post_works(self):
self.assertTrue(Choice.objects.filter(poll=1).count())
url = '/admin/polls/poll/1/tools/delete_all_choices/'
response = self.client.post(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 302)
self.assertEqual(Choice.objects.filter(poll=1).count(), 0)

0 comments on commit 41ca626

Please sign in to comment.