3434from ietf .nomcom .factories import NomComFactory , FeedbackFactory , \
3535 nomcom_kwargs_for_year , provide_private_key_to_test_client , \
3636 key
37- from ietf .person .factories import PersonFactory
37+ from ietf .person .factories import PersonFactory , EmailFactory
3838from ietf .dbtemplate .factories import DBTemplateFactory
3939from ietf .dbtemplate .models import DBTemplate
4040
@@ -481,11 +481,7 @@ def test_public_nominate(self):
481481
482482 self .nominate_view (public = True ,confirmation = True )
483483
484- self .assertEqual (len (outbox ), messages_before + 4 )
485-
486- self .assertTrue ('New person' in outbox [- 4 ]['Subject' ])
487- self .assertTrue ('nomcomchair' in outbox [- 4 ]['To' ])
488- self .assertTrue ('secretariat' in outbox [- 4 ]['To' ])
484+ self .assertEqual (len (outbox ), messages_before + 3 )
489485
490486 self .assertEqual ('IETF Nomination Information' , outbox [- 3 ]['Subject' ])
491487 self .assertTrue ('nominee' in outbox [- 3 ]['To' ])
@@ -518,15 +514,23 @@ def test_public_nominate_with_automatic_questionnaire(self):
518514 login_testing_unauthorized (self , COMMUNITY_USER , self .public_nominate_url )
519515 empty_outbox ()
520516 self .nominate_view (public = True )
521- self .assertEqual (len (outbox ), 4 )
517+ self .assertEqual (len (outbox ), 3 )
522518 # test_public_nominate checks the other messages
523- self .assertTrue ('Questionnaire' in outbox [2 ]['Subject' ])
524- self .assertTrue ('nominee@' in outbox [2 ]['To' ])
519+ self .assertTrue ('Questionnaire' in outbox [1 ]['Subject' ])
520+ self .assertTrue ('nominee@' in outbox [1 ]['To' ])
525521
526522
527523 def nominate_view (self , * args , ** kwargs ):
528524 public = kwargs .pop ('public' , True )
525+ nominee = kwargs .pop ('nominee' , None )
529526 nominee_email = kwargs .pop ('nominee_email' , u'nominee@example.com' )
527+ if not nominee :
528+ nominee = Email .objects .filter (address = nominee_email ).first ()
529+ if not nominee :
530+ nominee = EmailFactory (address = nominee_email ,primary = True )
531+ if not nominee .person :
532+ nominee .person = PersonFactory ()
533+ nominee .save ()
530534 nominator_email = kwargs .pop ('nominator_email' , "%s%s" % (COMMUNITY_USER , EMAIL_DOMAIN ))
531535 position_name = kwargs .pop ('position' , 'IAOC' )
532536 confirmation = kwargs .pop ('confirmation' , False )
@@ -553,16 +557,13 @@ def nominate_view(self, *args, **kwargs):
553557 self .assertEqual (len (q ("#nominate-form" )), 1 )
554558
555559 position = Position .objects .get (name = position_name )
556- candidate_email = nominee_email
557- candidate_name = u'nominee'
558560 comments = u'Test nominate view. Comments with accents äöåÄÖÅ éáíóú âêîôû ü àèìòù.'
559561 candidate_phone = u'123456'
560562
561- test_data = {'candidate_name' : candidate_name ,
562- 'candidate_email' : candidate_email ,
563+ test_data = {'candidate' : nominee .pk ,
563564 'candidate_phone' : candidate_phone ,
564565 'position' : position .id ,
565- 'comments ' : comments ,
566+ 'qualifications ' : comments ,
566567 'confirmation' : confirmation }
567568 if not public :
568569 test_data ['nominator_email' ] = nominator_email
@@ -573,12 +574,11 @@ def nominate_view(self, *args, **kwargs):
573574 self .assertContains (response , "alert-success" )
574575
575576 # check objects
576- email = Email .objects .get (address = candidate_email )
577- Person .objects .get (name = candidate_name , address = candidate_email )
578- nominee = Nominee .objects .get (email = email )
579- NomineePosition .objects .get (position = position , nominee = nominee )
577+ ## TODO - straighten this _obj vs _email naming mess out
578+ nominee_obj = Nominee .objects .get (email = nominee )
579+ NomineePosition .objects .get (position = position , nominee = nominee_obj )
580580 feedback = Feedback .objects .filter (positions__in = [position ],
581- nominees__in = [nominee ],
581+ nominees__in = [nominee_obj ],
582582 type = FeedbackTypeName .objects .get (slug = 'nomina' )).latest ('id' )
583583 if public :
584584 self .assertEqual (feedback .author , nominator_email )
@@ -588,13 +588,85 @@ def nominate_view(self, *args, **kwargs):
588588
589589 self .assertEqual (check_comments (feedback .comments , comments , self .privatekey_file ), True )
590590 Nomination .objects .get (position = position ,
591- candidate_name = candidate_name ,
592- candidate_email = candidate_email ,
591+ candidate_name = nominee . person . plain_name () ,
592+ candidate_email = nominee . address ,
593593 candidate_phone = candidate_phone ,
594- nominee = nominee ,
594+ nominee = nominee_obj ,
595595 comments = feedback ,
596596 nominator_email = "%s%s" % (COMMUNITY_USER , EMAIL_DOMAIN ))
597597
598+ ## Save this for repurposing to test the to-be-created 'by name and address' form
599+ ## def nominate_view(self, *args, **kwargs):
600+ ## public = kwargs.pop('public', True)
601+ ## nominee_email = kwargs.pop('nominee_email', u'nominee@example.com')
602+ ## nominator_email = kwargs.pop('nominator_email', "%s%s" % (COMMUNITY_USER, EMAIL_DOMAIN))
603+ ## position_name = kwargs.pop('position', 'IAOC')
604+ ## confirmation = kwargs.pop('confirmation', False)
605+ ##
606+ ## if public:
607+ ## nominate_url = self.public_nominate_url
608+ ## else:
609+ ## nominate_url = self.private_nominate_url
610+ ## response = self.client.get(nominate_url)
611+ ## self.assertEqual(response.status_code, 200)
612+ ##
613+ ## nomcom = get_nomcom_by_year(self.year)
614+ ## if not nomcom.public_key:
615+ ## q = PyQuery(response.content)
616+ ## self.assertEqual(len(q("#nominate-form")), 0)
617+ ##
618+ ## # save the cert file in tmp
619+ ## nomcom.public_key.storage.location = tempfile.gettempdir()
620+ ## nomcom.public_key.save('cert', File(open(self.cert_file.name, 'r')))
621+ ##
622+ ## response = self.client.get(nominate_url)
623+ ## self.assertEqual(response.status_code, 200)
624+ ## q = PyQuery(response.content)
625+ ## self.assertEqual(len(q("#nominate-form")), 1)
626+ ##
627+ ## position = Position.objects.get(name=position_name)
628+ ## candidate_email = nominee_email
629+ ## candidate_name = u'nominee'
630+ ## comments = u'Test nominate view. Comments with accents äöåÄÖÅ éáíóú âêîôû ü àèìòù.'
631+ ## candidate_phone = u'123456'
632+ ##
633+ ## test_data = {'candidate_name': candidate_name,
634+ ## 'candidate_email': candidate_email,
635+ ## 'candidate_phone': candidate_phone,
636+ ## 'position': position.id,
637+ ## 'qualifications': comments,
638+ ## 'confirmation': confirmation}
639+ ## if not public:
640+ ## test_data['nominator_email'] = nominator_email
641+ ##
642+ ## response = self.client.post(nominate_url, test_data)
643+ ## self.assertEqual(response.status_code, 200)
644+ ## q = PyQuery(response.content)
645+ ## self.assertContains(response, "alert-success")
646+ ##
647+ ## # check objects
648+ ## email = Email.objects.get(address=candidate_email)
649+ ## Person.objects.get(name=candidate_name, address=candidate_email)
650+ ## nominee = Nominee.objects.get(email=email)
651+ ## NomineePosition.objects.get(position=position, nominee=nominee)
652+ ## feedback = Feedback.objects.filter(positions__in=[position],
653+ ## nominees__in=[nominee],
654+ ## type=FeedbackTypeName.objects.get(slug='nomina')).latest('id')
655+ ## if public:
656+ ## self.assertEqual(feedback.author, nominator_email)
657+ ##
658+ ## # to check feedback comments are saved like enrypted data
659+ ## self.assertNotEqual(feedback.comments, comments)
660+ ##
661+ ## self.assertEqual(check_comments(feedback.comments, comments, self.privatekey_file), True)
662+ ## Nomination.objects.get(position=position,
663+ ## candidate_name=candidate_name,
664+ ## candidate_email=candidate_email,
665+ ## candidate_phone=candidate_phone,
666+ ## nominee=nominee,
667+ ## comments=feedback,
668+ ## nominator_email="%s%s" % (COMMUNITY_USER, EMAIL_DOMAIN))
669+ ##
598670 def test_add_questionnaire (self ):
599671 self .access_chair_url (self .add_questionnaire_url )
600672 return self .add_questionnaire ()
@@ -656,10 +728,10 @@ def test_public_feedback(self):
656728 self .feedback_view (public = True ,confirmation = True )
657729 # feedback_view does a nomination internally: there is a lot of email related to that - tested elsewhere
658730 # We're interested in the confirmation receipt here
659- self .assertEqual (len (outbox ),4 )
660- self .assertEqual ('NomCom comment confirmation' , outbox [3 ]['Subject' ])
661- self .assertTrue ('plain' in outbox [3 ]['To' ])
662- self .assertTrue (u'Comments with accents äöå' in unicode (outbox [3 ].get_payload (decode = True ),"utf-8" ,"replace" ))
731+ self .assertEqual (len (outbox ),3 )
732+ self .assertEqual ('NomCom comment confirmation' , outbox [2 ]['Subject' ])
733+ self .assertTrue ('plain' in outbox [2 ]['To' ])
734+ self .assertTrue (u'Comments with accents äöå' in unicode (outbox [2 ].get_payload (decode = True ),"utf-8" ,"replace" ))
663735
664736 empty_outbox ()
665737 self .feedback_view (public = True )
0 commit comments