Skip to content

Commit

Permalink
Supprime le fichier .svgz généré pendant un test (#6463)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippemilink authored May 14, 2023
1 parent 21413cc commit 1fe24f2
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions zds/gallery/api/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from uuid import uuid4

from django.core.cache import caches
Expand Down Expand Up @@ -281,21 +282,24 @@ def test_post_add_image(self):
def test_post_fail_add_image_not_an_image(self):
title = "un super titre pour une image"
legend = "une super legende aussi"
file_id = str(uuid4())
filename = str(uuid4()) + ".svgz"
# generate a bare empty file so that the test continues and sends error message
with open(file_id + ".svgz", "w"):
with open(filename, "w"):
pass
response = self.client.post(
reverse("api:gallery:list-images", kwargs={"pk_gallery": self.gallery.pk}),
{
"title": title,
"legend": legend,
"physical": open(file_id + ".svgz", "rb"),
},
format="multipart",
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Image.objects.filter(gallery=self.gallery).count(), 1)
try:
response = self.client.post(
reverse("api:gallery:list-images", kwargs={"pk_gallery": self.gallery.pk}),
{
"title": title,
"legend": legend,
"physical": open(filename, "rb"),
},
format="multipart",
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(Image.objects.filter(gallery=self.gallery).count(), 1)
finally:
os.remove(filename)

def test_post_can_add_image_svg_image(self):
title = "un super titre pour une image svg"
Expand Down

0 comments on commit 1fe24f2

Please sign in to comment.