class TestInterest(TestCase):
    view_name = "interest"

    def setUp(self):
        self.client = Client()
        self.priv_profile = ProfileFactory()
        self.context = ClassContext()
        self.old_conference = ConferenceFactory(status="completed")
        self.old_context = ClassContext(conference=self.old_conference)
        grant_privilege(self.priv_profile, 'Class Coordinator')
        self.url = reverse(self.view_name, urlconf="gbe.reporting.urls")

    def test_interest_not_visible_without_permission(self):
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 403)

    def test_default_conf_success(self):
        login_as(self.priv_profile, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, self.context.bid.e_title)
        self.assertNotContains(response, self.old_context.bid.e_title)
        self.assertContains(response, self.context.teacher.name)
        self.assertNotContains(response, self.old_context.teacher.name)
        self.assertContains(response, self.context.room.name)
        self.assertNotContains(response, self.old_context.room.name)

    def test_interest_is_present(self):
        interested = []
        for i in range(0, 3):
            interested += [self.context.set_interest()]
        login_as(self.priv_profile, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        for person in interested:
            self.assertContains(
                response, "%s <%s>;" %
                (person.display_name, person.user_object.email))

    def test_interest_old_conf(self):
        interested = []
        for i in range(0, 3):
            interested += [self.old_context.set_interest()]
        login_as(self.priv_profile, self)
        response = self.client.get(
            self.url,
            data={'conf_slug': self.old_context.conference.conference_slug})
        self.assertEqual(response.status_code, 200)
        for person in interested:
            self.assertContains(
                response, "%s <%s>;" %
                (person.display_name, person.user_object.email))

    def test_info_is_present(self):
        interested = []
        login_as(self.priv_profile, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, interested_report_explain_msg)
 def test_room_setup_by_conference_with_permission(self):
     '''room_setup view should load for privileged users,
        and fail for others
     '''
     Conference.objects.all().delete()
     context = ClassContext()
     one_day = timedelta(1)
     ConferenceDayFactory(conference=context.conference,
                          day=context.sched_event.starttime.date())
     ConferenceDayFactory(conference=context.conference,
                          day=context.sched_event.starttime.date() +
                          one_day)
     context.schedule_instance(starttime=context.sched_event.starttime +
                               one_day)
     current_conference = context.conference
     ConferenceDayFactory(conference=context.conference,
                          day=context.sched_event.starttime.date())
     current_conference = ConferenceFactory()
     grant_privilege(self.profile, 'Act Reviewers')
     login_as(self.profile, self)
     response = self.client.get(
         reverse('room_setup', urlconf='gbe.reporting.urls'),
         data={'conf_slug': context.conference.conference_slug})
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, context.bid.e_title, 2)
    def test_ticket_purchase(self):
        '''a ticket purchaser gets a checklist item
        '''
        transaction = TransactionFactory()
        purchaser = ProfileFactory(
            user_object=transaction.purchaser.matched_to_user)
        conference = transaction.ticket_item.bpt_event.conference
        ticket_condition = TicketingEligibilityConditionFactory(
            tickets=[transaction.ticket_item]
        )
        context = ClassContext(
            conference=transaction.ticket_item.bpt_event.conference)
        context.set_interest(interested_profile=purchaser)

        request = self.factory.get(
            'reports/schedule_all?conf_slug='+conference.conference_slug)
        login_as(self.priv_profile, self)
        response = self.client.get(
            self.url,
            data={"conf_slug": conference.conference_slug})
        self.assertEqual(response.status_code, 200)
        nt.assert_true(
            str(purchaser) in response.content,
            msg="Buyer is not in the list")
        nt.assert_true(
            str(ticket_condition.checklistitem) in response.content)
 def setUp(self):
     self.client = Client()
     self.priv_profile = ProfileFactory()
     self.context = ClassContext()
     self.old_conference = ConferenceFactory(status="completed")
     self.old_context = ClassContext(conference=self.old_conference)
     grant_privilege(self.priv_profile, 'Class Coordinator')
     self.url = reverse(self.view_name, urlconf="gbe.reporting.urls")
Beispiel #5
0
 def setUp(self):
     self.client = Client()
     self.priv_profile = ProfileFactory()
     self.context = ClassContext()
     self.old_conference = ConferenceFactory(status="completed")
     self.old_context = ClassContext(conference=self.old_conference)
     grant_privilege(self.priv_profile, 'Class Coordinator')
     self.url = reverse(self.view_name,
                        urlconf="gbe.reporting.urls")
 def test_no_eval_for_teacher(self):
     context = ClassContext(starttime=datetime.now() - timedelta(days=1))
     context.setup_eval()
     login_as(context.teacher.contact, self)
     url = reverse(self.view_name,
                   urlconf="gbe.scheduling.urls",
                   args=[context.bid.eventitem_id])
     response = self.client.get(url)
     self.assertNotContains(response, "fa-tachometer")
 def test_eval_future(self):
     context = ClassContext(conference=self.conf,
                            starttime=datetime.now() + timedelta(days=1))
     context.setup_eval()
     url = reverse("event_list",
                   urlconf="gbe.scheduling.urls",
                   args=['Class'])
     response = self.client.get(url)
     self.assertNotContains(response, "fa-tachometer")
Beispiel #8
0
 def setUp(self):
     Conference.objects.all().delete()
     self.client = Client()
     self.privileged_user = User.objects.create_superuser(
         'myuser', '*****@*****.**', "mypassword")
     self.privileged_profile = ProfileFactory(
         user_object=self.privileged_user)
     grant_privilege(self.privileged_profile.user_object, "Schedule Mavens")
     self.context = ClassContext()
     self.url = reverse(self.view_name, urlconf="gbe.email.urls")
Beispiel #9
0
 def test_bios_teachers_no_conf_slug(self):
     current_context = ClassContext(conference=current_conference())
     other_conference = ConferenceFactory(status="ended")
     other_context = ClassContext(conference=other_conference)
     url = reverse(self.view_name, urlconf="gbe.urls")
     login_as(ProfileFactory(), self)
     response = self.client.get(url)
     assert response.status_code == 200
     assert current_context.teacher.name in response.content
     assert current_context.bid.b_title in response.content
Beispiel #10
0
 def test_bios_teachers_specific_conference(self):
     first_context = ClassContext()
     other_context = ClassContext()
     url = reverse(self.view_name, urlconf="gbe.urls")
     login_as(ProfileFactory(), self)
     response = self.client.get(
         url, data={'conference': first_context.conference.conference_slug})
     assert response.status_code == 200
     assert first_context.bid.teacher.name in response.content
     assert first_context.bid.b_title in response.content
 def setUp(self):
     self.client = Client()
     self.user = ProfileFactory.create().user_object
     self.privileged_profile = ProfileFactory()
     self.privileged_user = self.privileged_profile.user_object
     grant_privilege(self.privileged_user, 'Scheduling Mavens')
     Conference.objects.all().delete()
     self.context = ClassContext()
     self.url = reverse(self.view_name,
                        urlconf="gbe.scheduling.urls",
                        args=[self.context.sched_event.pk])
 def setUp(self):
     self.client = Client()
     Conference.objects.all().delete()
     self.conference = ConferenceFactory()
     self.user = ProfileFactory.create().user_object
     self.privileged_profile = ProfileFactory()
     self.privileged_user = self.privileged_profile.user_object
     grant_privilege(self.privileged_user, 'Scheduling Mavens')
     self.url = reverse(self.view_name, urlconf="scheduler.urls")
     self.showcontext = ShowContext(conference=self.conference)
     self.classcontext = ClassContext(conference=self.conference)
