Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seb-b committed Aug 13, 2024
1 parent c8c4c53 commit f2b574f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 54 deletions.
54 changes: 2 additions & 52 deletions tests/test_admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,28 +567,6 @@ def test_add_post(self):
self.assertEqual(response_json["video_id"], response.context["video"].id)
self.assertTrue(response_json["success"])

def test_add_post_noajax(self):
"""
This tests that only AJAX requests are allowed to POST to the add view
"""
response = self.client.post(reverse("wagtailvideos:add_multiple"), {})

# Check response
self.assertEqual(response.status_code, 400)

def test_add_post_nofile(self):
"""
This tests that the add view checks for a file when a user POSTs to it
"""
response = self.client.post(
reverse("wagtailvideos:add_multiple"),
{},
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
)

# Check response
self.assertEqual(response.status_code, 400)

def test_add_post_badfile(self):
"""
This tests that the add view checks for a file when a user POSTs to it
Expand Down Expand Up @@ -637,7 +615,6 @@ def test_edit_post(self):
("video-%d-title" % self.video.id): "New title!",
("video-%d-tags" % self.video.id): "",
},
HTTP_X_REQUESTED_WITH="XMLHttpRequest",
)

# Check response
Expand All @@ -651,22 +628,7 @@ def test_edit_post(self):
self.assertIn("success", response_json)
self.assertEqual(response_json["video_id"], self.video.id)
self.assertTrue(response_json["success"])

def test_edit_post_noajax(self):
"""
This tests that a POST request to the edit view without AJAX returns a 400 response
"""
# Send request
response = self.client.post(
reverse("wagtailvideos:edit_multiple", args=(self.video.id,)),
{
("video-%d-title" % self.video.id): "New title!",
("video-%d-tags" % self.video.id): "",
},
)

# Check response
self.assertEqual(response.status_code, 400)
self.assertEqual(Video.objects.get(id=self.video.id).title, "New title!")

def test_edit_post_validation_error(self):
"""
Expand All @@ -686,7 +648,7 @@ def test_edit_post_validation_error(self):
# Check response
self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Type"], "application/json")
self.assertTemplateUsed(response, "wagtailvideos/multiple/edit_form.html")
self.assertTemplateUsed(response, "wagtailadmin/generic/multiple_upload/edit_form.html")

# Check that a form error was raised
self.assertFormError(
Expand Down Expand Up @@ -736,15 +698,3 @@ def test_delete_post(self):
self.assertIn("success", response_json)
self.assertEqual(response_json["video_id"], self.video.id)
self.assertTrue(response_json["success"])

def test_delete_post_noajax(self):
"""
This tests that a POST request to the delete view without AJAX returns a 400 response
"""
# Send request
response = self.client.post(
reverse("wagtailvideos:delete_multiple", args=(self.video.id,))
)

# Check response
self.assertEqual(response.status_code, 400)
4 changes: 2 additions & 2 deletions wagtailvideos/views/multiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def get_edit_form_class(self):

class DeleteView(BaseDeleteView):
permission_policy = permission_policy
pk_url_kwarg = "image_id"
context_object_id_name = "image_id"
pk_url_kwarg = "video_id"
context_object_id_name = "video_id"

def get_model(self):
return get_video_model()
Expand Down

0 comments on commit f2b574f

Please sign in to comment.