|
| 1 | +# Copyright The IETF Trust 2020, All Rights Reserved |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +from ietf.group.factories import GroupFactory |
| 4 | +from ietf.meeting.factories import SessionFactory, MeetingFactory |
| 5 | +from ietf.meeting.helpers import tag_assignments_with_filter_keywords |
| 6 | +from ietf.utils.test_utils import TestCase |
| 7 | + |
| 8 | + |
| 9 | +class HelpersTests(TestCase): |
| 10 | + def do_test_tag_assignments_with_filter_keywords(self, bof=False, historic=None): |
| 11 | + """Assignments should be tagged properly |
| 12 | + |
| 13 | + The historic param can be None, group, or parent, to specify whether to test |
| 14 | + with no historic_group, a historic_group but no historic_parent, or both. |
| 15 | + """ |
| 16 | + meeting_types = ['regular', 'plenary'] |
| 17 | + group_state_id = 'bof' if bof else 'active' |
| 18 | + group = GroupFactory(state_id=group_state_id) |
| 19 | + historic_group = GroupFactory(state_id=group_state_id) |
| 20 | + historic_parent = GroupFactory(type_id='area') |
| 21 | + |
| 22 | + if historic == 'parent': |
| 23 | + historic_group.historic_parent = historic_parent |
| 24 | + |
| 25 | + # Create meeting and sessions |
| 26 | + meeting = MeetingFactory() |
| 27 | + for meeting_type in meeting_types: |
| 28 | + sess = SessionFactory(group=group, meeting=meeting, type_id=meeting_type) |
| 29 | + ts = sess.timeslotassignments.first().timeslot |
| 30 | + ts.type = sess.type |
| 31 | + ts.save() |
| 32 | + |
| 33 | + # Create an office hours session in the group's area (i.e., parent). This is not |
| 34 | + # currently really needed, but will protect against areas and groups diverging |
| 35 | + # in a way that breaks keywording. |
| 36 | + office_hours = SessionFactory( |
| 37 | + name='some office hours', |
| 38 | + group=group.parent, |
| 39 | + meeting=meeting, |
| 40 | + type_id='other' |
| 41 | + ) |
| 42 | + ts = office_hours.timeslotassignments.first().timeslot |
| 43 | + ts.type = office_hours.type |
| 44 | + ts.save() |
| 45 | + |
| 46 | + assignments = meeting.schedule.assignments.all() |
| 47 | + orig_num_assignments = len(assignments) |
| 48 | + |
| 49 | + # Set up historic groups if needed |
| 50 | + if historic: |
| 51 | + for a in assignments: |
| 52 | + if a.session != office_hours: |
| 53 | + a.session.historic_group = historic_group |
| 54 | + |
| 55 | + # Execute the method under test |
| 56 | + tag_assignments_with_filter_keywords(assignments) |
| 57 | + |
| 58 | + # Assert expected results |
| 59 | + self.assertEqual(len(assignments), orig_num_assignments, 'Should not change number of assignments') |
| 60 | + |
| 61 | + if historic: |
| 62 | + expected_group = historic_group |
| 63 | + expected_area = historic_parent if historic == 'parent' else historic_group.parent |
| 64 | + else: |
| 65 | + expected_group = group |
| 66 | + expected_area = group.parent |
| 67 | + |
| 68 | + for assignment in assignments: |
| 69 | + expected_filter_keywords = {assignment.timeslot.type.slug, assignment.session.type.slug} |
| 70 | + |
| 71 | + if assignment.session == office_hours: |
| 72 | + expected_filter_keywords.update([ |
| 73 | + group.parent.acronym, |
| 74 | + 'officehours', |
| 75 | + 'someofficehours', |
| 76 | + ]) |
| 77 | + else: |
| 78 | + expected_filter_keywords.update([ |
| 79 | + expected_group.acronym, |
| 80 | + expected_area.acronym |
| 81 | + ]) |
| 82 | + if bof: |
| 83 | + expected_filter_keywords.add('bof') |
| 84 | + |
| 85 | + self.assertCountEqual( |
| 86 | + assignment.filter_keywords, |
| 87 | + expected_filter_keywords, |
| 88 | + 'Assignment has incorrect filter keywords' |
| 89 | + ) |
| 90 | + |
| 91 | + def test_tag_assignments_with_filter_keywords(self): |
| 92 | + self.do_test_tag_assignments_with_filter_keywords() |
| 93 | + self.do_test_tag_assignments_with_filter_keywords(historic='group') |
| 94 | + self.do_test_tag_assignments_with_filter_keywords(historic='parent') |
| 95 | + self.do_test_tag_assignments_with_filter_keywords(bof=True) |
| 96 | + self.do_test_tag_assignments_with_filter_keywords(bof=True, historic='group') |
| 97 | + self.do_test_tag_assignments_with_filter_keywords(bof=True, historic='parent') |
0 commit comments