Beispiel #13
0
 def test_interest(self):
     '''Basic test of landing_page view
     '''
     context = ClassContext(conference=self.current_conf)
     context.set_interest(self.profile)
     url = reverse('home', urlconf='gbe.urls')
     login_as(self.profile, self)
     response = self.client.get(url)
     set_fav_link = reverse("set_favorite",
                            args=[context.sched_event.pk, "off"],
                            urlconf="gbe.scheduling.urls")
     self.assertContains(response, "%s?next=%s" % (set_fav_link, url))
Beispiel #14
0
 def setUp(self):
     self.client = Client()
     self.context = ClassContext(starttime=datetime.now()-timedelta(days=1))
     self.q0 = self.context.setup_eval()
     self.profile = ProfileFactory()
     make_admission_purchase(self.context.conference,
                             self.profile.user_object,
                             include_most=True,
                             include_conference=True)
     self.url = reverse(
         self.view_name,
         urlconf="gbe.scheduling.urls",
         args=[self.context.sched_event.pk])
 def test_eval_class(self):
     context = ClassContext(starttime=datetime.now() - timedelta(days=1))
     context.setup_eval()
     url = reverse(self.view_name,
                   urlconf="gbe.scheduling.urls",
                   args=[context.bid.eventitem_id])
     response = self.client.get(url)
     eval_link = reverse("eval_event",
                         args=[
                             context.sched_event.pk,
                         ],
                         urlconf="gbe.scheduling.urls")
     self.assertContains(response, "%s?next=%s" % (eval_link, url))
 def test_eval_ready(self):
     context = ClassContext(conference=self.conf,
                            starttime=datetime.now() - timedelta(days=1))
     context.setup_eval()
     url = reverse("event_list",
                   urlconf="gbe.scheduling.urls",
                   args=['Class'])
     response = self.client.get(url)
     eval_link = reverse("eval_event",
                         args=[
                             context.sched_event.pk,
                         ],
                         urlconf="gbe.scheduling.urls")
     self.assertContains(response, "%s?next=%s" % (eval_link, url))
 def test_class_already_evaled(self):
     context = ClassContext(starttime=datetime.now() - timedelta(days=1))
     eval_profile = context.set_eval_answerer()
     login_as(eval_profile, self)
     url = reverse(self.view_name,
                   urlconf="gbe.scheduling.urls",
                   args=[context.bid.eventitem_id])
     response = self.client.get(url)
     eval_link = reverse("eval_event",
                         args=[
                             context.sched_event.pk,
                         ],
                         urlconf="gbe.scheduling.urls")
     self.assertNotContains(response, "%s?next=%s" % (eval_link, url))
     self.assertContains(response, "You have already rated this class")
 def test_disabled_eval(self):
     context = ClassContext(conference=self.conf,
                            starttime=datetime.now() - timedelta(days=1))
     eval_profile = context.set_eval_answerer()
     url = reverse("event_list",
                   urlconf="gbe.scheduling.urls",
                   args=['Class'])
     login_as(eval_profile, self)
     response = self.client.get(url)
     eval_link = reverse("eval_event",
                         args=[
                             context.sched_event.pk,
                         ],
                         urlconf="gbe.scheduling.urls")
     self.assertNotContains(response, "%s?next=%s" % (eval_link, url))
     self.assertContains(response, "You have already rated this class")
 def test_approval_w_conflict_start_before(self):
     self.context.worker.role = "Pending Volunteer"
     self.context.worker.save()
     class_context = ClassContext(
         conference=self.context.conference,
         teacher=PersonaFactory(performer_profile=self.context.profile),
         starttime=self.context.opp_event.starttime - timedelta(minutes=30))
     self.context.worker.role = "Pending Volunteer"
     self.context.worker.save()
     login_as(self.privileged_user, self)
     approve_url = reverse(self.approve_name,
                           urlconf='gbe.scheduling.urls',
                           args=[
                               "approve", self.context.profile.pk,
                               self.context.allocation.pk
                           ])
     response = self.client.get(approve_url)
     self.assertNotContains(response, approve_url)
     alert_msg = set_volunteer_role_msg % "Volunteer"
     full_msg = '%s Person: %s<br/>Event: %s, Start Time: %s' % (
         alert_msg, str(self.context.profile), str(self.context.opp_event),
         self.context.opp_event.starttime.strftime(GBE_DATETIME_FORMAT))
     conflict_msg = 'Conflicting booking: %s, Start Time: %s' % (
         class_context.bid.e_title,
         class_context.sched_event.starttime.strftime(GBE_DATETIME_FORMAT))
     self.assertContains(response, conflict_msg)
 def test_parent_event(self):
     vol_context = VolunteerContext(conference=self.context.conference)
     lead = vol_context.set_staff_lead()
     class_context = ClassContext(
         conference=self.context.conference,
         teacher=PersonaFactory(performer_profile=self.profile),
         starttime=vol_context.opp_event.starttime)
     url = reverse(self.view_name,
                   args=[vol_context.opp_event.pk, "on"],
                   urlconf="gbe.scheduling.urls")
     login_as(self.profile, self)
     response = self.client.get(url, follow=True)
     staff_msg = assert_email_template_used("Volunteer Schedule Change",
                                            outbox_size=2,
                                            message_index=1)
     assert (vol_context.opportunity.e_title in staff_msg.body)
     conflict_msg = 'Conflicting booking: %s, Start Time: %s' % (
         class_context.bid.e_title,
         class_context.sched_event.starttime.strftime(GBE_DATETIME_FORMAT))
     assert (class_context.bid.e_title in staff_msg.body)
     assert_email_recipient([lead.user_object.email],
                            outbox_size=2,
                            message_index=1)
     self.assertContains(response, conflict_msg)
     assert (conflict_msg in staff_msg.body)
Beispiel #21
0
 def test_interest(self):
     '''Basic test of landing_page view
     '''
     context = ClassContext(
         conference=self.current_conf)
     context.set_interest(self.profile)
     url = reverse('home', urlconf='gbe.urls')
     login_as(self.profile, self)
     response = self.client.get(url)
     set_fav_link = reverse(
         "set_favorite",
         args=[context.sched_event.pk, "off"],
         urlconf="gbe.scheduling.urls")
     self.assertContains(response, "%s?next=%s" % (
         set_fav_link,
         url))
