|
8 | 8 | from datetime import datetime |
9 | 9 | from imio.dms.mail import _tr |
10 | 10 | from imio.dms.mail import CREATING_GROUP_SUFFIX |
| 11 | +from imio.dms.mail import PRODUCT_DIR |
11 | 12 | from imio.dms.mail.testing import DMSMAIL_INTEGRATION_TESTING |
12 | 13 | from imio.dms.mail.utils import sub_create |
13 | 14 | from imio.dms.mail.vocabularies import AssignedUsersWithDeactivatedVocabulary |
| 15 | +from imio.dms.mail.wfadaptations import OMToApproveAdaptation |
14 | 16 | from imio.helpers import EMPTY_STRING |
15 | 17 | from imio.helpers import EMPTY_TITLE |
16 | 18 | from imio.helpers.content import get_object |
|
21 | 23 | from plone.app.testing import TEST_USER_ID |
22 | 24 | from plone.app.users.browser.personalpreferences import UserDataConfiglet |
23 | 25 | from plone.dexterity.utils import createContentInContainer |
| 26 | +from plone.namedfile.file import NamedBlobFile |
24 | 27 | from Products.statusmessages.interfaces import IStatusMessage |
25 | 28 | from z3c.relationfield import RelationValue |
26 | 29 | from zExceptions import Redirect |
@@ -58,6 +61,7 @@ def setUp(self): |
58 | 61 | ) |
59 | 62 | self.omf = self.portal["outgoing-mail"] |
60 | 63 | self.pgof = self.portal["contacts"]["plonegroup-organization"] |
| 64 | + self.pf = self.portal["contacts"]["personnel-folder"] |
61 | 65 |
|
62 | 66 | def test_item_copied(self): |
63 | 67 | # check if protection markers are removed from copied item |
@@ -164,9 +168,9 @@ def test_dmsincomingmail_transition(self): |
164 | 168 | self.assertEqual(self.imail.assigned_user, "agent") |
165 | 169 |
|
166 | 170 | def test_dmsoutgoingmail_modified(self): |
167 | | - dirg = self.portal["contacts"]["personnel-folder"]["dirg"] |
| 171 | + dirg = self.pf["dirg"] |
168 | 172 | dirg_hp = dirg["directeur-general"] |
169 | | - bourgmestre = self.portal["contacts"]["personnel-folder"]["bourgmestre"] |
| 173 | + bourgmestre = self.pf["bourgmestre"] |
170 | 174 | bourgmestre_hp = bourgmestre["bourgmestre"] |
171 | 175 | rk = "imio.dms.mail.browser.settings.IImioDmsMailConfig.omail_signer_rules" |
172 | 176 | omail = sub_create( |
@@ -791,14 +795,100 @@ def test_dmsoutgoingmail_modified(self): |
791 | 795 | ], |
792 | 796 | ) |
793 | 797 |
|
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 | + |
795 | 888 | api.content.transition(omail, to_state="sent") |
796 | 889 | omail.signers = None |
797 | 890 | modified(omail) |
798 | 891 | self.assertIsNone(omail.signers) |
799 | | - # TODO add tests for 2 other raises |
800 | | - # The ${userid} already exists ... |
801 | | - # You cannot have an approving number |
802 | 892 |
|
803 | 893 | def test_task_transition(self): |
804 | 894 | # task = createContentInContainer(self.imail, 'task', id='t1') |
|
0 commit comments