Skip to content

Commit

Permalink
Ajoute des tests pour les images SVG
Browse files Browse the repository at this point in the history
  • Loading branch information
Situphen committed Nov 16, 2021
1 parent c90d57e commit 676deaf
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions zds/gallery/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def test_fail_member_no_permission_can_edit_image(self):
self.assertNotEqual("modify with no perms", image_test.title)
image_test.delete()

def test_success_member_edit_image(self):
def test_success_member_edit_png_image(self):
self.client.force_login(self.profile1.user)

nb_files = len(os.listdir(self.gallery.get_gallery_path()))
Expand All @@ -543,6 +543,27 @@ def test_success_member_edit_image(self):
# picture AND thumbnail should be gone
self.assertEqual(nb_files, len(os.listdir(self.gallery.get_gallery_path())))

def test_success_member_edit_svg_image(self):
self.client.force_login(self.profile1.user)

nb_files = len(os.listdir(self.gallery.get_gallery_path()))

with (settings.BASE_DIR / "assets" / "licenses" / "copyright.svg").open("rb") as fp:

response = self.client.post(
reverse("gallery-image-edit", args=[self.gallery.pk, self.image.pk]),
{"title": "edit title", "legend": "dit legend", "slug": "edit-slug", "physical": fp},
follow=True,
)
self.assertEqual(200, response.status_code)
self.assertEqual(nb_files + 3, len(os.listdir(self.gallery.get_gallery_path())))

image_test = Image.objects.get(pk=self.image.pk)
self.assertEqual("edit title", image_test.title)
image_test.delete()
# picture AND thumbnail should be gone
self.assertEqual(nb_files, len(os.listdir(self.gallery.get_gallery_path())))

def test_access_permission(self):
self.client.force_login(self.profile1.user)

Expand Down Expand Up @@ -648,7 +669,7 @@ def setUp(self):
self.user_gallery1 = UserGalleryFactory(user=self.profile1.user, gallery=self.gallery, mode="W")
self.user_gallery2 = UserGalleryFactory(user=self.profile2.user, gallery=self.gallery, mode="R")

def test_success_new_image_write_permission(self):
def test_success_new_png_image_write_permission(self):
self.client.force_login(self.profile1.user)
self.assertEqual(0, len(self.gallery.get_images()))

Expand All @@ -664,6 +685,22 @@ def test_success_new_image_write_permission(self):
self.assertEqual(3, len(os.listdir(self.gallery.get_gallery_path()))) # New image and thumbnail
self.gallery.get_images()[0].delete()

def test_success_new_svg_image_write_permission(self):
self.client.force_login(self.profile1.user)
self.assertEqual(0, len(self.gallery.get_images()))

with (settings.BASE_DIR / "assets" / "licenses" / "copyright.png").open("rb") as fp:
response = self.client.post(
reverse("gallery-image-new", args=[self.gallery.pk]),
{"title": "Test title", "legend": "Test legend", "slug": "test-slug", "physical": fp},
follow=True,
)

self.assertEqual(200, response.status_code)
self.assertEqual(1, len(self.gallery.get_images()))
self.assertEqual(3, len(os.listdir(self.gallery.get_gallery_path()))) # New image and thumbnail
self.gallery.get_images()[0].delete()

def test_fail_new_image_with_read_permission(self):
self.client.force_login(self.profile2.user)
self.assertEqual(0, len(self.gallery.get_images()))
Expand Down

0 comments on commit 676deaf

Please sign in to comment.