Beispiel #22
0
 def setUp(self):
     self.client = Client()
     self.profile = ProfileFactory()
     self.context = ClassContext()
     self.url = reverse(self.view_name,
                        args=[self.context.sched_event.pk, "on"],
                        urlconf="gbe.scheduling.urls")
 def test_volunteer_conflict(self):
     self.privileged_profile = ProfileFactory()
     self.privileged_user = self.privileged_profile.user_object
     grant_privilege(self.privileged_user, 'Volunteer Coordinator')
     class_context = ClassContext(
         conference=self.context.conference,
         teacher=PersonaFactory(performer_profile=self.profile),
         starttime=self.volunteeropp.starttime)
     login_as(self.profile, self)
     response = self.client.get(self.url, follow=True)
     redirect_url = reverse('home', urlconf="gbe.urls")
     msg = assert_email_template_used(
         "A change has been made to your Volunteer Schedule!",
         outbox_size=2)
     assert ("http://%s%s" % (Site.objects.get_current().domain,
                              reverse('home', urlconf='gbe.urls'))
             in msg.body)
     assert_email_recipient([self.profile.user_object.email], outbox_size=2)
     staff_msg = assert_email_template_used("Volunteer Schedule Change",
                                            outbox_size=2,
                                            message_index=1)
     assert (self.volunteeropp.eventitem.e_title in staff_msg.body)
     conflict_msg = 'Conflicting booking: %s, Start Time: %s' % (
         class_context.bid.e_title,
         class_context.sched_event.starttime.strftime(GBE_DATETIME_FORMAT))
     assert (class_context.bid.e_title in staff_msg.body)
     assert_email_recipient([
         self.privileged_user.email,
         self.context.staff_lead.profile.user_object.email
     ],
                            outbox_size=2,
                            message_index=1)
     self.assertContains(response, conflict_msg)
     assert (conflict_msg in staff_msg.body)
Beispiel #24
0
 def test_historical_no_interest(self):
     context = ClassContext(
         conference=self.previous_conf,
         teacher=PersonaFactory(performer_profile=self.profile))
     interested = []
     for i in range(0, 3):
         interested += [context.set_interest()]
     url = reverse('home', urlconf='gbe.urls')
     login_as(self.profile, self)
     response = self.client.get(url, data={'historical': 1})
     content = response.content
     for person in interested:
         self.assertNotContains(
             response, "%s &lt;%s&gt;;</br>" %
             (person.display_name, person.user_object.email))
     self.assertNotContains(response, interested_explain_msg)
Beispiel #25
0
 def test_teacher_interest(self):
     '''Basic test of landing_page view
     '''
     context = ClassContext(
         conference=self.current_conf,
         teacher=PersonaFactory(performer_profile=self.profile))
     interested = []
     for i in range(0, 3):
         interested += [context.set_interest()]
     url = reverse('home', urlconf='gbe.urls')
     login_as(self.profile, self)
     response = self.client.get(url)
     for person in interested:
         self.assertContains(
             response, "%s &lt;%s&gt;;" %
             (person.display_name, person.user_object.email))
     self.assertContains(response, interested_explain_msg)
Beispiel #26
0
 def test_get_teacher_w_label(self):
     context = ClassContext()
     booking = ResourceAllocation.objects.get(
         event=context.sched_event, resource__worker__role='Teacher')
     label = LabelFactory(allocation=booking)
     response = get_schedule(
         user=context.teacher.performer_profile.user_object)
     self.assertEqual(response.schedule_items[0].label.text, label.text)
 def test_class_changestate_clear_schedule(self):
     '''The proper coordinator is changing the state, it works'''
     context = ClassContext()
     url = reverse(self.view_name,
                   args=[context.bid.pk],
                   urlconf='gbe.urls')
     login_as(self.privileged_user, self)
     response = self.client.post(url, data={'accepted': '1'})
     assert not context.bid.scheduler_events.exists()
Beispiel #28
0
 def setUp(self):
     self.client = Client()
     self.privileged_user = ProfileFactory.create().user_object
     grant_privilege(self.privileged_user, 'Registrar', 'view_transaction')
     self.url = reverse(self.view_name, urlconf='ticketing.urls')
     self.class_context = ClassContext()
     self.ticket_context = PurchasedTicketContext(
         profile=self.class_context.teacher.performer_profile,
         conference=self.class_context.conference)
Beispiel #29
0
 def test_eval_ready(self):
     '''Basic test of landing_page view
     '''
     context = ClassContext(
         conference=self.current_conf,
         starttime=datetime.now()-timedelta(days=1))
     context.set_interest(self.profile)
     context.setup_eval()
     url = reverse('home', urlconf='gbe.urls')
     login_as(self.profile, self)
     response = self.client.get(url)
     eval_link = reverse(
         "eval_event",
         args=[context.sched_event.pk, ],
         urlconf="gbe.scheduling.urls")
     self.assertContains(response, "%s?next=%s" % (
         eval_link,
         url))
Beispiel #30
0
 def setUp(self):
     self.client = Client()
     clear_conferences()
     conference = ConferenceFactory()
     save_the_date = datetime(2016, 02, 06, 12, 00, 00)
     day = ConferenceDayFactory(conference=conference,
                                day=date(2016, 02, 06))
     self.staffcontext = StaffAreaContext(conference=conference,
                                          starttime=save_the_date)
     self.showcontext = ShowContext(conference=conference,
                                    starttime=save_the_date)
     self.other_conference = ConferenceFactory(status='completed')
     self.other_conf_day = ConferenceDayFactory(
         conference=self.other_conference, day=date(2015, 02, 06))
     self.other_show = ShowContext(conference=self.other_conference)
     self.classcontext = ClassContext(conference=conference,
                                      starttime=save_the_date)
     self.volunteeropp = self.staffcontext.add_volunteer_opp()
Beispiel #31
0
 def test_teacher_interest(self):
     '''Basic test of landing_page view
     '''
     context = ClassContext(
         conference=self.current_conf,
         teacher=PersonaFactory(performer_profile=self.profile))
     interested = []
     for i in range(0, 3):
         interested += [context.set_interest()]
     url = reverse('home', urlconf='gbe.urls')
     login_as(self.profile, self)
     response = self.client.get(url)
     for person in interested:
         self.assertContains(
             response,
             "%s &lt;%s&gt;;" % (person.display_name,
                                 person.user_object.email))
     self.assertContains(response,
                         interested_explain_msg)
 def test_disabled_interest(self):
     context = ClassContext(conference=self.conf,
                            starttime=datetime.now() - timedelta(days=1))
     url = reverse("event_list",
                   urlconf="gbe.scheduling.urls",
                   args=['Class'])
     login_as(context.teacher.performer_profile, self)
     response = self.client.get(url)
     self.assertContains(
         response, '<a href="#" class="cal-favorite detail_link-disabled')
     self.assertNotContains(response, "fa-tachometer")
Beispiel #33
0
 def test_historical_no_interest(self):
     context = ClassContext(
         conference=self.previous_conf,
         teacher=PersonaFactory(performer_profile=self.profile))
     interested = []
     for i in range(0, 3):
         interested += [context.set_interest()]
     url = reverse('home', urlconf='gbe.urls')
     login_as(self.profile, self)
     response = self.client.get(
         url,
         data={'historical': 1})
     content = response.content
     for person in interested:
         self.assertNotContains(
             response,
             "%s &lt;%s&gt;;</br>" % (person.display_name,
                                      person.user_object.email))
     self.assertNotContains(response,
                            interested_explain_msg)
 def test_booked_teacher_over_bid_teacher(self):
     context = ClassContext(conference=self.conf,
                            starttime=datetime.now() - timedelta(days=1))
     context.bid.teacher = PersonaFactory()
     url = reverse("event_list",
                   urlconf="gbe.scheduling.urls",
                   args=['Class'])
     login_as(context.teacher.performer_profile, self)
     response = self.client.get(url)
     self.assertContains(response, str(context.teacher.performer))
     self.assertNotContains(response, str(context.bid.teacher.performer))
