def add_volunteer_opp(self, volunteer_sched_event=None, room=None): if not self.conference.conferenceday_set.exists(): if volunteer_sched_event: self.conf_day = ConferenceDayFactory( day=volunteer_sched_event.starttime.date(), conference=self.conference) else: self.conf_day = ConferenceDayFactory( conference=self.conference) else: self.conf_day = self.conference.conferenceday_set.first() if not volunteer_sched_event: vol_event = GenericEventFactory(e_conference=self.conference, type="Volunteer") volunteer_sched_event = SchedEventFactory( eventitem=vol_event, max_volunteer=self.area.default_volunteers, starttime=noon(self.conf_day)) if not room: room = RoomFactory() ResourceAllocationFactory(event=volunteer_sched_event, resource=LocationFactory(_item=room)) EventLabelFactory(event=volunteer_sched_event, text=self.area.slug) EventLabelFactory(event=volunteer_sched_event, text=self.conference.conference_slug) EventLabelFactory(event=volunteer_sched_event, text="Volunteer") return volunteer_sched_event
def schedule_instance(self, starttime=None, room=None, teacher=None): room = room or self.room teacher = teacher or self.teacher if starttime: sched_event = SchedEventFactory(eventitem=self.bid.eventitem_ptr, starttime=starttime) elif self.sched_event: one_day = timedelta(1) sched_event = SchedEventFactory( eventitem=self.bid.eventitem_ptr, starttime=self.sched_event.starttime + one_day) else: sched_event = SchedEventFactory(eventitem=self.bid.eventitem_ptr, starttime=noon(self.days[0])) ResourceAllocationFactory( event=sched_event, resource=LocationFactory(_item=room.locationitem_ptr)) ResourceAllocationFactory(event=sched_event, resource=WorkerFactory( _item=teacher.workeritem_ptr, role='Teacher')) EventLabelFactory(event=sched_event, text=self.conference.conference_slug) EventLabelFactory(event=sched_event, text="Conference") return sched_event
def book_act_item_for_show(actitem, eventitem): booking = ResourceAllocationFactory.create( event=SchedEventFactory.create(eventitem=eventitem), resource=ActResourceFactory.create(_item=actitem)) EventLabelFactory(event=booking.event, text=eventitem.e_conference.conference_slug) EventLabelFactory(event=booking.event, text=eventitem.calendar_type) return booking
def book_act_item_for_show(actitem, eventitem): booking = ResourceAllocationFactory.create( event=SchedEventFactory.create(eventitem=eventitem), resource=WorkerFactory.create(_item=actitem.performer, role="Performer")) order = OrderingFactory(allocation=booking, class_id=actitem.pk, class_name="Act") EventLabelFactory(event=booking.event, text=eventitem.e_conference.conference_slug) EventLabelFactory(event=booking.event, text=eventitem.calendar_type) return booking
def __init__(self, profile=None, bid=None, event=None, opportunity=None, role=None): if not event: self.window = VolunteerWindowFactory() self.conference = self.window.day.conference else: self.conference = event.e_conference if not VolunteerWindow.objects.filter( day__conference=self.conference).exists(): self.window = VolunteerWindowFactory( day__conference=self.conference) else: self.window = VolunteerWindow.objects.all().first() self.conf_day = self.window.day self.profile = profile or ProfileFactory() if not hasattr(self.profile, 'preferences'): ProfilePreferencesFactory(profile=self.profile) if bid is False: self.bid = None elif bid: self.bid = bid self.profile = self.bid.profile else: self.bid = VolunteerFactory( b_conference=self.conference, profile=self.profile) self.interest = VolunteerInterestFactory( volunteer=self.bid) self.event = event or ShowFactory( e_conference=self.conference) self.role = role or "Volunteer" self.room = RoomFactory() self.sched_event = SchedEventFactory( eventitem=self.event.eventitem_ptr, starttime=datetime.combine(self.window.day.day, self.window.start)) ResourceAllocationFactory( event=self.sched_event, resource=LocationFactory(_item=self.room)) EventLabelFactory(event=self.sched_event, text="General") EventLabelFactory(event=self.sched_event, text=self.conference.conference_slug) self.worker = WorkerFactory(_item=self.profile.workeritem, role=self.role) self.opportunity, self.opp_event = self.add_opportunity(opportunity) self.allocation = ResourceAllocationFactory(resource=self.worker, event=self.opp_event)
def book_worker_item_for_role(workeritem, role, eventitem=None): worker = WorkerFactory.create(_item=workeritem, role=role) if eventitem: event = SchedEventFactory.create(eventitem=eventitem) else: event = SchedEventFactory.create() EventLabelFactory(event=event, text=event.eventitem.e_conference.conference_slug) EventLabelFactory(event=event, text=event.eventitem.calendar_type) booking = ResourceAllocationFactory.create(event=event, resource=worker) return booking
def schedule_instance(self, starttime=None, room=None): room = room or self.room if starttime: sched_event = SchedEventFactory(eventitem=self.show.eventitem_ptr, starttime=starttime) else: sched_event = SchedEventFactory(eventitem=self.show.eventitem_ptr, starttime=noon(self.days[0])) EventLabelFactory(event=sched_event, text=self.conference.conference_slug) EventLabelFactory(event=sched_event, text="General") ResourceAllocationFactory( event=sched_event, resource=LocationFactory(_item=room.locationitem_ptr)) return sched_event
def test_copy_parent_w_area(self): show_context = VolunteerContext() staff = StaffAreaContext(conference=show_context.conference) EventLabelFactory(event=show_context.sched_event, text=staff.area.slug) url = reverse( self.view_name, args=[show_context.sched_event.pk], urlconf='gbe.scheduling.urls') data = { 'copy_mode': 'include_parent', 'copy_to_day': show_context.conf_day.pk, 'room': self.context.room.pk, 'pick_event': "Finish", } login_as(self.privileged_user, self) response = self.client.post(url, data=data, follow=True) max_pk = Event.objects.latest('pk').pk redirect_url = "%s?%s-day=%d&filter=Filter&new=[%s]" % ( reverse('manage_event_list', urlconf='gbe.scheduling.urls', args=[show_context.conference.conference_slug]), show_context.conference.conference_slug, show_context.conf_day.pk, str(max_pk),) self.assertContains(response, reverse( 'edit_staff', urlconf='gbe.scheduling.urls', args=[staff.area.pk]))
def test_volunteer_conflict_sends_warning_to_areastaff(self): context = VolunteerContext() area = StaffAreaFactory(conference=context.conference, staff_lead=context.profile) EventLabelFactory( event=context.opp_event, text=area.slug) change_window = context.add_window() context.bid.available_windows.add(context.window) form = self.get_form(context) form['available_windows'] = [change_window.pk] url = reverse('volunteer_edit', urlconf='gbe.urls', args=[context.bid.pk]) login_as(context.profile, self) response = self.client.post( url, form, follow=True) assert_right_mail_right_addresses( 1, 3, "URGENT: Volunteer Schedule Conflict Occurred", [self.privileged_profile.contact_email, context.profile.contact_email])
def test_no_rehearsal_in_events(self): '''no rehearsal data shows up''' # horrible setup process. Need to fix data = self.set_basic_opportunity() rehearsal = GenericEventFactory( e_conference=data['context'].conference, type="Rehearsal Slot") rehearsal_slot = SchedEventFactory(eventitem=rehearsal, starttime=datetime( 2016, 2, 6, 13, 0, 0, 0, pytz.utc), max_volunteer=10) EventLabelFactory(event=rehearsal_slot, text=data['context'].conference.conference_slug) volunteer = VolunteerFactory(b_conference=data['context'].conference, submitted=True) url = reverse(self.view_name, args=[volunteer.pk], urlconf="gbe.urls") login_as(self.privileged_user, self) response = self.client.get(url) nt.assert_not_in(str(rehearsal), response.content, msg="Event Title for rehearsal should not show up") nt.assert_not_in(date_format(rehearsal_slot.starttime, "SHORT_DATETIME_FORMAT"), response.content, msg="end time for rehearsal shouldn't show up")
def add_opportunity(self, opportunity=None, start_time=None): opportunity = opportunity or GenericEventFactory( e_conference=self.conference, type='Volunteer') start_time = start_time or datetime.combine(self.conf_day.day, time(12, 0, 0)) opp_event = SchedEventFactory(eventitem=opportunity.eventitem_ptr, starttime=start_time, max_volunteer=2) ResourceAllocationFactory(event=opp_event, resource=LocationFactory(_item=self.room)) EventContainerFactory(parent_event=self.sched_event, child_event=opp_event) EventLabelFactory(event=opp_event, text=self.conference.conference_slug) EventLabelFactory(event=opp_event, text="Volunteer") return opportunity, opp_event
def __init__(self, profile=None, event=None, sched_event=None, opportunity=None, role=None, conference=None): if not event: self.conference = conference or ConferenceFactory() else: self.conference = event.e_conference if ConferenceDay.objects.filter(conference=self.conference).exists(): self.conf_day = ConferenceDay.objects.filter( conference=self.conference).first() else: self.conf_day = ConferenceDayFactory(conference=self.conference) self.profile = profile or ProfileFactory() if not hasattr(self.profile, 'preferences'): ProfilePreferencesFactory(profile=self.profile) self.role = role or "Volunteer" self.room = RoomFactory() self.room.conferences.add(self.conference) self.event = event or ShowFactory(e_conference=self.conference) if not sched_event: self.sched_event = SchedEventFactory( eventitem=self.event.eventitem_ptr, starttime=datetime.combine(self.conf_day.day, time(12, 0, 0))) ResourceAllocationFactory( event=self.sched_event, resource=LocationFactory(_item=self.room)) EventLabelFactory(event=self.sched_event, text="General") EventLabelFactory(event=self.sched_event, text=self.conference.conference_slug) else: self.sched_event = sched_event self.worker = WorkerFactory(_item=self.profile.workeritem, role=self.role) self.opportunity, self.opp_event = self.add_opportunity(opportunity) self.allocation = ResourceAllocationFactory(resource=self.worker, event=self.opp_event)
def __init__(self, performer=None, act=None, show=None, sched_event=None, conference=None, room_name=None, schedule_rehearsal=False, act_role="Regular Act", set_waitlist=False): if conference: self.show = show or ShowFactory(e_conference=conference) else: self.show = show or ShowFactory() self.conference = conference or self.show.e_conference self.performer = performer or PersonaFactory() self.act = act or ActFactory(performer=self.performer, b_conference=self.conference, accepted=3, submitted=True) role = "Performer" if set_waitlist: self.act.accepted = 2 self.act.save() act_role = "Waitlisted" role = "Waitlisted" self.tech = self.act.tech # schedule the show if sched_event: self.sched_event = sched_event else: self.sched_event = SchedEventFactory( eventitem=self.show.eventitem_ptr) EventLabelFactory(event=self.sched_event, text=self.conference.conference_slug) room_name = room_name or "Dining Room" self.room = RoomFactory(name=room_name) self.room.conferences.add(self.conference) if not sched_event: ResourceAllocationFactory( event=self.sched_event, resource=LocationFactory(_item=self.room.locationitem_ptr)) # schedule the act into the show self.booking = ResourceAllocationFactory(event=self.sched_event, resource=WorkerFactory( _item=self.act.performer, role=role)) self.order = OrderingFactory(allocation=self.booking, class_id=self.act.pk, class_name="Act", role=act_role) if schedule_rehearsal: self.rehearsal = self._schedule_rehearsal(self.sched_event, self.act)
def test_booking_is_good(self): # horrible setup process. Need to fix data = self.set_basic_opportunity() booked_sched = SchedEventFactory( eventitem=data['current_sched'].eventitem, starttime=datetime(2016, 2, 6, 9, 0, 0, 0, pytz.utc), max_volunteer=1) data['context'].book_volunteer(booked_sched, volunteer=data['volunteer'].profile) EventLabelFactory(event=booked_sched, text=data['context'].conference.conference_slug) EventLabelFactory(event=booked_sched, text="Volunteer") url = reverse(self.view_name, args=[data['volunteer'].pk], urlconf="gbe.urls") login_as(self.privileged_user, self) response = self.client.get(url) nt.assert_in(date_format(booked_sched.start_time, "SHORT_DATETIME_FORMAT"), response.content, msg="start time for booked_sched didn't show up") nt.assert_in(date_format(booked_sched.end_time, "SHORT_DATETIME_FORMAT"), response.content, msg="end time for booked_sched didn't show up") nt.assert_is_not_none(re.search( '''<td class="bid-table">\s+Y\s+</td>''', response.content), msg="The booked event should show as full") # using \ to make sure the formatting of the reg ex is correct. checked_box = '''<input id="id_events_\d"\s+name="events"\s''' + \ '''type="checkbox" value="''' + str(booked_sched.pk) + \ '''"\s+checked="checked"/>''' nt.assert_is_not_none( re.search(checked_box, response.content), msg="The booked event should appear as checked in form")
def _schedule_rehearsal(self, s_event, act=None): rehearsal = GenericEventFactory(type="Rehearsal Slot", e_conference=self.conference) rehearsal_event = SchedEventFactory( eventitem=rehearsal.eventitem_ptr, max_volunteer=10, starttime=self.sched_event.starttime) event_container = EventContainerFactory(child_event=rehearsal_event, parent_event=s_event) EventLabelFactory(event=rehearsal_event, text=self.conference.conference_slug) if act: ResourceAllocationFactory( resource=ActResourceFactory(_item=act.actitem_ptr), event=rehearsal_event) return rehearsal_event
def make_rehearsal(self, room=True): rehearsal = GenericEventFactory(e_conference=self.conference, type='Rehearsal Slot') start_time = datetime.combine(self.days[0].day, (self.sched_event.start_time - timedelta(hours=4)).time()) slot = SchedEventFactory(eventitem=rehearsal.eventitem_ptr, starttime=start_time, max_volunteer=10) if room: ResourceAllocationFactory( event=slot, resource=LocationFactory(_item=self.room)) EventContainerFactory(parent_event=self.sched_event, child_event=slot) EventLabelFactory(event=slot, text=self.conference.conference_slug) return rehearsal, slot
def test_staff_lead_button(self): show_context = ActTechInfoContext(schedule_rehearsal=True) vol_context = VolunteerContext(event=show_context.show, sched_event=show_context.sched_event) context = StaffAreaContext(conference=show_context.conference) EventLabelFactory(event=vol_context.opp_event, text=context.area.slug) vol1, opp1 = context.book_volunteer( volunteer_sched_event=vol_context.opp_event, volunteer=context.staff_lead) self.profile = context.staff_lead response = self.get_landing_page() self.assertContains(response, reverse( 'show_dashboard', urlconf='gbe.scheduling.urls', args=[show_context.sched_event.pk]))
def test_act_changestate_book_act_with_conflict(self): # accepted -> waitlist (#2, see above) # change show, change role EmailTemplateSenderFactory(from_email="*****@*****.**", template__name='act wait list', template__subject="test template") grant_privilege(self.privileged_user, 'Act Reviewers') conflict = SchedEventFactory( starttime=self.context.sched_event.starttime) EventLabelFactory(event=conflict, text=self.context.conference.conference_slug) ResourceAllocationFactory( event=conflict, resource=WorkerFactory( _item=self.context.performer.performer_profile)) login_as(self.privileged_user, self) response = self.client.post(self.url, data=self.data, follow=True) self.assertContains(response, "Conflicting booking: %s" % str(conflict)) assert_email_template_used("test template", "*****@*****.**")
def _schedule_rehearsal(self, s_event, act=None): rehearsal = GenericEventFactory(type="Rehearsal Slot", e_conference=self.conference) rehearsal_event = SchedEventFactory( eventitem=rehearsal.eventitem_ptr, max_commitments=10, starttime=self.sched_event.starttime) event_container = EventContainerFactory(child_event=rehearsal_event, parent_event=s_event) EventLabelFactory(event=rehearsal_event, text=self.conference.conference_slug) if act: booking = ResourceAllocationFactory(event=rehearsal_event, resource=WorkerFactory( _item=act.performer, role="Performer")) OrderingFactory(allocation=booking, class_id=act.pk, class_name="Act") return rehearsal_event
def setUp(self): self.client = Client() self.context = ActTechInfoContext() self.show = ShowFactory(e_conference=self.context.conference) self.sched_event = SchedEventFactory(eventitem=self.show.eventitem_ptr) EventLabelFactory(event=self.sched_event, text=self.context.conference.conference_slug) self.privileged_user = ProfileFactory().user_object grant_privilege(self.privileged_user, 'Act Coordinator') grant_privilege(self.privileged_user, 'Act Reviewers') self.data = { 'show': self.show.eventitem_id, 'casting': 'Regular Act', 'accepted': '2' } self.url = reverse(self.view_name, args=[self.context.act.pk], urlconf='gbe.urls') self.regular_casting = ActCastingOptionFactory( casting="Regular Act", show_as_special=False, display_header="Check Out these Performers", display_order=1)
def test_staff_area_role_display(self): vol_context = VolunteerContext(event=self.context.show, sched_event=self.context.sched_event) context = StaffAreaContext(conference=self.context.conference) EventLabelFactory(event=vol_context.opp_event, text=context.area.slug) vol1, opp1 = context.book_volunteer( volunteer_sched_event=vol_context.opp_event) vol2, opp2 = context.book_volunteer( volunteer_sched_event=vol_context.opp_event, role="Pending Volunteer") vol3, opp3 = context.book_volunteer( volunteer_sched_event=vol_context.opp_event, role="Waitlisted") vol4, opp4 = context.book_volunteer( volunteer_sched_event=vol_context.opp_event, role="Rejected") login_as(self.profile, self) response = self.client.get(self.url) self.assertEqual(response.status_code, 200) self.assertContains(response, str(vol1)) self.assertContains(response, str(vol2)) self.assertContains(response, str(vol3)) self.assertNotContains(response, str(vol4)) self.assertNotContains( response, reverse("approve_volunteer", urlconf='gbe.scheduling.urls', args=['approve', vol1.pk, opp1.pk])) self.assertContains( response, reverse("approve_volunteer", urlconf='gbe.scheduling.urls', args=['approve', vol2.pk, opp2.pk])) self.assertContains( response, reverse("approve_volunteer", urlconf='gbe.scheduling.urls', args=['approve', vol3.pk, opp3.pk])) self.assertContains(response, context.area.title)
def test_assign_volunteer_show_unavailable_event(self): '''test how event shows when volunteer not available''' data = self.set_basic_opportunity() unavail_sched = SchedEventFactory( eventitem=data['current_sched'].eventitem, starttime=datetime(2016, 2, 7, 12, 0, 0, 0, pytz.utc), max_volunteer=10) EventLabelFactory(event=unavail_sched, text=data['context'].conference.conference_slug) EventLabelFactory(event=unavail_sched, text="Volunteer") unavail_window = VolunteerWindowFactory( day__conference=data['context'].conference, day__day=date(2016, 2, 7), start=time(11), end=time(15)) volunteer = VolunteerFactory(b_conference=data['context'].conference, submitted=True) VolunteerInterestFactory(volunteer=data['volunteer']) data['volunteer'].unavailable_windows.add(unavail_window) data['volunteer'].save() url = reverse(self.view_name, args=[data['volunteer'].pk], urlconf="gbe.urls") login_as(self.privileged_user, self) response = self.client.get(url) nt.assert_equal(response.status_code, 200) nt.assert_true('Assign Volunteer to Opportunities' in response.content) # event names nt.assert_equal( response.content.count(str(data['current_sched'].eventitem)), 2, msg="There should be 2 schedule items for current_sched.eventitem") nt.assert_in(date_format(unavail_sched.start_time, "SHORT_DATETIME_FORMAT"), response.content, msg="start time for unavail_sched didn't show up") nt.assert_in(date_format(unavail_sched.end_time, "TIME_FORMAT"), response.content, msg="end time for unavail_sched didn't show up") nt.assert_is_not_none( re.search( date_format(unavail_sched.start_time, "SHORT_DATETIME_FORMAT"), response.content), msg="unavail_window shows with unavail_sched is not found") nt.assert_equal( response.content.count('''<td class="bid-table">10</td>'''), 2, msg="unavail_sched and current_sched should have 10 volunteers") nt.assert_true( "Not Free<br>" in response.content, msg="The volunteer should be not free for unavail_sched event") nt.assert_is_not_none( re.search('''<td class="bid-table">\s+N\s+</td>''', response.content), msg="The unavailable event should be not yet full")