1414import debug # pyflakes:ignore
1515
1616from ietf .utils .test_utils import login_testing_unauthorized , TestCase
17- from ietf .utils .mail import outbox
17+ from ietf .utils .mail import outbox , empty_outbox
1818
1919from ietf .person .models import Email , Person
2020from ietf .group .models import Group
@@ -466,8 +466,35 @@ def test_questionnaires_view(self):
466466
467467 def test_public_nominate (self ):
468468 login_testing_unauthorized (self , COMMUNITY_USER , self .public_nominate_url )
469- return self .nominate_view (public = True )
470- self .client .logout ()
469+
470+ messages_before = len (outbox )
471+
472+ self .nominate_view (public = True ,confirmation = True )
473+
474+ self .assertEqual (len (outbox ), messages_before + 4 )
475+
476+ self .assertTrue ('New person' in outbox [- 4 ]['Subject' ])
477+ self .assertTrue ('nomcomchair' in outbox [- 4 ]['To' ])
478+ self .assertTrue ('secretariat' in outbox [- 4 ]['To' ])
479+
480+ self .assertEqual ('IETF Nomination Information' , outbox [- 3 ]['Subject' ])
481+ self .assertTrue ('nominee' in outbox [- 3 ]['To' ])
482+
483+ self .assertEqual ('Nomination Information' , outbox [- 2 ]['Subject' ])
484+ self .assertTrue ('nomcomchair' in outbox [- 2 ]['To' ])
485+
486+ self .assertEqual ('Nomination receipt' , outbox [- 1 ]['Subject' ])
487+ self .assertTrue ('plain' in outbox [- 1 ]['To' ])
488+ self .assertTrue (u'Comments with accents äöå' in unicode (outbox [- 1 ].get_payload (decode = True ),"utf-8" ,"replace" ))
489+
490+ # Nominate the same person for the same position again without asking for confirmation
491+
492+ messages_before = len (outbox )
493+
494+ self .nominate_view (public = True )
495+ self .assertEqual (len (outbox ), messages_before + 1 )
496+ self .assertEqual ('Nomination Information' , outbox [- 1 ]['Subject' ])
497+ self .assertTrue ('nomcomchair' in outbox [- 1 ]['To' ])
471498
472499 def test_private_nominate (self ):
473500 self .access_member_url (self .private_nominate_url )
@@ -479,6 +506,7 @@ def nominate_view(self, *args, **kwargs):
479506 nominee_email = kwargs .pop ('nominee_email' , u'nominee@example.com' )
480507 nominator_email = kwargs .pop ('nominator_email' , "%s%s" % (COMMUNITY_USER , EMAIL_DOMAIN ))
481508 position_name = kwargs .pop ('position' , 'IAOC' )
509+ confirmation = kwargs .pop ('confirmation' , False )
482510
483511 if public :
484512 nominate_url = self .public_nominate_url
@@ -511,7 +539,8 @@ def nominate_view(self, *args, **kwargs):
511539 'candidate_email' : candidate_email ,
512540 'candidate_phone' : candidate_phone ,
513541 'position' : position .id ,
514- 'comments' : comments }
542+ 'comments' : comments ,
543+ 'confirmation' : confirmation }
515544 if not public :
516545 test_data ['nominator_email' ] = nominator_email
517546
@@ -599,8 +628,20 @@ def add_questionnaire(self, *args, **kwargs):
599628
600629 def test_public_feedback (self ):
601630 login_testing_unauthorized (self , COMMUNITY_USER , self .public_feedback_url )
602- return self .feedback_view (public = True )
603- self .client .logout ()
631+
632+ empty_outbox ()
633+ self .feedback_view (public = True ,confirmation = True )
634+ # feedback_view does a nomination internally: there is a lot of email related to that - tested elsewhere
635+ # We're interested in the confirmation receipt here
636+ self .assertEqual (len (outbox ),4 )
637+ self .assertEqual ('NomCom comment confirmation' , outbox [3 ]['Subject' ])
638+ self .assertTrue ('plain' in outbox [3 ]['To' ])
639+ self .assertTrue (u'Comments with accents äöå' in unicode (outbox [3 ].get_payload (decode = True ),"utf-8" ,"replace" ))
640+
641+ empty_outbox ()
642+ self .feedback_view (public = True )
643+ self .assertTrue (len (outbox ),1 )
644+ self .assertFalse ('confirmation' in outbox [0 ]['Subject' ])
604645
605646 def test_private_feedback (self ):
606647 self .access_member_url (self .private_feedback_url )
@@ -612,6 +653,7 @@ def feedback_view(self, *args, **kwargs):
612653 nominee_email = kwargs .pop ('nominee_email' , u'nominee@example.com' )
613654 nominator_email = kwargs .pop ('nominator_email' , "%s%s" % (COMMUNITY_USER , EMAIL_DOMAIN ))
614655 position_name = kwargs .pop ('position' , 'IAOC' )
656+ confirmation = kwargs .pop ('confirmation' , False )
615657
616658 self .nominate_view (public = public ,
617659 nominee_email = nominee_email ,
@@ -645,7 +687,8 @@ def feedback_view(self, *args, **kwargs):
645687 test_data = {'comments' : comments ,
646688 'position_name' : position .name ,
647689 'nominee_name' : nominee .email .person .name ,
648- 'nominee_email' : nominee .email .address }
690+ 'nominee_email' : nominee .email .address ,
691+ 'confirmation' : confirmation }
649692
650693 if public :
651694 test_data ['nominator_email' ] = nominator_email
0 commit comments