Beispiel #35
0
    def test_pick_everyone(self):
        second_context = ClassContext()
        ProfilePreferencesFactory(profile=second_context.teacher.contact)

        login_as(self.privileged_profile, self)
        data = {
            'everyone': "Everyone",
        }
        response = self.client.post(self.url, data=data, follow=True)
        for user in User.objects.exclude(username="******"):
            self.assertContains(response, user.email)
 def setUp(self):
     self.client = Client()
     Conference.objects.all().delete()
     self.conference = ConferenceFactory()
     self.user = ProfileFactory.create().user_object
     self.privileged_profile = ProfileFactory()
     self.privileged_user = self.privileged_profile.user_object
     grant_privilege(self.privileged_user, 'Scheduling Mavens')
     self.url = reverse(self.view_name,
                        urlconf="scheduler.urls")
     self.showcontext = ShowContext(conference=self.conference)
     self.classcontext = ClassContext(conference=self.conference)
Beispiel #37
0
 def setUp(self):
     Conference.objects.all().delete()
     self.client = Client()
     self.privileged_user = User.objects.create_superuser(
         'myuser', '*****@*****.**', "mypassword")
     self.privileged_profile = ProfileFactory(
         user_object=self.privileged_user)
     grant_privilege(self.privileged_profile.user_object,
                     "Schedule Mavens")
     self.context = ClassContext()
     self.url = reverse(self.view_name,
                        urlconf="gbe.email.urls")
Beispiel #38
0
 def test_authorized_user_get_class(self):
     copy_class = ClassFactory()
     vol_context = VolunteerContext(event=copy_class)
     target_context = ClassContext()
     url = reverse(
         self.view_name,
         args=[vol_context.sched_event.pk],
         urlconf='gbe.scheduling.urls')
     login_as(self.privileged_user, self)
     response = self.client.get(url)
     #  copying ONLY volunteer events is OK, but copying the class is not
     self.assertEqual(403, response.status_code)
Beispiel #39
0
class TestInterest(TestCase):
    view_name = "interest"

    def setUp(self):
        self.client = Client()
        self.priv_profile = ProfileFactory()
        self.context = ClassContext()
        self.old_conference = ConferenceFactory(status="completed")
        self.old_context = ClassContext(conference=self.old_conference)
        grant_privilege(self.priv_profile, 'Class Coordinator')
        self.url = reverse(self.view_name,
                           urlconf="gbe.reporting.urls")

    def test_interest_not_visible_without_permission(self):
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 403)

    def test_default_conf_success(self):
        login_as(self.priv_profile, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, self.context.bid.e_title)
        self.assertNotContains(response, self.old_context.bid.e_title)
        self.assertContains(response, self.context.teacher.name)
        self.assertNotContains(response, self.old_context.teacher.name)
        self.assertContains(response, self.context.room.name)
        self.assertNotContains(response, self.old_context.room.name)

    def test_interest_is_present(self):
        interested = []
        for i in range(0, 3):
            interested += [self.context.set_interest()]
        login_as(self.priv_profile, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        for person in interested:
            self.assertContains(
                response,
                "%s &lt;%s&gt;;" % (person.display_name,
                                    person.user_object.email))

    def test_interest_old_conf(self):
        interested = []
        for i in range(0, 3):
            interested += [self.old_context.set_interest()]
        login_as(self.priv_profile, self)
        response = self.client.get(
            self.url,
            data={'conf_slug': self.old_context.conference.conference_slug})
        self.assertEqual(response.status_code, 200)
        for person in interested:
            self.assertContains(
                response,
                "%s &lt;%s&gt;;" % (person.display_name,
                                    person.user_object.email))

    def test_info_is_present(self):
        interested = []
        login_as(self.priv_profile, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response,
                            interested_report_explain_msg)
class TestEvalEventView(TestCase):
    view_name = 'eval_event'

    def setUp(self):
        self.client = Client()
        self.context = ClassContext(starttime=datetime.now()-timedelta(days=1))
        self.q0 = self.context.setup_eval()
        self.profile = ProfileFactory()
        make_admission_purchase(self.context.conference,
                                self.profile.user_object,
                                include_most=True,
                                include_conference=True)
        self.url = reverse(
            self.view_name,
            urlconf="gbe.scheduling.urls",
            args=[self.context.sched_event.pk])

    def test_no_login_gives_error(self):
        response = self.client.get(self.url, follow=True)
        redirect_url = reverse('register',
                               urlconf='gbe.urls') + "?next=" + self.url
        self.assertRedirects(response, redirect_url)
        self.assertContains(response, "Create an Account")
        assert_alert_exists(
            response,
            'warning',
            'Warning',
            full_login_msg % (no_login_msg, reverse(
                'login',
                urlconf='gbe.urls') + "?next=" + self.url))

    def test_get_unfinished_user(self):
        unfinished = UserFactory()
        login_as(unfinished, self)
        response = self.client.get(self.url, follow=True)
        redirect_url = reverse('register',
                               urlconf='gbe.urls') + "?next=" + self.url
        self.assertRedirects(response, redirect_url)
        self.assertContains(response, "Create an Account")
        assert_alert_exists(
            response,
            'warning',
            'Warning',
            no_profile_msg)

    def test_post_unfinished_user(self):
        unfinished = UserFactory()
        login_as(unfinished, self)
        response = self.client.post(self.url, follow=True)
        redirect_url = reverse('register',
                               urlconf='gbe.urls') + "?next=" + self.url
        self.assertRedirects(response, redirect_url)
        self.assertContains(response, "Create an Account")
        assert_alert_exists(
            response,
            'warning',
            'Warning',
            no_profile_msg)

    def test_get_eval(self):
        q1 = EventEvalQuestionFactory(answer_type="grade")
        q2 = EventEvalQuestionFactory(answer_type="text",
                                      help_text="so helpful")
        q3 = EventEvalQuestionFactory(answer_type="boolean")
        q4 = EventEvalQuestionFactory(visible=False,
                                      help_text="unhelpful")
        login_as(self.profile, self)
        response = self.client.get(self.url, follow=True)
        self.assertContains(response, self.context.bid.e_title)
        self.assertContains(response, self.context.teacher)
        self.assertContains(response, q1.question)
        self.assertContains(response, q2.question)
        self.assertContains(response, q2.help_text)
        self.assertContains(response, q3.question)
        self.assertNotContains(response, q4.question)
        self.assertNotContains(response, q4.help_text)
        n = 0
        grade_input = '<input id="id_question%d_%d" name="question%d" ' + \
                      'type="radio" value="%s" />'
        answer_textarea = '<textarea cols="40" id="id_question%d" ' + \
                          'name="question%d" rows="10">'
        boolean_checkbox = '<input id="id_question%d" name="question%d" ' + \
                           'type="checkbox" />'
        for grade in new_grade_options:
            self.assertContains(
                response,
                grade_input % (q1.pk, n, q1.pk, grade[0]))
            n = n + 1
        self.assertContains(
            response,
            answer_textarea % (q2.pk, q2.pk))
        self.assertContains(
            response,
            boolean_checkbox % (q3.pk, q3.pk))

    def test_get_eval_own_class(self):
        q1 = EventEvalQuestionFactory(answer_type="grade")
        q2 = EventEvalQuestionFactory(answer_type="text",
                                      help_text="so helpful")
        q3 = EventEvalQuestionFactory(answer_type="boolean")
        q4 = EventEvalQuestionFactory(visible=False,
                                      help_text="unhelpful")
        login_as(self.context.teacher.contact, self)
        response = self.client.get(self.url, follow=True)
        assert_alert_exists(
            response,
            'danger',
            'Error',
            eval_as_presenter_error)

    def test_get_no_purchase(self):
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url, follow=True)
        assert_alert_exists(
            response,
            'danger',
            'Error',
            not_purchased_msg)
        self.assertRedirects(response, reverse('home', urlconf='gbe.urls'))

    def test_post_no_purchase(self):
        login_as(ProfileFactory(), self)
        response = self.client.post(self.url, follow=True)
        assert_alert_exists(
            response,
            'danger',
            'Error',
            not_purchased_msg)

    def test_bad_occurrence_id(self):
        login_as(self.profile, self)
        url = reverse(
            self.view_name,
            urlconf="gbe.scheduling.urls",
            args=[self.context.sched_event.pk + 1000])
        response = self.client.get(url, follow=True)
        assert_alert_exists(
            response,
            'danger',
            'Error',
            "An error has occurred.  Occurrence id %d not found" % (
                self.context.sched_event.pk + 1000))

    def test_get_future_class(self):
        login_as(self.profile, self)
        future_context = ClassContext(
            starttime=datetime.now()+timedelta(days=1),
            conference=self.context.conference)
        url = reverse(
            self.view_name,
            urlconf="gbe.scheduling.urls",
            args=[future_context.sched_event.pk])
        response = self.client.get(url, follow=True)
        assert_alert_exists(
            response,
            'warning',
            'Warning',
            "The event hasn't occurred yet, and can't be rated.")

    def test_post_future_class(self):
        login_as(self.profile, self)
        future_context = ClassContext(
            starttime=datetime.now()+timedelta(days=1),
            conference=self.context.conference)
        url = reverse(
            self.view_name,
            urlconf="gbe.scheduling.urls",
            args=[future_context.sched_event.pk])
        response = self.client.post(url,
                                    data={'question%d' % self.q0.pk: "C", },
                                    follow=True)
        assert_alert_exists(
            response,
            'warning',
            'Warning',
            "The event hasn't occurred yet, and can't be rated.")

    def test_no_questions(self):
        EventEvalQuestion.objects.all().delete()
        login_as(self.profile, self)
        response = self.client.get(self.url, follow=True)
        assert_alert_exists(
            response,
            'warning',
            'Warning',
            not_ready_for_eval)

    def test_already_answered(self):
        self.context.set_eval_answerer(self.profile)
        login_as(self.profile, self)
        response = self.client.get(self.url, follow=True)
        assert_alert_exists(
            response,
            'warning',
            'Warning',
            one_eval_msg)

    def test_set_eval(self):
        q1 = EventEvalQuestionFactory(answer_type="grade")
        q2 = EventEvalQuestionFactory(answer_type="text")
        q3 = EventEvalQuestionFactory(answer_type="boolean")

        login_as(self.profile, self)
        response = self.client.post(
            self.url,
            data={
                'question%d' % self.q0.pk: "A",
                'question%d' % q1.pk: "B",
                'question%d' % q2.pk: "This is Test Text.",
                'question%d' % q3.pk: True,
                },
            follow=True)
        assert_alert_exists(
            response,
            'info',
            'Info',
            eval_success_msg)
        self.assertEqual(
            2,
            EventEvalGrade.objects.filter(
                event=self.context.sched_event).count())
        self.assertEqual(
            1,
            EventEvalComment.objects.filter(
                event=self.context.sched_event).count())
        self.assertEqual(
            1,
            EventEvalBoolean.objects.filter(
                event=self.context.sched_event).count())
        self.assertRedirects(response, reverse('home', urlconf='gbe.urls'))

    def test_invalid_eval(self):
        login_as(self.profile, self)
        response = self.client.post(
            self.url,
            data={'question%d' % self.q0.pk: "invalid", },
            follow=True)
        self.assertContains(
            response,
            'Select a valid choice. invalid is not one of the available ' +
            'choices.')

    def test_set_eval(self):
        login_as(self.profile, self)
        redirect = reverse(
            "detail_view",
            urlconf="gbe.scheduling.urls",
            args=[self.context.bid.eventitem_id])
        response = self.client.post(
            "%s?next=%s" % (self.url, redirect),
            data={'question%d' % self.q0.pk: 2, },
            follow=True)
        assert_alert_exists(
            response,
            'info',
            'Info',
            eval_success_msg)
        self.assertRedirects(response, redirect)
