diff --git a/ietf/secr/sreq/tests.py b/ietf/secr/sreq/tests.py index 25942638f..b0364f7f1 100644 --- a/ietf/secr/sreq/tests.py +++ b/ietf/secr/sreq/tests.py @@ -104,7 +104,7 @@ class SessionRequestTestCase(TestCase): 'joint_with_groups': group3.acronym + ' ' + group4.acronym, 'joint_for_session': '2', 'timeranges': ['thursday-afternoon-early', 'thursday-afternoon-late'], - 'session_set-TOTAL_FORMS': '2', + 'session_set-TOTAL_FORMS': '3', # matches what view actually sends, even with only 2 filled in 'session_set-INITIAL_FORMS': '1', 'session_set-MIN_NUM_FORMS': '1', 'session_set-MAX_NUM_FORMS': '3', @@ -130,6 +130,16 @@ class SessionRequestTestCase(TestCase): 'session_set-1-attendees': attendees, 'session_set-1-comments': comments, 'session_set-1-DELETE': '', + 'session_set-2-id': '', + 'session_set-2-name': '', + 'session_set-2-short': '', + 'session_set-2-purpose': 'regular', + 'session_set-2-type': 'regular', + 'session_set-2-requested_duration': '', + 'session_set-2-on_agenda': 'True', + 'session_set-2-attendees': attendees, + 'session_set-2-comments': '', + 'session_set-2-DELETE': 'on', 'submit': 'Continue'} r = self.client.post(url, post_data, HTTP_HOST='example.com') redirect_url = reverse('ietf.secr.sreq.views.view', kwargs={'acronym': 'mars'}) @@ -172,7 +182,7 @@ class SessionRequestTestCase(TestCase): 'comments':'need lights', 'joint_with_groups': group2.acronym, 'joint_for_session': '1', - 'session_set-TOTAL_FORMS': '2', + 'session_set-TOTAL_FORMS': '3', # matches what view actually sends, even with only 2 filled in 'session_set-INITIAL_FORMS': '2', 'session_set-MIN_NUM_FORMS': '1', 'session_set-MAX_NUM_FORMS': '3', @@ -198,6 +208,16 @@ class SessionRequestTestCase(TestCase): 'session_set-1-attendees': sessions[1].attendees, 'session_set-1-comments': sessions[1].comments, 'session_set-1-DELETE': '', + 'session_set-2-id': '', + 'session_set-2-name': '', + 'session_set-2-short': '', + 'session_set-2-purpose': 'regular', + 'session_set-2-type': 'regular', + 'session_set-2-requested_duration': '', + 'session_set-2-on_agenda': 'True', + 'session_set-2-attendees': attendees, + 'session_set-2-comments': '', + 'session_set-2-DELETE': 'on', 'submit': 'Continue'} r = self.client.post(url, post_data, HTTP_HOST='example.com') self.assertRedirects(r, redirect_url) @@ -222,6 +242,74 @@ class SessionRequestTestCase(TestCase): r = self.client.get(redirect_url) self.assertContains(r, 'First session with: {}'.format(group2.acronym)) + + @override_settings(SECR_VIRTUAL_MEETINGS=tuple()) # ensure not unexpectedly testing a virtual meeting session + def test_edit_constraint_bethere(self): + meeting = MeetingFactory(type_id='ietf', date=datetime.date.today()) + mars = RoleFactory(name_id='chair', person__user__username='marschairman', group__acronym='mars').group + session = SessionFactory(meeting=meeting, group=mars, status_id='sched') + Constraint.objects.create( + meeting=meeting, + source=mars, + person=Person.objects.get(user__username='marschairman'), + name_id='bethere', + ) + self.assertEqual(session.people_constraints.count(), 1) + url = reverse('ietf.secr.sreq.views.edit', kwargs=dict(acronym='mars')) + self.client.login(username='marschairman', password='marschairman+password') + attendees = '10' + ad = Person.objects.get(user__username='ad') + post_data = { + 'num_session': '1', + 'attendees': attendees, + 'bethere': str(ad.pk), + 'constraint_chair_conflict':'', + 'comments':'', + 'joint_with_groups': '', + 'joint_for_session': '', + 'delete_conflict': 'on', + 'session_set-TOTAL_FORMS': '3', # matches what view actually sends, even with only 2 filled in + 'session_set-INITIAL_FORMS': '1', + 'session_set-MIN_NUM_FORMS': '1', + 'session_set-MAX_NUM_FORMS': '3', + 'session_set-0-id':session.pk, + 'session_set-0-name': session.name, + 'session_set-0-short': session.short, + 'session_set-0-purpose': session.purpose_id, + 'session_set-0-type': session.type_id, + 'session_set-0-requested_duration': '3600', + 'session_set-0-on_agenda': session.on_agenda, + 'session_set-0-remote_instructions': session.remote_instructions, + 'session_set-0-attendees': attendees, + 'session_set-0-comments': '', + 'session_set-0-DELETE': '', + 'session_set-1-id': '', + 'session_set-1-name': '', + 'session_set-1-short': '', + 'session_set-1-purpose':'regular', + 'session_set-1-type':'regular', + 'session_set-1-requested_duration': '', + 'session_set-1-on_agenda': 'True', + 'session_set-1-attendees': attendees, + 'session_set-1-comments': '', + 'session_set-1-DELETE': 'on', + 'session_set-2-id': '', + 'session_set-2-name': '', + 'session_set-2-short': '', + 'session_set-2-purpose': 'regular', + 'session_set-2-type': 'regular', + 'session_set-2-requested_duration': '', + 'session_set-2-on_agenda': 'True', + 'session_set-2-attendees': attendees, + 'session_set-2-comments': '', + 'session_set-2-DELETE': 'on', + 'submit': 'Save', + } + r = self.client.post(url, post_data, HTTP_HOST='example.com') + redirect_url = reverse('ietf.secr.sreq.views.view', kwargs={'acronym': 'mars'}) + self.assertRedirects(r, redirect_url) + self.assertEqual([pc.person for pc in session.people_constraints.all()], [ad]) + def test_edit_inactive_conflicts(self): """Inactive conflicts should be displayed and removable""" meeting = MeetingFactory(type_id='ietf', date=datetime.date.today(), group_conflicts=['chair_conflict']) diff --git a/ietf/secr/sreq/views.py b/ietf/secr/sreq/views.py index f0e708323..65d6e8d0c 100644 --- a/ietf/secr/sreq/views.py +++ b/ietf/secr/sreq/views.py @@ -446,9 +446,9 @@ def edit(request, acronym, num=None): ) login = request.user.person - session = Session() + first_session = Session() if(len(sessions) > 0): - session = sessions[0] + first_session = sessions[0] if request.method == 'POST': button_text = request.POST.get('submit', '') @@ -461,11 +461,10 @@ def edit(request, acronym, num=None): changed_session_forms = [sf for sf in form.session_forms.forms_to_keep if sf.has_changed()] form.session_forms.save() for n, subform in enumerate(form.session_forms): - session = subform.instance - if session in form.session_forms.new_objects: + if subform.instance in form.session_forms.new_objects: SchedulingEvent.objects.create( - session=session, - status_id=status_slug_for_new_session(session, n), + session=subform.instance, + status_id=status_slug_for_new_session(subform.instance, n), by=request.user.person, ) for sf in changed_session_forms: @@ -483,10 +482,10 @@ def edit(request, acronym, num=None): new_joint_for_session_idx = int(form.data.get('joint_for_session', '-1')) - 1 current_joint_for_session_idx = None current_joint_with_groups = None - for idx, session in enumerate(sessions): - if session.joint_with_groups.count(): + for idx, sess in enumerate(sessions): + if sess.joint_with_groups.count(): current_joint_for_session_idx = idx - current_joint_with_groups = session.joint_with_groups.all() + current_joint_with_groups = sess.joint_with_groups.all() if current_joint_with_groups != new_joint_with_groups or current_joint_for_session_idx != new_joint_for_session_idx: if current_joint_for_session_idx is not None: @@ -520,13 +519,13 @@ def edit(request, acronym, num=None): new_resource_ids = form.cleaned_data['resources'] new_resources = [ ResourceAssociation.objects.get(pk=a) for a in new_resource_ids] - session.resources = new_resources + first_session.resources = new_resources if 'bethere' in form.changed_data and set(form.cleaned_data['bethere'])!=set(initial['bethere']): - session.constraints().filter(name='bethere').delete() + first_session.constraints().filter(name='bethere').delete() bethere_cn = ConstraintName.objects.get(slug='bethere') for p in form.cleaned_data['bethere']: - Constraint.objects.create(name=bethere_cn, source=group, person=p, meeting=session.meeting) + Constraint.objects.create(name=bethere_cn, source=group, person=p, meeting=first_session.meeting) if 'session_time_relation' in form.changed_data: Constraint.objects.filter(meeting=meeting, source=group, name='time_relation').delete()