@@ -95,6 +95,7 @@ def test_edit(self):
9595 attendees = 10
9696 comments = 'need lights'
9797 mars_sessions = meeting .session_set .filter (group__acronym = 'mars' )
98+ empty_outbox ()
9899 post_data = {'num_session' :'2' ,
99100 'attendees' : attendees ,
100101 'constraint_chair_conflict' :iabprog .acronym ,
@@ -156,11 +157,16 @@ def test_edit(self):
156157 self .assertContains (r , group2 .acronym )
157158 self .assertContains (r , 'Second session with: {} {}' .format (group3 .acronym , group4 .acronym ))
158159
160+ # check that a notification was sent
161+ self .assertEqual (len (outbox ), 1 )
162+ notification_payload = get_payload_text (outbox [0 ])
163+ self .assertIn ('1 Hour, 1 Hour' , notification_payload )
164+ self .assertNotIn ('1 Hour, 1 Hour, 1 Hour' , notification_payload )
165+
159166 # Edit again, changing the joint sessions and clearing some fields. The behaviour of
160167 # edit is different depending on whether previous joint sessions were recorded.
168+ empty_outbox ()
161169 post_data = {'num_session' :'2' ,
162- 'length_session1' :'3600' ,
163- 'length_session2' :'3600' ,
164170 'attendees' :attendees ,
165171 'constraint_chair_conflict' :'' ,
166172 'comments' :'need lights' ,
@@ -206,6 +212,12 @@ def test_edit(self):
206212 self .assertEqual (list (sessions [0 ].joint_with_groups .all ()), [group2 ])
207213 self .assertFalse (sessions [1 ].joint_with_groups .count ())
208214
215+ # check that a notification was sent
216+ self .assertEqual (len (outbox ), 1 )
217+ notification_payload = get_payload_text (outbox [0 ])
218+ self .assertIn ('1 Hour, 1 Hour' , notification_payload )
219+ self .assertNotIn ('1 Hour, 1 Hour, 1 Hour' , notification_payload )
220+
209221 # Check whether the updated data is visible on the view page
210222 r = self .client .get (redirect_url )
211223 self .assertContains (r , 'First session with: {}' .format (group2 .acronym ))
@@ -579,7 +591,7 @@ def test_request_notification(self):
579591 sessions = Session .objects .filter (meeting = meeting ,group = group )
580592 self .assertEqual (len (sessions ), 2 )
581593 session = sessions [0 ]
582-
594+
583595 self .assertEqual (session .resources .count (),1 )
584596 self .assertEqual (session .people_constraints .count (),1 )
585597 self .assertEqual (session .constraints ().get (name = 'time_relation' ).time_relation , 'subsequent-days' )
@@ -597,6 +609,115 @@ def test_request_notification(self):
597609 self .assertTrue (ad .ascii_name () in notification_payload )
598610 self .assertIn (ConstraintName .objects .get (slug = 'chair_conflict' ).name , notification_payload )
599611 self .assertIn (group .acronym , notification_payload )
612+ self .assertIn ('1 Hour, 1 Hour' , notification_payload )
613+ self .assertNotIn ('1 Hour, 1 Hour, 1 Hour' , notification_payload )
614+ self .assertNotIn ('The third session requires your approval' , notification_payload )
615+
616+ def test_request_notification_third_session (self ):
617+ meeting = MeetingFactory (type_id = 'ietf' , date = datetime .date .today ())
618+ ad = Person .objects .get (user__username = 'ad' )
619+ area = GroupFactory (type_id = 'area' )
620+ RoleFactory (name_id = 'ad' , person = ad , group = area )
621+ group = GroupFactory (acronym = 'ames' , parent = area )
622+ group2 = GroupFactory (acronym = 'ames2' , parent = area )
623+ group3 = GroupFactory (acronym = 'ames2' , parent = area )
624+ group4 = GroupFactory (acronym = 'ames3' , parent = area )
625+ RoleFactory (name_id = 'chair' , group = group , person__user__username = 'ameschairman' )
626+ resource = ResourceAssociation .objects .create (name_id = 'project' )
627+ # Bit of a test data hack - the fixture now has no used resources to pick from
628+ resource .name .used = True
629+ resource .name .save ()
630+
631+ url = reverse ('ietf.secr.sreq.views.new' ,kwargs = {'acronym' :group .acronym })
632+ confirm_url = reverse ('ietf.secr.sreq.views.confirm' ,kwargs = {'acronym' :group .acronym })
633+ len_before = len (outbox )
634+ attendees = '10'
635+ post_data = {'num_session' :'2' ,
636+ 'third_session' : 'true' ,
637+ 'attendees' :attendees ,
638+ 'bethere' :str (ad .pk ),
639+ 'constraint_chair_conflict' :group4 .acronym ,
640+ 'comments' :'' ,
641+ 'resources' : resource .pk ,
642+ 'session_time_relation' : 'subsequent-days' ,
643+ 'adjacent_with_wg' : group2 .acronym ,
644+ 'joint_with_groups' : group3 .acronym ,
645+ 'joint_for_session' : '2' ,
646+ 'timeranges' : ['thursday-afternoon-early' , 'thursday-afternoon-late' ],
647+ 'session_set-TOTAL_FORMS' : '3' ,
648+ 'session_set-INITIAL_FORMS' : '0' ,
649+ 'session_set-MIN_NUM_FORMS' : '1' ,
650+ 'session_set-MAX_NUM_FORMS' : '3' ,
651+ # no 'session_set-0-id' for new session
652+ 'session_set-0-name' : '' ,
653+ 'session_set-0-short' : '' ,
654+ 'session_set-0-purpose' : 'regular' ,
655+ 'session_set-0-type' : 'regular' ,
656+ 'session_set-0-requested_duration' : '3600' ,
657+ 'session_set-0-on_agenda' : True ,
658+ 'session_set-0-remote_instructions' : '' ,
659+ 'session_set-0-attendees' : attendees ,
660+ 'session_set-0-comments' : '' ,
661+ 'session_set-0-DELETE' : '' ,
662+ # no 'session_set-1-id' for new session
663+ 'session_set-1-name' : '' ,
664+ 'session_set-1-short' : '' ,
665+ 'session_set-1-purpose' : 'regular' ,
666+ 'session_set-1-type' : 'regular' ,
667+ 'session_set-1-requested_duration' : '3600' ,
668+ 'session_set-1-on_agenda' : True ,
669+ 'session_set-1-remote_instructions' : '' ,
670+ 'session_set-1-attendees' : attendees ,
671+ 'session_set-1-comments' : '' ,
672+ 'session_set-1-DELETE' : '' ,
673+ # no 'session_set-2-id' for new session
674+ 'session_set-2-name' : '' ,
675+ 'session_set-2-short' : '' ,
676+ 'session_set-2-purpose' : 'regular' ,
677+ 'session_set-2-type' : 'regular' ,
678+ 'session_set-2-requested_duration' : '3600' ,
679+ 'session_set-2-on_agenda' : True ,
680+ 'session_set-2-remote_instructions' : '' ,
681+ 'session_set-2-attendees' : attendees ,
682+ 'session_set-2-comments' : '' ,
683+ 'session_set-2-DELETE' : '' ,
684+ 'submit' : 'Continue' }
685+ self .client .login (username = "ameschairman" , password = "ameschairman+password" )
686+ # submit
687+ r = self .client .post (url ,post_data )
688+ self .assertEqual (r .status_code , 200 )
689+ q = PyQuery (r .content )
690+ self .assertTrue ('Confirm' in str (q ("title" )), r .context ['form' ].errors )
691+ # confirm
692+ post_data ['submit' ] = 'Submit'
693+ r = self .client .post (confirm_url ,post_data )
694+ self .assertRedirects (r , reverse ('ietf.secr.sreq.views.main' ))
695+ self .assertEqual (len (outbox ),len_before + 1 )
696+ notification = outbox [- 1 ]
697+ notification_payload = get_payload_text (notification )
698+ sessions = Session .objects .filter (meeting = meeting ,group = group )
699+ self .assertEqual (len (sessions ), 3 )
700+ session = sessions [0 ]
701+
702+ self .assertEqual (session .resources .count (),1 )
703+ self .assertEqual (session .people_constraints .count (),1 )
704+ self .assertEqual (session .constraints ().get (name = 'time_relation' ).time_relation , 'subsequent-days' )
705+ self .assertEqual (session .constraints ().get (name = 'wg_adjacent' ).target .acronym , group2 .acronym )
706+ self .assertEqual (
707+ list (session .constraints ().get (name = 'timerange' ).timeranges .all ().values ('name' )),
708+ list (TimerangeName .objects .filter (name__in = ['thursday-afternoon-early' , 'thursday-afternoon-late' ]).values ('name' ))
709+ )
710+ resource = session .resources .first ()
711+ self .assertTrue (resource .desc in notification_payload )
712+ self .assertTrue ('Schedule the sessions on subsequent days' in notification_payload )
713+ self .assertTrue (group2 .acronym in notification_payload )
714+ self .assertTrue ("Can't meet: Thursday early afternoon, Thursday late" in notification_payload )
715+ self .assertTrue ('Second session joint with: {}' .format (group3 .acronym ) in notification_payload )
716+ self .assertTrue (ad .ascii_name () in notification_payload )
717+ self .assertIn (ConstraintName .objects .get (slug = 'chair_conflict' ).name , notification_payload )
718+ self .assertIn (group .acronym , notification_payload )
719+ self .assertIn ('1 Hour, 1 Hour, 1 Hour' , notification_payload )
720+ self .assertIn ('The third session requires your approval' , notification_payload )
600721
601722class LockAppTestCase (TestCase ):
602723 def setUp (self ):
@@ -747,17 +868,17 @@ def test_valid(self):
747868
748869 # Test with two sessions
749870 self .valid_form_data .update ({
750- 'length_session3' : '' ,
751871 'third_session' : '' ,
872+ 'session_set-TOTAL_FORMS' : '2' ,
752873 'joint_for_session' : '2'
753874 })
754875 form = SessionForm (data = self .valid_form_data , group = self .group1 , meeting = self .meeting )
755876 self .assertTrue (form .is_valid ())
756877
757878 # Test with one session
758879 self .valid_form_data .update ({
759- 'length_session2' : '' ,
760880 'num_session' : 1 ,
881+ 'session_set-TOTAL_FORMS' : '1' ,
761882 'joint_for_session' : '1' ,
762883 'session_time_relation' : '' ,
763884 })
@@ -806,7 +927,7 @@ def test_invalid_conflict_with_self(self):
806927 def test_invalid_session_time_relation (self ):
807928 form = self ._invalid_test_helper ({
808929 'third_session' : '' ,
809- 'length_session2 ' : '' ,
930+ 'session_set-TOTAL_FORMS ' : 1 ,
810931 'num_session' : 1 ,
811932 'joint_for_session' : '1' ,
812933 })
0 commit comments