class TestExportCalendar(TestCase):
    view_name = 'export_calendar'

    def setUp(self):
        self.client = Client()
        Conference.objects.all().delete()
        self.conference = ConferenceFactory()
        self.user = ProfileFactory.create().user_object
        self.privileged_profile = ProfileFactory()
        self.privileged_user = self.privileged_profile.user_object
        grant_privilege(self.privileged_user, 'Scheduling Mavens')
        self.url = reverse(self.view_name,
                           urlconf="scheduler.urls")
        self.showcontext = ShowContext(conference=self.conference)
        self.classcontext = ClassContext(conference=self.conference)

    def make_three_day_spread(self):
        conference_events = [self.showcontext.sched_event,
                             self.classcontext.sched_event]
        two_day = timedelta(2)

        ConferenceDayFactory(conference=self.conference,
                             day=date(2016, 2, 6))
        ConferenceDayFactory(conference=self.conference,
                             day=date(2016, 2, 7))
        conference_events += [self.showcontext.schedule_instance()]
        conference_events += [self.showcontext.schedule_instance(
            starttime=self.showcontext.sched_event.starttime+two_day)]
        conference_events += [self.classcontext.schedule_instance()]
        conference_events += [self.classcontext.schedule_instance(
            starttime=self.classcontext.sched_event.starttime+two_day)]
        return conference_events

    def test_no_login(self):
        response = self.client.get(self.url, follow=True)
        redirect_url = reverse(
            'login',
            urlconf='gbe.urls') + "/?next=" + self.url
        self.assertRedirects(response, redirect_url)
        self.assertTrue(is_login_page(response))

    def test_no_schedule(self):
        Conference.objects.all().delete()
        show = ShowFactory()
        SchedEventFactory.create(eventitem=show.eventitem_ptr)
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url)
        self.assertTrue(response.content.count('\n') == 1)
        self.assertTrue('Session Title' in response.content)

    def test_schedule(self):
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url)
        self.assertTrue(response.content.count('\n') > 1)
        self.assertTrue(len(
            (response.content.split('\r\n')[1].split('","'))) >= 8)
        self.assertIn(self.showcontext.show.e_title, response.content)

    def test_guidebook(self):
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url)
        self.assertIn(self.showcontext.show.e_title, response.content)
        self.assertIn(self.classcontext.bid.b_title, response.content)

    def test_ical(self):
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url + '?cal_format=ical')
        self.assertTrue('BEGIN:VCALENDAR' in
                        response.content.split('\r\n')[0])
        vevent_count = 0
        for line in response.content.split('\r\n'):
            if 'BEGIN:VEVENT' in line:
                vevent_count = vevent_count + 1
        self.assertTrue(vevent_count > 0)

    def test_type_class(self):
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url + '?event_types=Class')
        self.assertNotIn(self.showcontext.show.e_title, response.content)
        self.assertIn(self.classcontext.bid.b_title, response.content)

    def test_type_show(self):
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url + '?event_types=Show')
        self.assertIn(self.showcontext.show.e_title, response.content)
        self.assertNotIn(self.classcontext.bid.b_title, response.content)

    def test_day_all(self):
        login_as(ProfileFactory(), self)
        event_set = self.make_three_day_spread()
        response = self.client.get(self.url + '?day=All')
        fri_count, sat_count, sun_count = 0, 0, 0
        for line in response.content.split('\r\n'):
            if 'Feb. 5' in line:
                fri_count = fri_count + 1
            elif 'Feb. 6' in line:
                sat_count = sat_count + 1
            elif 'Feb. 7' in line:
                sun_count = sun_count + 1
        self.assertTrue(fri_count == 2 and sat_count == 2 and sun_count == 2)

    def test_day_sat(self):
        login_as(ProfileFactory(), self)
        event_set = self.make_three_day_spread()
        response = self.client.get(self.url + '?day=Saturday')
        fri_count, sat_count, sun_count = 0, 0, 0
        for line in response.content.split('\r\n'):
            if 'Feb. 5' in line:
                fri_count = fri_count + 1
            elif 'Feb. 6' in line:
                sat_count = sat_count + 1
            elif 'Feb. 7' in line:
                sun_count = sun_count + 1
        self.assertTrue(fri_count == 0 and sat_count == 2 and sun_count == 0)
