2828 NomineePositionStateName , Feedback , FeedbackTypeName , \
2929 Nomination , FeedbackLastSeen
3030from ietf .nomcom .forms import EditMembersForm , EditMembersFormPreview
31- from ietf .nomcom .utils import get_nomcom_by_year , get_or_create_nominee , get_hash_nominee_position
31+ from ietf .nomcom .utils import get_nomcom_by_year , make_nomineeposition , get_hash_nominee_position
3232from ietf .nomcom .management .commands .send_reminders import Command , is_time_to_send
3333
3434from ietf .nomcom .factories import NomComFactory , FeedbackFactory , \
@@ -951,20 +951,22 @@ def setUp(self):
951951 today = datetime .date .today ()
952952 t_minus_3 = today - datetime .timedelta (days = 3 )
953953 t_minus_4 = today - datetime .timedelta (days = 4 )
954- n = get_or_create_nominee (self .nomcom ,"Nominee 1" ,"nominee1@example.org" ,gen ,None )
954+ e1 = EmailFactory (address = "nominee1@example.org" ,person = PersonFactory (name = u"Nominee 1" ))
955+ e2 = EmailFactory (address = "nominee2@example.org" ,person = PersonFactory (name = u"Nominee 2" ))
956+ n = make_nomineeposition (self .nomcom ,e1 .person ,gen ,None )
955957 np = n .nomineeposition_set .get (position = gen )
956958 np .time = t_minus_3
957959 np .save ()
958- n = get_or_create_nominee (self .nomcom ,"Nominee 1" , "nominee1@example.org" ,iab ,None )
960+ n = make_nomineeposition (self .nomcom ,e1 . person ,iab ,None )
959961 np = n .nomineeposition_set .get (position = iab )
960962 np .state = NomineePositionStateName .objects .get (slug = 'accepted' )
961963 np .time = t_minus_3
962964 np .save ()
963- n = get_or_create_nominee (self .nomcom ,"Nominee 2" , "nominee2@example.org" ,rai ,None )
965+ n = make_nomineeposition (self .nomcom ,e2 . person ,rai ,None )
964966 np = n .nomineeposition_set .get (position = rai )
965967 np .time = t_minus_4
966968 np .save ()
967- n = get_or_create_nominee (self .nomcom ,"Nominee 2" , "nominee2@example.org" ,gen ,None )
969+ n = make_nomineeposition (self .nomcom ,e2 . person ,gen ,None )
968970 np = n .nomineeposition_set .get (position = gen )
969971 np .state = NomineePositionStateName .objects .get (slug = 'accepted' )
970972 np .time = t_minus_4
@@ -1445,14 +1447,51 @@ def test_simple_feedback_pending(self):
14451447 'form-0-id' : fb .id ,
14461448 'form-0-type' : 'nomina' ,
14471449 'form-0-position' : position .id ,
1448- 'form-0-candidate_name' : nominee .name (),
1449- 'form-0-candidate_email' : nominee .email .address ,
1450+ 'form-0-searched_email' : nominee .email .address ,
14501451 })
14511452 self .assertEqual (response .status_code ,302 )
14521453 fb = Feedback .objects .get (id = fb .id )
14531454 self .assertEqual (fb .type_id ,'nomina' )
14541455 self .assertEqual (nominee .feedback_set .count (),fb_count_before + 1 )
14551456
1457+ # Classify a newperson
1458+ fb = FeedbackFactory (nomcom = self .nc ,type_id = None )
1459+ position = self .nc .position_set .first ()
1460+ response = self .client .post (url , {'form-TOTAL_FORMS' :1 ,
1461+ 'form-INITIAL_FORMS' :1 ,
1462+ 'end' :'Save feedback' ,
1463+ 'form-0-id' : fb .id ,
1464+ 'form-0-type' : 'nomina' ,
1465+ 'form-0-position' : position .id ,
1466+ 'form-0-candidate_email' : 'newperson@example.com' ,
1467+ 'form-0-candidate_name' : 'New Person' ,
1468+ })
1469+ self .assertEqual (response .status_code ,302 )
1470+ fb = Feedback .objects .get (id = fb .id )
1471+ self .assertEqual (fb .type_id ,'nomina' )
1472+ self .assertTrue (fb .nominees .filter (person__name = 'New Person' ).exists ())
1473+
1474+ # check for failure when trying to add a newperson that already exists
1475+
1476+ fb = FeedbackFactory (nomcom = self .nc ,type_id = None )
1477+ position = self .nc .position_set .all ()[1 ]
1478+ nominee = self .nc .nominee_set .get (person__email__address = 'newperson@example.com' )
1479+ fb_count_before = nominee .feedback_set .count ()
1480+ response = self .client .post (url , {'form-TOTAL_FORMS' :1 ,
1481+ 'form-INITIAL_FORMS' :1 ,
1482+ 'end' :'Save feedback' ,
1483+ 'form-0-id' : fb .id ,
1484+ 'form-0-type' : 'nomina' ,
1485+ 'form-0-position' : position .id ,
1486+ 'form-0-candidate_email' : 'newperson@example.com' ,
1487+ 'form-0-candidate_name' : 'New Person' ,
1488+ })
1489+ self .assertEqual (response .status_code ,200 )
1490+ self .assertTrue ('already exists' in unicontent (response ))
1491+ fb = Feedback .objects .get (id = fb .id )
1492+ self .assertEqual (fb .type_id ,None )
1493+ self .assertEqual (nominee .feedback_set .count (),fb_count_before )
1494+
14561495 fb = FeedbackFactory (nomcom = self .nc ,type_id = None )
14571496 np = NomineePosition .objects .filter (position__nomcom = self .nc ,state = 'accepted' ).first ()
14581497 fb_count_before = np .nominee .feedback_set .count ()
@@ -1461,7 +1500,7 @@ def test_simple_feedback_pending(self):
14611500 'end' :'Save feedback' ,
14621501 'form-0-id' : fb .id ,
14631502 'form-0-type' : 'questio' ,
1464- 'form-0-nominee' : '%s_%s' % (np .position .id ,np .nominee .id ),
1503+ 'form-0-nominee' : '%s_%s' % (np .position .id ,np .nominee .id ),
14651504 })
14661505 self .assertEqual (response .status_code ,302 )
14671506 fb = Feedback .objects .get (id = fb .id )
@@ -1504,23 +1543,23 @@ def test_complicated_feedback_pending(self):
15041543 self .assertEqual (q ('input[name=\" form-0-type\" ]' ).attr ['value' ],'nomina' )
15051544 self .assertEqual (q ('input[name=\" extra_ids\" ]' ).attr ['value' ],'%s:comment' % fb2 .id )
15061545
1507- # Second formset
1546+ # Second formset
15081547 response = self .client .post (url , {'form-TOTAL_FORMS' :1 ,
15091548 'form-INITIAL_FORMS' :1 ,
15101549 'end' :'Save feedback' ,
15111550 'form-0-id' : fb1 .id ,
15121551 'form-0-type' : 'nomina' ,
15131552 'form-0-position' : new_position_for_nominee .id ,
1514- 'form-0-candidate_name' : nominee . name () ,
1515- 'form-0-candidate_email' : nominee . email . address ,
1553+ 'form-0-candidate_name' : 'Totally New Person' ,
1554+ 'form-0-candidate_email' : 'totallynew@example.org' ,
15161555 'extra_ids' : '%s:comment' % fb2 .id ,
15171556 })
15181557 self .assertEqual (response .status_code ,200 ) # Notice that this is also is not a 302
1519- fb1 = Feedback .objects .get (id = fb1 .id )
1520- self .assertEqual (fb1 .type_id ,'nomina' )
15211558 q = PyQuery (response .content )
15221559 self .assertEqual (q ('input[name=\" form-0-type\" ]' ).attr ['value' ],'comment' )
15231560 self .assertFalse (q ('input[name=\" extra_ids\" ]' ))
1561+ fb1 = Feedback .objects .get (id = fb1 .id )
1562+ self .assertEqual (fb1 .type_id ,'nomina' )
15241563
15251564 # Exercising the resulting third formset is identical to the simple test above
15261565 # that categorizes a single thing as a comment. Note that it returns a 302.
0 commit comments