11# -*- coding: utf-8 -*-
22"""Test views."""
33
4- from AccessControl import Unauthorized
54from collective .dms .mailcontent .dmsmail import internalReferenceOutgoingMailDefaultValue
65from collective .iconifiedcategory .utils import calculate_category_id
76from collective .MockMailHost .MockMailHost import MockMailHost
87from datetime import datetime
98from HTMLParser import HTMLParser
109from imio .dms .mail import PERIODS
1110from imio .dms .mail import PRODUCT_DIR
11+ from imio .dms .mail .browser .views import OMSessionAnnotationInfoView
1212from imio .dms .mail .browser .views import parse_query
13- from imio .dms .mail .browser .views import SigningAnnotationInfoView
1413from imio .dms .mail .interfaces import IOMApproval
1514from imio .dms .mail .testing import change_user
1615from imio .dms .mail .testing import DMSMAIL_INTEGRATION_TESTING
2625from plone .app .testing import login
2726from plone .dexterity .utils import createContentInContainer
2827from plone .namedfile .file import NamedBlobFile
29- from Products .CMFPlone .utils import safe_unicode
3028from z3c .relationfield import RelationValue
3129from zope .component import getUtility
3230from zope .i18n import translate
@@ -318,16 +316,16 @@ def test_call(self):
318316 self .assertIn (u">5032 Isnes<" , rendered )
319317
320318
321- class TestSigningAnnotationInfoView (unittest .TestCase , ImioTestHelpers ):
322- """Test SigningAnnotationInfoView """
319+ class TestOMSessionAnnotationInfoView (unittest .TestCase , ImioTestHelpers ):
320+ """Test OMSessionAnnotationInfoView """
323321
324322 layer = DMSMAIL_INTEGRATION_TESTING
325323
326324 def setUp (self ):
327325 self .portal = self .layer ["portal" ]
328326 change_user (self .portal )
329327 self .om1 = get_object (oid = "reponse1" , ptype = "dmsoutgoingmail" )
330- self .view = SigningAnnotationInfoView (self .om1 , self .portal .REQUEST )
328+ self .view = OMSessionAnnotationInfoView (self .om1 , self .portal .REQUEST )
331329 self .pf = self .portal ["contacts" ]["personnel-folder" ]
332330 self .pgof = self .portal ["contacts" ]["plonegroup-organization" ]
333331
@@ -394,68 +392,12 @@ def _approve_all_files(self, omail, files, approval):
394392 approval .approve_file (files [1 ], "bourgmestre" , transition = "propose_to_be_signed" )
395393 approval .approve_file (files [0 ], "bourgmestre" , transition = "propose_to_be_signed" )
396394
397- def test_call (self ):
398- with self .assertRaises (Unauthorized ):
399- self .view ()
400- login (self .portal .aq_parent , "admin" )
401- self .assertIsInstance (self .view (), basestring )
402-
403- def test_render_value (self ):
404- # Dict
405- self .assertEqual (self .view ._render_value ({}), u"{}" )
406- self .assertEqual (
407- self .view ._render_value ({"key" : "val" }),
408- u"{\n 'key': 'val',\n }" ,
409- )
410-
411- # Indentation: nested value increases indent level
412- self .assertEqual (
413- self .view ._render_value ({"key" : ["a" ]}),
414- u"{\n 'key': [\n 'a',\n ],\n }" ,
415- )
416-
417- # List
418- self .assertEqual (self .view ._render_value ([]), u"[]" )
419- self .assertEqual (
420- self .view ._render_value (["a" , "b" ]),
421- u"[\n 'a',\n 'b',\n ]" ,
422- )
423-
424- # Tuple
425- self .assertEqual (self .view ._render_value (()), u"[]" )
426-
427- # String
428- self .assertEqual (self .view ._render_value (u"hello" ), u"u'hello'" )
429-
430- # UID not found
431- fake_uid = u"a" * 32
432- self .assertEqual (
433- self .view ._render_value (fake_uid ),
434- u"<span title='not found'>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</span>" ,
435- )
436-
437- # UID found
438- self .assertEqual (
439- self .view ._render_value (self .om1 .UID ()),
440- u"<a href='http://nohost/plone/outgoing-mail/202608/reponse1' title='/plone/outgoing-mail/202608/reponse1'>R\xe9 ponse 1</a>" ,
441- )
442-
443- def test_uid_to_link (self ):
444- uid = self .om1 .UID ()
445- result = self .view ._uid_to_link (uid )
446- self .assertIn (u"<a href=" , result )
447- self .assertIn (self .om1 .absolute_url (), result )
448-
449- result = self .view ._uid_to_link (u"a" * 32 )
450- self .assertIn (u"<span" , result )
451- self .assertIn (u"not found" , result )
452-
453- def test_approval_and_esign_sessions (self ):
454- """Test approval_annot_html and esign_session_html after a true approval process."""
395+ def test_annot_html (self ):
396+ """Test approval_annot_html and esign_session_html."""
455397 omail , files , approval = self ._setup_esign_omail ()
456398 self ._approve_all_files (omail , files , approval )
457399
458- view = SigningAnnotationInfoView (omail , self .portal .REQUEST )
400+ view = OMSessionAnnotationInfoView (omail , self .portal .REQUEST )
459401
460402 # approval annot html
461403 self .assertEqual (
@@ -501,15 +443,15 @@ def test_approval_and_esign_sessions(self):
501443 False,
502444 ],
503445 'files': [
504- <a href='http://nohost/plone/outgoing-mail/202608 /om-esign/file0' title='/plone/outgoing-mail/202608 /om-esign/file0'>Réponse salle.odt</a>,
505- <a href='http://nohost/plone/outgoing-mail/202608 /om-esign/file1' title='/plone/outgoing-mail/202608 /om-esign/file1'>Réponse salle.odt</a>,
446+ <a href='http://nohost/plone/outgoing-mail/{folder_name} /om-esign/file0/view ' title='/plone/outgoing-mail/{folder_name} /om-esign/file0'>Réponse salle.odt</a>,
447+ <a href='http://nohost/plone/outgoing-mail/{folder_name} /om-esign/file1/view ' title='/plone/outgoing-mail/{folder_name} /om-esign/file1'>Réponse salle.odt</a>,
506448 ],
507449 'pdf_files': [
508450 [
509- <a href='http://nohost/plone/outgoing-mail/202608 /om-esign/reponse-salle.pdf' title='/plone/outgoing-mail/202608 /om-esign/reponse-salle.pdf'>Réponse salle.pdf</a>,
451+ <a href='http://nohost/plone/outgoing-mail/{folder_name} /om-esign/reponse-salle.pdf/view ' title='/plone/outgoing-mail/{folder_name} /om-esign/reponse-salle.pdf'>Réponse salle.pdf</a>,
510452 ],
511453 [
512- <a href='http://nohost/plone/outgoing-mail/202608 /om-esign/reponse-salle-1.pdf' title='/plone/outgoing-mail/202608 /om-esign/reponse-salle-1.pdf'>Réponse salle.pdf</a>,
454+ <a href='http://nohost/plone/outgoing-mail/{folder_name} /om-esign/reponse-salle-1.pdf/view ' title='/plone/outgoing-mail/{folder_name} /om-esign/reponse-salle-1.pdf'>Réponse salle.pdf</a>,
513455 ],
514456 ],
515457 'session_ids': [
@@ -532,6 +474,7 @@ def test_approval_and_esign_sessions(self):
532474 repr (approval .annot ["approval" ][0 ][1 ]["approved_on" ]),
533475 repr (approval .annot ["approval" ][1 ][0 ]["approved_on" ]),
534476 repr (approval .annot ["approval" ][1 ][1 ]["approved_on" ]),
477+ folder_name = omail .__parent__ .__name__ ,
535478 ),
536479 )
537480
@@ -551,20 +494,20 @@ def test_approval_and_esign_sessions(self):
551494 'discriminators': [],
552495 'files': [
553496 {{
554- 'context_uid': <a href='http://nohost/plone/outgoing-mail/{folder_name}/om-esign' title='/plone/outgoing-mail/{folder_name}/om-esign'>Courrier test esign</a>,
497+ 'context_uid': <a href='http://nohost/plone/outgoing-mail/{folder_name}/om-esign/view ' title='/plone/outgoing-mail/{folder_name}/om-esign'>Courrier test esign</a>,
555498 'filename': u'R\\ xe9ponse salle__{pdf1_uid}.pdf',
556499 'scan_id': '012999900000601',
557500 'status': '',
558501 'title': u'R\\ xe9ponse salle.pdf',
559- 'uid': <a href='http://nohost/plone/outgoing-mail/{folder_name}/om-esign/reponse-salle.pdf' title='/plone/outgoing-mail/{folder_name}/om-esign/reponse-salle.pdf'>Réponse salle.pdf</a>,
502+ 'uid': <a href='http://nohost/plone/outgoing-mail/{folder_name}/om-esign/reponse-salle.pdf/view ' title='/plone/outgoing-mail/{folder_name}/om-esign/reponse-salle.pdf'>Réponse salle.pdf</a>,
560503 }},
561504 {{
562- 'context_uid': <a href='http://nohost/plone/outgoing-mail/{folder_name}/om-esign' title='/plone/outgoing-mail/{folder_name}/om-esign'>Courrier test esign</a>,
505+ 'context_uid': <a href='http://nohost/plone/outgoing-mail/{folder_name}/om-esign/view ' title='/plone/outgoing-mail/{folder_name}/om-esign'>Courrier test esign</a>,
563506 'filename': u'R\\ xe9ponse salle__{pdf2_uid}.pdf',
564507 'scan_id': '012999900000601',
565508 'status': '',
566509 'title': u'R\\ xe9ponse salle.pdf',
567- 'uid': <a href='http://nohost/plone/outgoing-mail/{folder_name}/om-esign/reponse-salle-1.pdf' title='/plone/outgoing-mail/{folder_name}/om-esign/reponse-salle-1.pdf'>Réponse salle.pdf</a>,
510+ 'uid': <a href='http://nohost/plone/outgoing-mail/{folder_name}/om-esign/reponse-salle-1.pdf/view ' title='/plone/outgoing-mail/{folder_name}/om-esign/reponse-salle-1.pdf'>Réponse salle.pdf</a>,
568511 }},
569512 ],
570513 'last_update': {last_update},
0 commit comments