Beispiel #42
0
class TestEval(TestCase):
    view_name = "evaluation"

    def setUp(self):
        self.client = Client()
        self.priv_profile = ProfileFactory()
        self.context = ClassContext()
        self.old_conference = ConferenceFactory(status="completed")
        self.old_context = ClassContext(conference=self.old_conference)
        grant_privilege(self.priv_profile, 'Class Coordinator')
        self.url = reverse(self.view_name,
                           urlconf="gbe.reporting.urls")

    def test_not_visible_without_permission(self):
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 403)

    def test_default_conf_success(self):
        login_as(self.priv_profile, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, self.context.bid.e_title)
        self.assertNotContains(response, self.old_context.bid.e_title)
        self.assertContains(response, self.context.teacher.name)
        self.assertNotContains(response, self.old_context.teacher.name)
        self.assertContains(response, eval_report_explain_msg)

    def test_old_conf_success(self):
        login_as(self.priv_profile, self)
        response = self.client.get(
            self.url,
            data={'conf_slug': self.old_context.conference.conference_slug})
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, self.context.bid.e_title)
        self.assertContains(response, self.old_context.bid.e_title)
        self.assertNotContains(response, self.context.teacher.name)
        self.assertContains(response, self.old_context.teacher.name)

    def test_interest_no_evals(self):
        interested = []
        for i in range(0, 3):
            interested += [self.context.set_interest()]
        login_as(self.priv_profile, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<td class="bid-table">3</td>')
        self.assertContains(response, '<td class="bid-table">0</td>')
        self.assertNotContains(response, reverse(
            'evaluation_detail',
            urlconf='gbe.reporting.urls',
            args=[self.context.sched_event.id]))

    def test_summary_calculations(self):
        interested = []
        login_as(self.priv_profile, self)
        grade1 = EventEvalGradeFactory(event=self.context.sched_event,
                                       answer=4)
        grade2 = EventEvalGradeFactory(event=self.context.sched_event,
                                       answer=3,
                                       question=grade1.question)
        bool1 = EventEvalBooleanFactory(event=self.context.sched_event,
                                        answer=True,
                                        profile=grade1.profile)
        bool2 = EventEvalBooleanFactory(event=self.context.sched_event,
                                        answer=False,
                                        profile=grade2.profile,
                                        question=bool1.question)
        text1 = EventEvalCommentFactory(event=self.context.sched_event,
                                        profile=grade1.profile)
        text2 = EventEvalCommentFactory(event=self.context.sched_event,
                                        profile=grade2.profile,
                                        question=text1.question)

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<td class="bid-table">0</td>')
        self.assertContains(response, '<td class="bid-table">2</td>')
        self.assertContains(response, grade1.question.question)
        self.assertContains(response, bool1.question.question)
        self.assertNotContains(response, text1.question.question)
        self.assertContains(response, '<td class="bid-table">3.5</td>')
        self.assertContains(response, '<td class="bid-table">0.5</td>')
        self.assertContains(response, reverse(
            'evaluation_detail',
            urlconf='gbe.reporting.urls',
            args=[self.context.sched_event.id]))

    def test_details(self):
        interested = []
        login_as(self.priv_profile, self)
        grade1 = EventEvalGradeFactory(event=self.context.sched_event,
                                       answer=4)
        grade2 = EventEvalGradeFactory(event=self.context.sched_event,
                                       answer=3,
                                       question=grade1.question)
        bool1 = EventEvalBooleanFactory(event=self.context.sched_event,
                                        answer=True,
                                        profile=grade1.profile)
        bool2 = EventEvalBooleanFactory(event=self.context.sched_event,
                                        answer=False,
                                        profile=grade2.profile,
                                        question=bool1.question)
        text1 = EventEvalCommentFactory(event=self.context.sched_event,
                                        profile=grade1.profile)
        text2 = EventEvalCommentFactory(event=self.context.sched_event,
                                        profile=grade2.profile,
                                        question=text1.question)

        response = self.client.get(reverse(
            'evaluation_detail',
            urlconf='gbe.reporting.urls',
            args=[self.context.sched_event.id]))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, grade1.question.question, 5)
        self.assertContains(response, bool1.question.question, 5)
        self.assertContains(response, text1.question.question, 2)
        self.assertContains(response, grade1.profile.profile.display_name)
        self.assertContains(response, grade2.profile.profile.display_name)
        self.assertContains(response, '<td class="bid-table">4</td>')
        self.assertContains(response, '<td class="bid-table">3</td>')
        self.assertContains(response, self.context.bid.e_description)

    def test_bad_details(self):
        interested = []
        login_as(self.priv_profile, self)

        response = self.client.get(reverse(
            'evaluation_detail',
            urlconf='gbe.reporting.urls',
            args=[self.context.sched_event.id+100]))
        self.assertContains(
            response,
            "Occurrence id %d not found" % (self.context.sched_event.pk+100))
