Skip to content

Commit 5ec00b9

Browse files
authored
Merge pull request #42 from IMIO/SE-114/tests
Added tests for dmsoutgoingmail_modified subcriber
2 parents b547f5f + 2359f51 commit 5ec00b9

File tree

2 files changed

+96
-11
lines changed

2 files changed

+96
-11
lines changed

imio/dms/mail/subscribers.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,12 @@ def dmsoutgoingmail_modified(mail, event):
514514
else:
515515
person = uuidToObject(approving, unrestricted=True)
516516
userid = person.userid
517-
# TODO: is this check required ?
518517
if userid in approval["users"] and approval["users"][userid]["order"] != i:
519518
raise Invalid(_("The ${userid} already exists in the approvings with another order ${o} <=> ${c}",
520519
mapping={"userid": userid, "o": approval["users"][userid]["order"],
521520
"c": i}))
522521
approval["users"][userid] = PersistentMapping({"status": "w", "order": i, "name": person.get_title(),
523522
"editor": signer["editor"]})
524-
# TODO: is this check required ?
525-
if numbers["status"] != "w":
526-
raise Invalid(_("You cannot have an approving number ${c} with status ${status} <=> w",
527-
mapping={"status": numbers["status"], "c": i}))
528523
if userid not in numbers["users"]:
529524
numbers["users"].append(userid)
530525
# files

imio/dms/mail/tests/test_subscribers.py

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
from datetime import datetime
99
from imio.dms.mail import _tr
1010
from imio.dms.mail import CREATING_GROUP_SUFFIX
11+
from imio.dms.mail import PRODUCT_DIR
1112
from imio.dms.mail.testing import DMSMAIL_INTEGRATION_TESTING
1213
from imio.dms.mail.utils import sub_create
1314
from imio.dms.mail.vocabularies import AssignedUsersWithDeactivatedVocabulary
15+
from imio.dms.mail.wfadaptations import OMToApproveAdaptation
1416
from imio.helpers import EMPTY_STRING
1517
from imio.helpers import EMPTY_TITLE
1618
from imio.helpers.content import get_object
@@ -21,6 +23,7 @@
2123
from plone.app.testing import TEST_USER_ID
2224
from plone.app.users.browser.personalpreferences import UserDataConfiglet
2325
from plone.dexterity.utils import createContentInContainer
26+
from plone.namedfile.file import NamedBlobFile
2427
from Products.statusmessages.interfaces import IStatusMessage
2528
from z3c.relationfield import RelationValue
2629
from zExceptions import Redirect
@@ -58,6 +61,7 @@ def setUp(self):
5861
)
5962
self.omf = self.portal["outgoing-mail"]
6063
self.pgof = self.portal["contacts"]["plonegroup-organization"]
64+
self.pf = self.portal["contacts"]["personnel-folder"]
6165

6266
def test_item_copied(self):
6367
# check if protection markers are removed from copied item
@@ -164,9 +168,9 @@ def test_dmsincomingmail_transition(self):
164168
self.assertEqual(self.imail.assigned_user, "agent")
165169

166170
def test_dmsoutgoingmail_modified(self):
167-
dirg = self.portal["contacts"]["personnel-folder"]["dirg"]
171+
dirg = self.pf["dirg"]
168172
dirg_hp = dirg["directeur-general"]
169-
bourgmestre = self.portal["contacts"]["personnel-folder"]["bourgmestre"]
173+
bourgmestre = self.pf["bourgmestre"]
170174
bourgmestre_hp = bourgmestre["bourgmestre"]
171175
rk = "imio.dms.mail.browser.settings.IImioDmsMailConfig.omail_signer_rules"
172176
omail = sub_create(
@@ -791,14 +795,100 @@ def test_dmsoutgoingmail_modified(self):
791795
],
792796
)
793797

794-
# Test mail in send or to_be_signed states
798+
# Test duplicate approvings userids
799+
chef = self.pf["chef"]
800+
omail.signers = None
801+
api.portal.set_registry_record(
802+
rk,
803+
[
804+
{
805+
"valid_until": None,
806+
"valid_from": None,
807+
"tal_condition": None,
808+
"mail_types": [],
809+
"approvings": [chef.UID()],
810+
"esign": True,
811+
"number": 1,
812+
"treating_groups": [],
813+
"send_modes": [],
814+
"signer": dirg_hp.UID(),
815+
"editor": True,
816+
},
817+
{
818+
"valid_until": None,
819+
"valid_from": None,
820+
"tal_condition": None,
821+
"mail_types": [],
822+
"approvings": [chef.UID()],
823+
"esign": True,
824+
"number": 2,
825+
"treating_groups": [],
826+
"send_modes": [],
827+
"signer": bourgmestre_hp.UID(),
828+
"editor": False,
829+
},
830+
],
831+
)
832+
with self.assertRaises(Invalid) as cm:
833+
modified(omail)
834+
self.assertEqual(
835+
cm.exception.message, u"The ${userid} already exists in the approvings with another order ${o} <=> ${c}"
836+
)
837+
838+
# Test signers have same email
839+
api.user.get("bourgmestre").setMemberProperties({"email": "[email protected]"})
840+
api.user.get("dirg").setMemberProperties({"email": "[email protected]"})
841+
omail.signers = None
842+
api.portal.set_registry_record(
843+
rk,
844+
[
845+
{
846+
"valid_until": None,
847+
"valid_from": None,
848+
"tal_condition": None,
849+
"mail_types": [],
850+
"approvings": [u"_empty_"],
851+
"esign": True,
852+
"number": 1,
853+
"treating_groups": [],
854+
"send_modes": [],
855+
"signer": dirg_hp.UID(),
856+
"editor": True,
857+
},
858+
{
859+
"valid_until": None,
860+
"valid_from": None,
861+
"tal_condition": None,
862+
"mail_types": [],
863+
"approvings": [u"_empty_"],
864+
"esign": True,
865+
"number": 2,
866+
"treating_groups": [],
867+
"send_modes": [],
868+
"signer": bourgmestre_hp.UID(),
869+
"editor": False,
870+
},
871+
],
872+
)
873+
with self.assertRaises(Invalid) as cm:
874+
modified(omail)
875+
self.assertEqual(cm.exception.message, u"You cannot have the same email (${email}) for multiple signers !")
876+
api.user.get("dirg").setMemberProperties({"email": "[email protected]"})
877+
878+
# Test mail in sent or to_be_signed states
879+
filepath = "%s/batchimport/toprocess/outgoing-mail/Réponse salle.odt" % PRODUCT_DIR
880+
with open(filepath, "rb") as fo:
881+
file_object = NamedBlobFile(fo.read(), filename=u"example.odt")
882+
createContentInContainer(omail, "dmsommainfile", id="1", title="Example", file=file_object)
883+
api.content.transition(omail, to_state="to_be_signed")
884+
omail.signers = None
885+
modified(omail)
886+
self.assertIsNone(omail.signers)
887+
795888
api.content.transition(omail, to_state="sent")
796889
omail.signers = None
797890
modified(omail)
798891
self.assertIsNone(omail.signers)
799-
# TODO add tests for 2 other raises
800-
# The ${userid} already exists ...
801-
# You cannot have an approving number
802892

803893
def test_task_transition(self):
804894
# task = createContentInContainer(self.imail, 'task', id='t1')

0 commit comments

Comments
 (0)