From c0381859156931ed78997951a35816a61a906e16 Mon Sep 17 00:00:00 2001 From: Tim Heap Date: Thu, 31 Mar 2016 13:23:39 +1100 Subject: [PATCH] Remove workarounds for bad request method checking Previously, the POST data could not be empty for some views, otherwise they would not work. This caused the workarounds to be necessary. The request method detection was fixed in the previous commit, so this commit removes the workarounds. --- wagtail/contrib/wagtailsearchpromotions/tests.py | 5 +---- wagtail/wagtaildocs/tests.py | 9 +++------ wagtail/wagtailimages/tests/test_admin_views.py | 4 +--- wagtail/wagtailredirects/tests.py | 8 +++----- wagtail/wagtailsnippets/tests.py | 3 +-- 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/wagtail/contrib/wagtailsearchpromotions/tests.py b/wagtail/contrib/wagtailsearchpromotions/tests.py index c5649a2a7a..451366243c 100644 --- a/wagtail/contrib/wagtailsearchpromotions/tests.py +++ b/wagtail/contrib/wagtailsearchpromotions/tests.py @@ -332,10 +332,7 @@ class TestSearchPromotionsDeleteView(TestCase, WagtailTestUtils): def test_post(self): # Submit - post_data = { - 'foo': 'bar', - } - response = self.client.post(reverse('wagtailsearchpromotions:delete', args=(self.query.id, )), post_data) + response = self.client.post(reverse('wagtailsearchpromotions:delete', args=(self.query.id, ))) # User should be redirected back to the index self.assertRedirects(response, reverse('wagtailsearchpromotions:index')) diff --git a/wagtail/wagtaildocs/tests.py b/wagtail/wagtaildocs/tests.py index 6ac1a51b3f..745bc555af 100644 --- a/wagtail/wagtaildocs/tests.py +++ b/wagtail/wagtaildocs/tests.py @@ -361,10 +361,7 @@ class TestDocumentDeleteView(TestCase, WagtailTestUtils): def test_delete(self): # Submit title change - post_data = { - 'foo': 'bar' - } - response = self.client.post(reverse('wagtaildocs:delete', args=(self.document.id,)), post_data) + response = self.client.post(reverse('wagtaildocs:delete', args=(self.document.id,))) # User should be redirected back to the index self.assertRedirects(response, reverse('wagtaildocs:index')) @@ -501,7 +498,7 @@ class TestMultipleDocumentUploader(TestCase, WagtailTestUtils): """ This tests that only AJAX requests are allowed to POST to the add view """ - response = self.client.post(reverse('wagtaildocs:add_multiple'), {}) + response = self.client.post(reverse('wagtaildocs:add_multiple')) # Check response self.assertEqual(response.status_code, 400) @@ -510,7 +507,7 @@ class TestMultipleDocumentUploader(TestCase, WagtailTestUtils): """ This tests that the add view checks for a file when a user POSTs to it """ - response = self.client.post(reverse('wagtaildocs:add_multiple'), {}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') + response = self.client.post(reverse('wagtaildocs:add_multiple'), HTTP_X_REQUESTED_WITH='XMLHttpRequest') # Check response self.assertEqual(response.status_code, 400) diff --git a/wagtail/wagtailimages/tests/test_admin_views.py b/wagtail/wagtailimages/tests/test_admin_views.py index 714597fe17..7a53857f72 100644 --- a/wagtail/wagtailimages/tests/test_admin_views.py +++ b/wagtail/wagtailimages/tests/test_admin_views.py @@ -369,9 +369,7 @@ class TestImageDeleteView(TestCase, WagtailTestUtils): self.assertTemplateUsed(response, 'wagtailimages/images/confirm_delete.html') def test_delete(self): - response = self.post({ - 'hello': 'world' - }) + response = self.post() # Should redirect back to index self.assertRedirects(response, reverse('wagtailimages:index')) diff --git a/wagtail/wagtailredirects/tests.py b/wagtail/wagtailredirects/tests.py index dd924573c9..fec07635de 100644 --- a/wagtail/wagtailredirects/tests.py +++ b/wagtail/wagtailredirects/tests.py @@ -386,10 +386,10 @@ class TestRedirectsDeleteView(TestCase, WagtailTestUtils): def get(self, params={}, redirect_id=None): return self.client.get(reverse('wagtailredirects:delete', args=(redirect_id or self.redirect.id, )), params) - def post(self, post_data={}, redirect_id=None): + def post(self, redirect_id=None): return self.client.post(reverse( 'wagtailredirects:delete', args=(redirect_id or self.redirect.id, ) - ), post_data) + )) def test_simple(self): response = self.get() @@ -400,9 +400,7 @@ class TestRedirectsDeleteView(TestCase, WagtailTestUtils): self.assertEqual(self.get(redirect_id=100000).status_code, 404) def test_delete(self): - response = self.post({ - 'hello': 'world' - }) + response = self.post() # Should redirect back to index self.assertRedirects(response, reverse('wagtailredirects:index')) diff --git a/wagtail/wagtailsnippets/tests.py b/wagtail/wagtailsnippets/tests.py index 8afa8f4a90..94b5488014 100644 --- a/wagtail/wagtailsnippets/tests.py +++ b/wagtail/wagtailsnippets/tests.py @@ -263,9 +263,8 @@ class TestSnippetDelete(TestCase, WagtailTestUtils): self.assertEqual(response.status_code, 200) def test_delete_post(self): - post_data = {'foo': 'bar'} # For some reason, this test doesn't work without a bit of POST data response = self.client.post( - reverse('wagtailsnippets:delete', args=('tests', 'advert', self.test_snippet.id, )), post_data + reverse('wagtailsnippets:delete', args=('tests', 'advert', self.test_snippet.id, )) ) # Should be redirected to explorer page