Beispiel #43
0
class TestMailToRoles(TestCase):
    view_name = 'mail_to_roles'
    role_list = ['Interested',
                 'Moderator',
                 "Panelist",
                 "Performer",
                 "Producer",
                 "Staff Lead",
                 "Teacher",
                 "Technical Director",
                 "Volunteer"]

    def setUp(self):
        Conference.objects.all().delete()
        self.client = Client()
        self.privileged_user = User.objects.create_superuser(
            'myuser', '*****@*****.**', "mypassword")
        self.privileged_profile = ProfileFactory(
            user_object=self.privileged_user)
        grant_privilege(self.privileged_profile.user_object,
                        "Schedule Mavens")
        self.context = ClassContext()
        self.url = reverse(self.view_name,
                           urlconf="gbe.email.urls")

    def class_coord_login(self):
        limited_profile = ProfileFactory()
        grant_privilege(limited_profile.user_object, "Class Coordinator")
        login_as(limited_profile, self)

    def test_no_priv(self):
        login_as(ProfileFactory(), self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 403)

    def test_full_login_first_get(self):
        login_as(self.privileged_profile, self)
        response = self.client.get(self.url, follow=True)
        assert_checkbox(
            response,
            "conference",
            0,
            self.context.conference.pk,
            self.context.conference.conference_slug)
        n = 0
        for role in role_options:
            assert_checkbox(
                response,
                "roles",
                n,
                role[0],
                role[1])
            n = n + 1
        self.assertContains(response, "Email Everyone")

    def test_reduced_login_first_get(self):
        for priv, roles in role_option_privs.iteritems():
            limited_profile = ProfileFactory()
            grant_privilege(limited_profile.user_object,
                            priv)
            login_as(limited_profile, self)

            response = self.client.get(self.url, follow=True)
            assert_checkbox(
                response,
                "conference",
                0,
                self.context.conference.pk,
                self.context.conference.conference_slug)
            n = 0
            for role in sorted(roles):
                assert_checkbox(
                    response,
                    "roles",
                    n,
                    role,
                    role)
                n = n + 1
        self.assertNotContains(response, "Email Everyone")

    def test_full_login_first_get_2_conf(self):
        extra_conf = ConferenceFactory()
        login_as(self.privileged_profile, self)
        response = self.client.get(self.url, follow=True)
        assert_checkbox(
            response,
            "conference",
            0,
            self.context.conference.pk,
            self.context.conference.conference_slug)
        assert_checkbox(
            response,
            "conference",
            1,
            extra_conf.pk,
            extra_conf.conference_slug)

    def test_pick_conf_teacher(self):
        second_context = ClassContext()
        login_as(self.privileged_profile, self)
        data = {
            'email-select-conference': [self.context.conference.pk],
            'email-select-roles': self.role_list,
            'filter': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(
            response,
            self.context.teacher.contact.user_object.email)
        self.assertNotContains(
            response,
            second_context.teacher.contact.user_object.email)

    def test_pick_class_teacher(self):
        interested = self.context.set_interest()
        self.class_coord_login()
        data = {
            'email-select-conference': [self.context.conference.pk],
            'email-select-roles': ["Teacher"],
            'filter': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(
            response,
            self.context.teacher.contact.user_object.email)
        self.assertNotContains(
            response,
            interested.user_object.email)
        print response.content
        assert_checkbox(
            response,
            "event_collections",
            0,
            "Conference",
            "All Conference Classes",
            checked=False,
            prefix="event-select")

    def test_pick_all_conf_class(self):
        interested = self.context.set_interest()
        self.class_coord_login()
        data = {
            'email-select-conference': [self.context.conference.pk],
            'email-select-roles': ["Teacher"],
            'event-select-event_collections': "Conference",
            'refine': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(
            response,
            self.context.teacher.contact.user_object.email)
        self.assertNotContains(
            response,
            interested.user_object.email)
        assert_checkbox(
            response,
            "event_collections",
            0,
            "Conference",
            "All Conference Classes",
            prefix="event-select")

    def test_pick_forbidden_role_reduced_priv(self):
        self.class_coord_login()
        data = {
            'email-select-conference': [self.context.conference.pk],
            'email-select-roles': ["Teacher", "Performer"],
            'filter': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(
            response,
            'Select a valid choice. ' +
            'Performer is not one of the available choices.'
            )

    def test_pick_forbidden_collection_reduced_priv(self):
        self.class_coord_login()
        data = {
            'email-select-conference': [self.context.conference.pk],
            'email-select-roles': ["Teacher", ],
            'event-select-event_collections': "Volunteer",
            'refine': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(
            response,
            'Select a valid choice. ' +
            'Volunteer is not one of the available choices.'
            )

    def test_pick_performer_reduced_priv(self):
        showcontext = ShowContext()
        producer = showcontext.set_producer()
        anothershowcontext = ShowContext(
            conference=showcontext.conference,
        )
        login_as(producer, self)
        data = {
            'email-select-conference': [showcontext.conference.pk,
                                        self.context.conference.pk],
            'email-select-roles': ['Performer', ],
            'filter': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertNotContains(
            response,
            self.context.teacher.contact.user_object.email)
        self.assertContains(
            response,
            showcontext.performer.contact.user_object.email)
        self.assertContains(
            response,
            anothershowcontext.performer.contact.user_object.email)
        assert_checkbox(
            response,
            "events",
            0,
            showcontext.show.pk,
            showcontext.show.e_title,
            checked=False,
            prefix="event-select")
        assert_checkbox(
            response,
            "events",
            1,
            anothershowcontext.show.pk,
            anothershowcontext.show.e_title,
            checked=False,
            prefix="event-select")

    def test_pick_performer_specific_show(self):
        showcontext = ShowContext()
        anothershowcontext = ShowContext(
            conference=showcontext.conference,
        )
        producer = showcontext.set_producer()
        login_as(producer, self)
        data = {
            'email-select-conference': [showcontext.conference.pk,
                                        self.context.conference.pk],
            'email-select-roles': ['Performer', ],
            'event-select-events': showcontext.show.pk,
            'refine': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertNotContains(
            response,
            anothershowcontext.performer.contact.user_object.email)
        self.assertContains(
            response,
            showcontext.performer.contact.user_object.email)
        assert_checkbox(
            response,
            "events",
            0,
            showcontext.show.pk,
            showcontext.show.e_title,
            prefix="event-select")
        assert_checkbox(
            response,
            "events",
            1,
            anothershowcontext.show.pk,
            anothershowcontext.show.e_title,
            checked=False,
            prefix="event-select")

    def test_pick_performer_mismatch_show(self):
        showcontext = ShowContext()
        anothershowcontext = ShowContext()
        producer = showcontext.set_producer()
        login_as(producer, self)
        data = {
            'email-select-conference': [anothershowcontext.conference.pk],
            'email-select-roles': ['Performer', ],
            'event-select-events': showcontext.show.pk,
            'refine': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(
            response,
            "%d is not one of the available choices." % showcontext.show.pk)

    def test_pick_staff_area_reduced_priv(self):
        staffcontext = StaffAreaContext()
        volunteer, booking = staffcontext.book_volunteer()
        special = GenericEventFactory(
            e_conference=staffcontext.conference)
        specialstaffcontext = VolunteerContext(
            event=special,
        )
        login_as(staffcontext.staff_lead, self)
        data = {
            'email-select-conference': [staffcontext.conference.pk, ],
            'email-select-roles': ['Volunteer', ],
            'filter': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertNotContains(
            response,
            self.context.teacher.contact.user_object.email)
        self.assertContains(
            response,
            volunteer.user_object.email)
        self.assertContains(
            response,
            specialstaffcontext.profile.user_object.email)
        assert_checkbox(
            response,
            "events",
            0,
            special.pk,
            special.e_title,
            checked=False,
            prefix="event-select")
        assert_checkbox(
            response,
            "staff_areas",
            0,
            staffcontext.area.pk,
            staffcontext.area.title,
            checked=False,
            prefix="event-select")
        assert_checkbox(
            response,
            "event_collections",
            0,
            "Volunteer",
            "All Volunteer Events",
            checked=False,
            prefix="event-select")

    def test_pick_special_reduced_priv(self):
        staffcontext = StaffAreaContext()
        volunteer, booking = staffcontext.book_volunteer()
        special = GenericEventFactory(
            e_conference=staffcontext.conference)
        specialstaffcontext = VolunteerContext(
            event=special,
        )
        login_as(staffcontext.staff_lead, self)
        data = {
            'email-select-conference': [staffcontext.conference.pk, ],
            'email-select-roles': ['Volunteer', ],
            'event-select-events': special.pk,
            'refine': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertNotContains(
            response,
            self.context.teacher.contact.user_object.email)
        self.assertNotContains(
            response,
            volunteer.user_object.email)
        self.assertContains(
            response,
            specialstaffcontext.profile.user_object.email)
        assert_checkbox(
            response,
            "events",
            0,
            special.pk,
            special.e_title,
            prefix="event-select")
        assert_checkbox(
            response,
            "staff_areas",
            0,
            staffcontext.area.pk,
            staffcontext.area.title,
            checked=False,
            prefix="event-select")
        assert_checkbox(
            response,
            "event_collections",
            0,
            "Volunteer",
            "All Volunteer Events",
            checked=False,
            prefix="event-select")

    def test_pick_drop_in(self):
        special = GenericEventFactory(
            e_conference=self.context.conference,
            type="Drop-In")
        specialstaffcontext = VolunteerContext(
            event=special,
            role="Teacher"
        )
        limited_profile = ProfileFactory()
        grant_privilege(limited_profile.user_object, "Registrar")
        login_as(limited_profile, self)
        data = {
            'email-select-conference': [self.context.conference.pk, ],
            'email-select-roles': ['Teacher', ],
            'event-select-event_collections': "Drop-In",
            'refine': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        print response
        self.assertNotContains(
            response,
            self.context.teacher.contact.user_object.email)
        self.assertContains(
            response,
            specialstaffcontext.profile.user_object.email)
        self.assertNotContains(
            response,
            special.e_title)
        assert_checkbox(
            response,
            "event_collections",
            1,
            "Drop-In",
            "All Drop-In Classes",
            prefix="event-select")

    def test_pick_area_reduced_priv(self):
        staffcontext = StaffAreaContext()
        volunteer, booking = staffcontext.book_volunteer()
        special = GenericEventFactory(
            e_conference=staffcontext.conference)
        specialstaffcontext = VolunteerContext(
            event=special,
        )
        login_as(staffcontext.staff_lead, self)
        data = {
            'email-select-conference': [staffcontext.conference.pk, ],
            'email-select-roles': ['Volunteer', ],
            'event-select-staff_areas': staffcontext.area.pk,
            'refine': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertNotContains(
            response,
            self.context.teacher.contact.user_object.email)
        self.assertContains(
            response,
            volunteer.user_object.email)
        self.assertNotContains(
            response,
            specialstaffcontext.profile.user_object.email)
        assert_checkbox(
            response,
            "events",
            0,
            special.pk,
            special.e_title,
            checked=False,
            prefix="event-select")
        assert_checkbox(
            response,
            "staff_areas",
            0,
            staffcontext.area.pk,
            staffcontext.area.title,
            prefix="event-select")
        assert_checkbox(
            response,
            "event_collections",
            0,
            "Volunteer",
            "All Volunteer Events",
            checked=False,
            prefix="event-select")

    def test_pick_all_vol_reduced_priv(self):
        staffcontext = StaffAreaContext()
        volunteer, booking = staffcontext.book_volunteer()
        special = GenericEventFactory(
            e_conference=staffcontext.conference)
        specialstaffcontext = VolunteerContext(
            event=special,
        )
        login_as(staffcontext.staff_lead, self)
        data = {
            'email-select-conference': [staffcontext.conference.pk, ],
            'email-select-roles': ['Volunteer', ],
            'event-select-event_collections': "Volunteer",
            'refine': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        self.assertNotContains(
            response,
            self.context.teacher.contact.user_object.email)
        self.assertContains(
            response,
            volunteer.user_object.email)
        self.assertContains(
            response,
            specialstaffcontext.profile.user_object.email)
        assert_checkbox(
            response,
            "events",
            0,
            special.pk,
            special.e_title,
            checked=False,
            prefix="event-select")
        assert_checkbox(
            response,
            "staff_areas",
            0,
            staffcontext.area.pk,
            staffcontext.area.title,
            checked=False,
            prefix="event-select")
        assert_checkbox(
            response,
            "event_collections",
            0,
            "Volunteer",
            "All Volunteer Events",
            prefix="event-select")

    def test_pick_no_bidders(self):
        login_as(self.privileged_profile, self)
        data = {
            'email-select-conference': [self.context.conference.pk],
            'email-select-roles': ['Interested', ],
            'filter': True,
        }
        response = self.client.post(self.url, data=data, follow=True)
        assert_alert_exists(
            response, 'danger', 'Error', to_list_empty_msg)

    def test_send_email_success_status(self):
        staffcontext = StaffAreaContext(conference=self.context.conference)
        volunteer, booking = staffcontext.book_volunteer()
        login_as(self.privileged_profile, self)
        data = {
            'to': volunteer.user_object.email,
            'sender': self.privileged_profile.user_object.email,
            'subject': "Subject",
            'html_message': "<p>Test Message</p>",
            'email-select-conference': [self.context.conference.pk],
            'email-select-roles': ["Performer", "Volunteer"],
            'event-select-staff_areas': staffcontext.area.pk,
            'event-select-event_collections': "Volunteer",
            'send': True
        }
        response = self.client.post(self.url, data=data, follow=True)
        assert_alert_exists(
            response, 'success', 'Success', "%s%s" % (
                send_email_success_msg,
                volunteer.user_object.email))

    def test_send_email_success_email_sent(self):
        staffcontext = StaffAreaContext(conference=self.context.conference)
        volunteer, booking = staffcontext.book_volunteer()
        showcontext = ShowContext(conference=self.context.conference)
        showcontext.set_producer(producer=staffcontext.staff_lead)
        login_as(staffcontext.staff_lead, self)
        data = {
            'to': volunteer.user_object.email,
            'sender': staffcontext.staff_lead.user_object.email,
            'subject': "Subject",
            'html_message': "<p>Test Message</p>",
            'email-select-conference': [self.context.conference.pk],
            'email-select-roles': ["Volunteer", ],
            'event-select-events': showcontext.show.pk,
            'event-select-staff_areas': staffcontext.area.pk,
            'event-select-event_collections': "Volunteer",
            'send': True
        }
        response = self.client.post(self.url, data=data, follow=True)
        assert_queued_email(
            [volunteer.user_object.email, ],
            data['subject'],
            data['html_message'],
            data['sender'],
            )

    def test_send_email_failure_preserve_choices(self):
        staffcontext = StaffAreaContext(conference=self.context.conference)
        volunteer, booking = staffcontext.book_volunteer()
        showcontext = ShowContext(conference=self.context.conference)
        showcontext.set_producer(producer=staffcontext.staff_lead)
        login_as(self.privileged_profile, self)
        data = {
            'to': volunteer.user_object.email,
            'sender': "*****@*****.**",
            'html_message': "<p>Test Message</p>",
            'email-select-conference': [self.context.conference.pk],
            'email-select-roles': ["Interested", ],
            'event-select-events': showcontext.show.pk,
            'event-select-staff_areas': staffcontext.area.pk,
            'event-select-event_collections': "Volunteer",
            'send': True
        }
        response = self.client.post(self.url, data=data, follow=True)
        assert_checkbox(
            response,
            "conference",
            0,
            self.context.conference.pk,
            self.context.conference.conference_slug)
        assert_checkbox(
            response,
            "roles",
            0,
            "Interested",
            "Interested")
        assert_checkbox(
            response,
            "events",
            0,
            showcontext.show.pk,
            showcontext.show.e_title,
            prefix="event-select")
        assert_checkbox(
            response,
            "event_collections",
            2,
            "Volunteer",
            "All Volunteer Events",
            prefix="event-select")