From b05cfff29ca11814e99bbcbb5b50d99c4423f911 Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Thu, 3 Feb 2022 15:52:17 +0100
Subject: [PATCH] testing is_editor_or_owner_of_ds

---
 .../viralhostrangedb/tests/test_templatetags.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/viralhostrange/viralhostrangedb/tests/test_templatetags.py b/src/viralhostrange/viralhostrangedb/tests/test_templatetags.py
index e0fc3b69..72359424 100644
--- a/src/viralhostrange/viralhostrangedb/tests/test_templatetags.py
+++ b/src/viralhostrange/viralhostrangedb/tests/test_templatetags.py
@@ -4,7 +4,7 @@ from django.test import TestCase, override_settings
 from django.utils import timezone
 
 from viralhostrangedb import models, business_process
-from viralhostrangedb.templatetags.viralhostrange_tags import can_edit, can_see, can_delete
+from viralhostrangedb.templatetags.viralhostrange_tags import can_edit, can_see, can_delete, is_editor_or_owner_of_ds
 
 
 class TemplateTagsTests(TestCase):
@@ -84,6 +84,21 @@ class TemplateTagsTests(TestCase):
         business_process.set_curator(self.user, True)
         self.assertTrue(can_edit(self.user, self.d_toto))
 
+    @override_settings(DEBUG=False)
+    def test_is_editor_or_owner_of_ds(self):
+        self.assertFalse(is_editor_or_owner_of_ds(self.user, self.d_toto))
+        self.assertTrue(is_editor_or_owner_of_ds(self.toto, self.d_toto))
+
+        self.assertTrue(is_editor_or_owner_of_ds(self.titi, self.d_toto_grant_titi))
+        business_process.set_curator(self.titi, True)
+        self.assertTrue(is_editor_or_owner_of_ds(self.titi, self.d_toto_grant_titi), "should still be allowed")
+
+        self.assertFalse(is_editor_or_owner_of_ds(self.user, self.d_toto_grant_titi))
+        self.assertFalse(is_editor_or_owner_of_ds(self.user, self.d_toto_grant_titi.pk))
+        business_process.set_curator(self.user, True)
+        self.assertFalse(is_editor_or_owner_of_ds(self.user, self.d_toto_grant_titi), "still not allowed")
+        self.assertFalse(is_editor_or_owner_of_ds(self.user, self.d_toto_grant_titi.pk), "still not allowed")
+
     @override_settings(DEBUG=False)
     def test_can_delete(self):
         self.assertFalse(can_delete(self.user, self.d_toto))
-- 
GitLab