def test_get_eventcontainer(self):
     context = ShowContext()
     rehearsal, slot = context.make_rehearsal()
     response = self.client.get('/admin/scheduler/eventcontainer/',
                                follow=True)
     self.assertContains(response, rehearsal.e_title)
     self.assertContains(response, context.show.e_title)
     self.assertContains(response, context.conference.conference_name)
Esempio n. 2
0
class TestEditEventView(TestCase):
    '''This view edits classes that were made through the wizard'''
    view_name = 'edit_event'

    def setUp(self):
        self.context = VolunteerContext(event=GenericEventFactory())
        self.context.sched_event.max_volunteer = 7
        self.context.sched_event.save()
        self.context.event.duration = Duration(hours=1, minutes=30)
        self.context.event.save()
        self.room = self.context.room
        self.staff_lead = self.context.set_staff_lead()
        self.extra_day = ConferenceDayFactory(
            conference=self.context.conference,
            day=self.context.conf_day.day + timedelta(days=1))
        self.url = reverse(
            self.view_name,
            args=[self.context.conference.conference_slug,
                  self.context.sched_event.pk],
            urlconf='gbe.scheduling.urls')
        self.client = Client()
        self.privileged_user = ProfileFactory().user_object
        grant_privilege(self.privileged_user, 'Scheduling Mavens')

    def edit_event(self):
        data = {
            'type': 'Special',
            'e_title': "Test Event Wizard",
            'e_description': 'Description',
            'max_volunteer': 3,
            'day': self.extra_day.pk,
            'time': '11:00:00',
            'duration': 2.5,
            'location': self.room.pk,
            'set_event': 'Any value',
            'alloc_0-role': 'Staff Lead',
        }
        return data

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

    def test_authorized_user_can_access_event(self):
        login_as(self.privileged_user, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        assert_role_choice(response, "Staff Lead")
        self.assertNotContains(response, "Volunteer Management")
        self.assertContains(response, "Finish")
        self.assertContains(response, self.context.event.e_title)
        self.assertContains(response, self.context.event.e_description)
        self.assertContains(
            response,
            '<option value="%d" selected="selected">%s</option>' % (
                self.context.conf_day.pk,
                self.context.conf_day.day.strftime(DATE_FORMAT)))
        self.assertContains(response,
                            'name="max_volunteer" type="number" value="7" />')
        self.assertContains(
            response,
            'name="duration" step="any" type="number" value="1.5" />')
        self.assertContains(
            response,
            '<option value="%d" selected="selected">%s</option>' % (
                self.staff_lead.pk,
                str(self.staff_lead)))

    def test_authorized_user_can_also_get_volunteer_mgmt(self):
        grant_privilege(self.privileged_user, 'Volunteer Coordinator')
        login_as(self.privileged_user, self)
        response = self.client.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Volunteer Management")
        self.assertContains(response, "Save and Continue")
        self.assertContains(
            response,
            '<option value="%d" selected="selected">%s</option>' % (
                self.context.conf_day.pk,
                self.context.conf_day.day.strftime("%b. %-d, %Y")))
        self.assertContains(
            response,
            'name="new_opp-max_volunteer" type="number" value="7" />')
        self.assertContains(
            response,
            'name="new_opp-duration" step="any" type="number" value="1.5" />')

    def test_authorized_user_can_access_rehearsal(self):
        self.context = ShowContext()
        rehearsal, slot = self.context.make_rehearsal()
        self.url = reverse(
            self.view_name,
            args=[self.context.conference.conference_slug,
                  slot.pk],
            urlconf='gbe.scheduling.urls')

        login_as(self.privileged_user, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Finish")
        self.assertContains(response, rehearsal.e_title)
        self.assertNotContains(response, 'Staffing')

    def test_vol_opp_present(self):
        vol_context = VolunteerContext()
        vol_context.sched_event.max_volunteer = 7
        vol_context.sched_event.save()
        vol_context.opp_event.set_locations([])
        grant_privilege(self.privileged_user, 'Volunteer Coordinator')
        login_as(self.privileged_user, self)
        self.url = reverse(
            self.view_name,
            args=[vol_context.conference.conference_slug,
                  vol_context.sched_event.pk],
            urlconf='gbe.scheduling.urls')
        response = self.client.get(self.url, follow=True)
        self.assertContains(
            response,
            'name="opp_event_id" type="hidden" value="%d" />' % (
                vol_context.opportunity.pk)
        )
        self.assertContains(
            response,
            'name="opp_sched_id" type="hidden" value="%d" />' % (
                vol_context.opp_event.pk)
        )
        self.assertContains(
            response,
            '<option value="%d" selected="selected">%s</option>' % (
                vol_context.window.day.pk,
                vol_context.window.day.day.strftime("%b. %-d, %Y")),
            3)
        self.assertContains(
            response,
            'name="max_volunteer" type="number" value="2" />')
        self.assertContains(
            response,
            'name="duration" step="any" type="number" value="1.0" />')

    def test_bad_conference(self):
        login_as(self.privileged_user, self)
        self.url = reverse(
            self.view_name,
            args=["BadConf",
                  self.context.sched_event.pk],
            urlconf='gbe.scheduling.urls')
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 404)

    def test_bad_occurrence_id(self):
        login_as(self.privileged_user, self)
        self.url = reverse(
            self.view_name,
            args=[self.context.conference.conference_slug,
                  self.context.sched_event.pk+1000],
            urlconf='gbe.scheduling.urls')
        response = self.client.get(self.url, follow=True)
        self.assertRedirects(
            response,
            reverse('manage_event_list',
                    urlconf='gbe.scheduling.urls',
                    args=[self.context.conference.conference_slug]))
        self.assertContains(
            response,
            "Occurrence id %d not found" % (self.context.sched_event.pk+1000))

    def test_edit_event_w_staffing(self):
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['alloc_0-worker'] = self.privileged_user.profile.pk
        response = self.client.post(
            self.url,
            data=data,
            follow=True)
        self.assertRedirects(
            response,
            "%s?%s-day=%d&filter=Filter&new=[%dL]" % (
                reverse('manage_event_list',
                        urlconf='gbe.scheduling.urls',
                        args=[self.context.conference.conference_slug]),
                self.context.conference.conference_slug,
                self.extra_day.pk,
                self.context.sched_event.pk))
        assert_alert_exists(
            response,
            'success',
            'Success',
            'Occurrence has been updated.<br>%s, Start Time: %s 11:00 AM' % (
                data['e_title'],
                self.extra_day.day.strftime(DATE_FORMAT))
            )
        self.assertContains(
            response,
            '<tr class="bid-table success">\n       ' +
            '<td class="bid-table">%s</td>' % data['e_title'])

    def test_edit_event_and_continue(self):
        grant_privilege(self.privileged_user, 'Volunteer Coordinator')
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['edit_event'] = "Save and Continue"
        response = self.client.post(
            self.url,
            data=data,
            follow=True)
        self.assertRedirects(
            response,
            "%s?volunteer_open=True" % self.url)
        assert_alert_exists(
            response,
            'success',
            'Success',
            'Occurrence has been updated.<br>%s, Start Time: %s 11:00 AM' % (
                data['e_title'],
                self.extra_day.day.strftime(DATE_FORMAT))
            )
        self.assertContains(response, data['e_title'])
        self.assertContains(response, data['e_description'])
        self.assertContains(
            response,
            '<option value="%d" selected="selected">%s</option>' % (
                self.extra_day.pk,
                self.extra_day.day.strftime(DATE_FORMAT)))
        self.assertContains(response,
                            'name="max_volunteer" type="number" value="3" />')
        self.assertContains(
            response,
            'name="duration" step="any" type="number" value="2.5" />')

    def test_auth_user_bad_user_assign(self):
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['alloc_0-role'] = "bad role"
        data['alloc_1-role'] = "bad role"
        response = self.client.post(
            self.url,
            data=data,
            follow=True)
        self.assertContains(
            response,
            "bad role is not one of the available choices.")

    def test_auth_user_bad_schedule_assign(self):
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['location'] = ""
        response = self.client.post(
            self.url,
            data=data,
            follow=True)
        self.assertContains(response, "This field is required.")

    def test_auth_user_bad_generic_booking_assign(self):
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['e_title'] = ""
        response = self.client.post(
            self.url,
            data=data,
            follow=True)
        self.assertContains(
            response,
            "This field is required.")

    def test_post_bad_occurrence(self):
        login_as(self.privileged_user, self)
        self.url = reverse(
            self.view_name,
            args=[self.context.conference.conference_slug,
                  self.context.sched_event.pk+1000],
            urlconf='gbe.scheduling.urls')
        response = self.client.post(self.url, follow=True)
        self.assertRedirects(
            response,
            reverse('manage_event_list',
                    urlconf='gbe.scheduling.urls',
                    args=[self.context.conference.conference_slug]))
        self.assertContains(
            response,
            "Occurrence id %d not found" % (self.context.sched_event.pk+1000))
Esempio n. 3
0
class TestEditShowWizard(TestCase):
    view_name = 'manage_show_opp'

    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')
        grant_privilege(self.privileged_user, 'Volunteer Coordinator')
        self.room = RoomFactory()
        self.context = ShowContext()
        self.url = reverse(self.view_name,
                           urlconf="gbe.scheduling.urls",
                           args=[
                               self.context.conference.conference_slug,
                               self.context.sched_event.pk
                           ])

    def get_new_slot_data(self, context):
        data = {
            'create_slot': 'create_slot',
            'new_slot-e_title': 'New Rehearsal Slot',
            'new_slot-type': "Rehearsal Slot",
            'new_slot-max_volunteer': '1',
            'new_slot-duration': '1.0',
            'new_slot-day': self.context.days[0].pk,
            'new_slot-time': '10:00:00',
            'new_slot-location': self.room.pk
        }
        return data

    def get_basic_data(self, context):
        data = {
            'e_title': 'Copied Rehearsal Slot',
            'type': 'Rehearsal Slot',
            'max_volunteer': '1',
            'duration': '1.0',
            'day': self.context.days[0].pk,
            'time': '10:00:00',
            'location': self.room.pk
        }
        return data

    def get_basic_action_data(self, context, action):
        data = self.get_basic_data(context)
        rehearsal, slot = self.context.make_rehearsal()
        data['e_title'] = 'Modify Rehearsal Slot'
        data['opp_event_id'] = rehearsal.event_id
        data['opp_sched_id'] = slot.pk
        data[action] = action
        return data, rehearsal, slot

    def test_good_user_get(self):
        self.url = reverse("edit_show",
                           urlconf="gbe.scheduling.urls",
                           args=[
                               self.context.conference.conference_slug,
                               self.context.sched_event.pk
                           ])
        login_as(self.privileged_profile, self)
        response = self.client.get(self.url, follow=True)
        self.assertContains(response, "Edit Show Details")
        self.assertContains(response, "Manage Volunteer Opportunities")
        self.assertContains(response, "Manage Rehearsal Slots")
        self.assertContains(response, 'class="panel-collapse collapse in"', 3)

    def test_good_user_get_rehearsal_w_acts(self):
        act_techinfo_context = ActTechInfoContext(
            show=self.context.show,
            sched_event=self.context.sched_event,
            schedule_rehearsal=True)
        self.url = reverse("edit_show",
                           urlconf="gbe.scheduling.urls",
                           args=[
                               self.context.conference.conference_slug,
                               self.context.sched_event.pk
                           ])
        login_as(self.privileged_profile, self)
        response = self.client.get(self.url, follow=True)
        self.assertContains(
            response, '<input id="id_current_acts" name="current_acts" ' +
            'readonly="readonly" type="number" value="1" />')

    def test_good_user_get_empty_room_rehearsal(self):
        rehearsal, slot = self.context.make_rehearsal(room=False)
        login_as(self.privileged_profile, self)
        response = self.client.get(self.url, follow=True)
        self.assertContains(
            response, '<option value="%d" selected="selected">%s</option>' %
            (self.context.room.pk, str(self.context.room)), 4)

    def test_good_user_get_bad_occurrence_id(self):
        login_as(self.privileged_user, self)
        self.url = reverse(self.view_name,
                           args=[
                               self.context.conference.conference_slug,
                               self.context.sched_event.pk + 1000
                           ],
                           urlconf='gbe.scheduling.urls')
        response = self.client.get(self.url, follow=True)
        self.assertRedirects(
            response,
            reverse('manage_event_list',
                    urlconf='gbe.scheduling.urls',
                    args=[self.context.conference.conference_slug]))
        self.assertContains(
            response, "Occurrence id %d not found" %
            (self.context.sched_event.pk + 1000))

    def test_create_slot(self):
        login_as(self.privileged_profile, self)
        response = self.client.post(self.url,
                                    data=self.get_new_slot_data(self.context),
                                    follow=True)
        self.assertContains(
            response,
            '<div id="collapse3" class="panel-collapse collapse in">')
        slots = EventContainer.objects.filter(
            parent_event=self.context.sched_event)
        self.assertTrue(slots.exists())
        for slot in slots:
            self.assertEqual(slot.child_event.eventitem.child().e_title,
                             'New Rehearsal Slot')
            self.assertRedirects(
                response, "%s?changed_id=%d&rehearsal_open=True" %
                (reverse('edit_show',
                         urlconf='gbe.scheduling.urls',
                         args=[
                             self.context.conference.conference_slug,
                             self.context.sched_event.pk
                         ]), slot.child_event.pk))
            self.assertEqual(
                EventLabel.objects.filter(text=slot.child_event.eventitem.
                                          child().e_conference.conference_slug,
                                          event=slot.child_event).count(), 1)
            self.assertEqual(
                EventLabel.objects.filter(event=slot.child_event).count(), 1)

        self.assertContains(
            response,
            '<input id="id_e_title" maxlength="128" name="e_title" ' +
            'type="text" value="New Rehearsal Slot" />')

    def test_create_slot_error(self):
        login_as(self.privileged_profile, self)
        data = self.get_new_slot_data(self.context)
        data['new_slot-max_volunteer'] = ''

        # number of volunteers is missing, it's required
        response = self.client.post(self.url, data=data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            '<div id="collapse3" class="panel-collapse collapse in">')
        slots = EventContainer.objects.filter(
            parent_event=self.context.sched_event).count()
        self.assertEqual(slots, 0)
        self.assertContains(
            response,
            '<ul class="errorlist"><li>This field is required.</li></ul>')

    def test_copy_opportunity(self):
        login_as(self.privileged_profile, self)
        data = self.get_basic_data(self.context)
        data['duplicate_slot'] = 'duplicate_slot'
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(
            response,
            '<div id="collapse3" class="panel-collapse collapse in">')
        slots = EventContainer.objects.filter(
            parent_event=self.context.sched_event)
        self.assertTrue(len(slots), 1)
        for slot in slots:
            self.assertContains(
                response, '<input id="id_e_title" maxlength="128" '
                'name="e_title" type="text" value="%s" />' %
                (slot.child_event.eventitem.child().e_title))
            self.assertRedirects(
                response, "%s?changed_id=%d&rehearsal_open=True" %
                (reverse('edit_show',
                         urlconf='gbe.scheduling.urls',
                         args=[
                             self.context.conference.conference_slug,
                             self.context.sched_event.pk
                         ]), slot.child_event.pk))

    def test_edit_slot(self):
        login_as(self.privileged_profile, self)
        data, rehearsal, slot = self.get_basic_action_data(
            self.context, 'edit_slot')
        response = self.client.post(self.url, data=data, follow=True)
        self.assertRedirects(
            response, "%s?changed_id=%d&rehearsal_open=True" %
            (reverse('edit_show',
                     urlconf='gbe.scheduling.urls',
                     args=[
                         self.context.conference.conference_slug,
                         self.context.sched_event.pk
                     ]), slot.pk))
        slots = EventContainer.objects.filter(
            parent_event=self.context.sched_event)
        self.assertTrue(len(slots), 1)
        self.assertContains(
            response,
            '<input id="id_e_title" maxlength="128" name="e_title" ' +
            'type="text" value="Modify Rehearsal Slot" />')
        self.assertContains(response, self.room.name)

    def test_edit_error(self):
        login_as(self.privileged_profile, self)
        data, rehearsal, slot = self.get_basic_action_data(
            self.context, 'edit_slot')
        data['max_volunteer'] = ''

        # number of volunteers is missing, it's required
        response = self.client.post(self.url, data=data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            '<input id="id_e_title" maxlength="128" name="e_title" ' +
            'type="text" value="Modify Rehearsal Slot" />')
        self.assertContains(
            response,
            '<ul class="errorlist"><li>This field is required.</li></ul>')

    def test_delete_slot(self):
        login_as(self.privileged_profile, self)
        data, rehearsal, slot = self.get_basic_action_data(
            self.context, 'delete_slot')

        # number of volunteers is missing, it's required
        response = self.client.post(self.url, data=data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, 'Modify Rehearsal Slot')
        slots = EventContainer.objects.filter(
            parent_event=self.context.sched_event)
        self.assertFalse(slots.exists())
Esempio n. 4
0
class TestEditShowWizard(TestCase):
    view_name = 'manage_show_opp'

    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')
        grant_privilege(self.privileged_user, 'Volunteer Coordinator')
        self.room = RoomFactory()
        self.context = ShowContext()
        self.url = reverse(
            self.view_name,
            urlconf="gbe.scheduling.urls",
            args=[self.context.conference.conference_slug,
                  self.context.sched_event.pk])

    def get_new_slot_data(self, context):
        data = {
            'create_slot': 'create_slot',
            'new_slot-e_title': 'New Rehearsal Slot',
            'new_slot-type': "Rehearsal Slot",
            'new_slot-max_volunteer': '1',
            'new_slot-duration': '1.0',
            'new_slot-day': self.context.days[0].pk,
            'new_slot-time': '10:00:00',
            'new_slot-location': self.room.pk}
        return data

    def get_basic_data(self, context):
        data = {
            'e_title': 'Copied Rehearsal Slot',
            'type': 'Rehearsal Slot',
            'max_volunteer': '1',
            'duration': '1.0',
            'day': self.context.days[0].pk,
            'time': '10:00:00',
            'location': self.room.pk}
        return data

    def get_basic_action_data(self, context, action):
        data = self.get_basic_data(context)
        rehearsal, slot = self.context.make_rehearsal()
        data['e_title'] = 'Modify Rehearsal Slot'
        data['opp_event_id'] = rehearsal.event_id
        data['opp_sched_id'] = slot.pk
        data[action] = action
        return data, rehearsal, slot

    def test_good_user_get(self):
        self.url = reverse(
            "edit_show",
            urlconf="gbe.scheduling.urls",
            args=[self.context.conference.conference_slug,
                  self.context.sched_event.pk])
        login_as(self.privileged_profile, self)
        response = self.client.get(self.url, follow=True)
        self.assertContains(response, "Edit Show Details")
        self.assertContains(response, "Manage Volunteer Opportunities")
        self.assertContains(response, "Manage Rehearsal Slots")
        self.assertContains(response, 'class="panel-collapse collapse in"', 3)

    def test_good_user_get_rehearsal_w_acts(self):
        act_techinfo_context = ActTechInfoContext(
            show=self.context.show,
            sched_event=self.context.sched_event,
            schedule_rehearsal=True)
        self.url = reverse(
            "edit_show",
            urlconf="gbe.scheduling.urls",
            args=[self.context.conference.conference_slug,
                  self.context.sched_event.pk])
        login_as(self.privileged_profile, self)
        response = self.client.get(self.url, follow=True)
        self.assertContains(
            response,
            '<input id="id_current_acts" name="current_acts" ' +
            'readonly="readonly" type="number" value="1" />')

    def test_good_user_get_empty_room_rehearsal(self):
        rehearsal, slot = self.context.make_rehearsal(room=False)
        login_as(self.privileged_profile, self)
        response = self.client.get(self.url, follow=True)
        self.assertContains(
            response,
            '<option value="%d" selected="selected">%s</option>' % (
                self.context.room.pk,
                str(self.context.room)),
            4)

    def test_good_user_get_bad_occurrence_id(self):
        login_as(self.privileged_user, self)
        self.url = reverse(
            self.view_name,
            args=[self.context.conference.conference_slug,
                  self.context.sched_event.pk+1000],
            urlconf='gbe.scheduling.urls')
        response = self.client.get(self.url, follow=True)
        self.assertRedirects(
            response,
            reverse('manage_event_list',
                    urlconf='gbe.scheduling.urls',
                    args=[self.context.conference.conference_slug]))
        self.assertContains(
            response,
            "Occurrence id %d not found" % (self.context.sched_event.pk+1000))

    def test_create_slot(self):
        login_as(self.privileged_profile, self)
        response = self.client.post(
            self.url,
            data=self.get_new_slot_data(self.context),
            follow=True)
        self.assertContains(
            response,
            '<div id="collapse3" class="panel-collapse collapse in">')
        slots = EventContainer.objects.filter(
            parent_event=self.context.sched_event)
        self.assertTrue(slots.exists())
        for slot in slots:
            self.assertEqual(slot.child_event.eventitem.child().e_title,
                             'New Rehearsal Slot')
            self.assertRedirects(
                response,
                "%s?changed_id=%d&rehearsal_open=True" % (
                    reverse('edit_show',
                            urlconf='gbe.scheduling.urls',
                            args=[self.context.conference.conference_slug,
                                  self.context.sched_event.pk]),
                    slot.child_event.pk))
            self.assertEqual(EventLabel.objects.filter(
                text=slot.child_event.eventitem.child(
                    ).e_conference.conference_slug,
                event=slot.child_event).count(), 1)
            self.assertEqual(EventLabel.objects.filter(
                event=slot.child_event).count(), 1)

        self.assertContains(
            response,
            '<input id="id_e_title" maxlength="128" name="e_title" ' +
            'type="text" value="New Rehearsal Slot" />')

    def test_create_slot_error(self):
        login_as(self.privileged_profile, self)
        data = self.get_new_slot_data(self.context)
        data['new_slot-max_volunteer'] = ''

        # number of volunteers is missing, it's required
        response = self.client.post(
            self.url,
            data=data,
            follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            '<div id="collapse3" class="panel-collapse collapse in">')
        slots = EventContainer.objects.filter(
            parent_event=self.context.sched_event).count()
        self.assertEqual(slots, 0)
        self.assertContains(
            response,
            '<ul class="errorlist"><li>This field is required.</li></ul>')

    def test_copy_opportunity(self):
        login_as(self.privileged_profile, self)
        data = self.get_basic_data(self.context)
        data['duplicate_slot'] = 'duplicate_slot'
        response = self.client.post(
            self.url,
            data=data,
            follow=True)
        self.assertContains(
            response,
            '<div id="collapse3" class="panel-collapse collapse in">')
        slots = EventContainer.objects.filter(
            parent_event=self.context.sched_event)
        self.assertTrue(len(slots), 1)
        for slot in slots:
            self.assertContains(
                response,
                '<input id="id_e_title" maxlength="128" '
                'name="e_title" type="text" value="%s" />' % (
                    slot.child_event.eventitem.child().e_title))
            self.assertRedirects(
                response,
                "%s?changed_id=%d&rehearsal_open=True" % (
                    reverse(
                        'edit_show',
                        urlconf='gbe.scheduling.urls',
                        args=[self.context.conference.conference_slug,
                              self.context.sched_event.pk]),
                    slot.child_event.pk))

    def test_edit_slot(self):
        login_as(self.privileged_profile, self)
        data, rehearsal, slot = self.get_basic_action_data(self.context,
                                                           'edit_slot')
        response = self.client.post(
            self.url,
            data=data,
            follow=True)
        self.assertRedirects(
            response,
            "%s?changed_id=%d&rehearsal_open=True" % (
                reverse('edit_show',
                        urlconf='gbe.scheduling.urls',
                        args=[self.context.conference.conference_slug,
                              self.context.sched_event.pk]),
                slot.pk))
        slots = EventContainer.objects.filter(
            parent_event=self.context.sched_event)
        self.assertTrue(len(slots), 1)
        self.assertContains(
            response,
            '<input id="id_e_title" maxlength="128" name="e_title" ' +
            'type="text" value="Modify Rehearsal Slot" />')
        self.assertContains(response, self.room.name)

    def test_edit_error(self):
        login_as(self.privileged_profile, self)
        data, rehearsal, slot = self.get_basic_action_data(self.context,
                                                           'edit_slot')
        data['max_volunteer'] = ''

        # number of volunteers is missing, it's required
        response = self.client.post(
            self.url,
            data=data,
            follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            '<input id="id_e_title" maxlength="128" name="e_title" ' +
            'type="text" value="Modify Rehearsal Slot" />')
        self.assertContains(
            response,
            '<ul class="errorlist"><li>This field is required.</li></ul>')

    def test_delete_slot(self):
        login_as(self.privileged_profile, self)
        data, rehearsal, slot = self.get_basic_action_data(self.context,
                                                           'delete_slot')

        # number of volunteers is missing, it's required
        response = self.client.post(
            self.url,
            data=data,
            follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, 'Modify Rehearsal Slot')
        slots = EventContainer.objects.filter(
            parent_event=self.context.sched_event)
        self.assertFalse(slots.exists())
Esempio n. 5
0
class TestEditEventView(TestScheduling):
    '''This view edits classes that were made through the wizard'''
    view_name = 'edit_event'

    def setUp(self):
        self.context = VolunteerContext(event=GenericEventFactory())
        self.context.sched_event.max_volunteer = 7
        self.context.sched_event.save()
        self.context.event.duration = timedelta(hours=1, minutes=30)
        self.context.event.save()
        self.room = self.context.room
        # because there was a bug around duplicate room names
        RoomFactory(name=self.room.name)
        self.staff_lead = self.context.set_staff_lead()
        self.extra_day = ConferenceDayFactory(
            conference=self.context.conference,
            day=self.context.conf_day.day + timedelta(days=1))
        self.url = reverse(self.view_name,
                           args=[
                               self.context.conference.conference_slug,
                               self.context.sched_event.pk
                           ],
                           urlconf='gbe.scheduling.urls')
        self.client = Client()
        self.privileged_user = ProfileFactory().user_object
        grant_privilege(self.privileged_user, 'Scheduling Mavens')

    def edit_event(self):
        data = {
            'type': 'Special',
            'e_title': "Test Event Wizard",
            'e_description': 'Description',
            'max_volunteer': 3,
            'day': self.extra_day.pk,
            'time': '11:00:00',
            'duration': 2.5,
            'location': self.room.pk,
            'set_event': 'Any value',
            'alloc_0-role': 'Staff Lead',
        }
        return data

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

    def test_authorized_user_can_access_event(self):
        login_as(self.privileged_user, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assert_role_choice(response, "Staff Lead")
        self.assertNotContains(response, "Volunteer Management")
        self.assertContains(response, "Finish")
        self.assertContains(response, self.context.event.e_title)
        self.assertContains(response, self.context.event.e_description)
        assert_option_state(
            response, self.context.conf_day.pk,
            self.context.conf_day.day.strftime(GBE_DATE_FORMAT), True)
        self.assertContains(response, 'name="max_volunteer" value="7"')
        self.assertContains(response, 'name="duration" value="1.5"')
        assert_option_state(response, self.staff_lead.pk, str(self.staff_lead),
                            True)

    def test_authorized_user_can_also_get_volunteer_mgmt(self):
        grant_privilege(self.privileged_user, 'Volunteer Coordinator')
        login_as(self.privileged_user, self)
        response = self.client.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Volunteer Management")
        self.assertContains(response, "Save and Continue")
        assert_option_state(response, self.context.conf_day.pk,
                            self.context.conf_day.day.strftime("%b. %-d, %Y"),
                            True)
        self.assertContains(response, 'name="new_opp-max_volunteer" value="7"')
        self.assertContains(response, 'name="new_opp-duration" value="1.5"')

    def test_authorized_user_can_access_rehearsal(self):
        self.context = ShowContext()
        rehearsal, slot = self.context.make_rehearsal()
        self.url = reverse(
            self.view_name,
            args=[self.context.conference.conference_slug, slot.pk],
            urlconf='gbe.scheduling.urls')

        login_as(self.privileged_user, self)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Finish")
        self.assertContains(response, rehearsal.e_title)
        self.assertNotContains(response, 'Display Staff')

    def test_vol_opp_present(self):
        vol_context = VolunteerContext()
        vol_context.sched_event.max_volunteer = 7
        vol_context.sched_event.save()
        vol_context.opp_event.set_locations([])
        grant_privilege(self.privileged_user, 'Volunteer Coordinator')
        login_as(self.privileged_user, self)
        self.url = reverse(self.view_name,
                           args=[
                               vol_context.conference.conference_slug,
                               vol_context.sched_event.pk
                           ],
                           urlconf='gbe.scheduling.urls')
        response = self.client.get(self.url, follow=True)
        self.assertContains(
            response, 'type="hidden" name="opp_event_id" value="%d"' %
            (vol_context.opportunity.pk))
        self.assertContains(
            response, 'type="hidden" name="opp_sched_id" value="%d"' %
            (vol_context.opp_event.pk))
        assert_option_state(response, vol_context.conf_day.pk,
                            vol_context.conf_day.day.strftime("%b. %-d, %Y"),
                            True)
        self.assertContains(response, 'name="max_volunteer" value="2"')
        self.assertContains(response, 'name="duration" value="1.0"')
        self.assertContains(response, "Display Staff", 2)

    def test_bad_occurrence_id(self):
        login_as(self.privileged_user, self)
        self.url = reverse(self.view_name,
                           args=[
                               self.context.conference.conference_slug,
                               self.context.sched_event.pk + 1000
                           ],
                           urlconf='gbe.scheduling.urls')
        response = self.client.get(self.url, follow=True)
        self.assertRedirects(
            response,
            reverse('manage_event_list',
                    urlconf='gbe.scheduling.urls',
                    args=[self.context.conference.conference_slug]))
        self.assertContains(
            response, "Occurrence id %d not found" %
            (self.context.sched_event.pk + 1000))

    def test_edit_event_w_staffing(self):
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['alloc_0-worker'] = self.privileged_user.profile.pk
        response = self.client.post(self.url, data=data, follow=True)
        self.assertRedirects(
            response, "%s?%s-day=%d&filter=Filter&new=[%d]" %
            (reverse('manage_event_list',
                     urlconf='gbe.scheduling.urls',
                     args=[self.context.conference.conference_slug
                           ]), self.context.conference.conference_slug,
             self.extra_day.pk, self.context.sched_event.pk))
        assert_alert_exists(
            response, 'success', 'Success',
            'Occurrence has been updated.<br>%s, Start Time: %s 11:00 AM' %
            (data['e_title'], self.extra_day.day.strftime(GBE_DATE_FORMAT)))
        self.assertContains(
            response, '<tr class="gbe-table-row gbe-table-success">\n       ' +
            '<td>%s</td>' % data['e_title'])

    def test_edit_event_and_continue(self):
        grant_privilege(self.privileged_user, 'Volunteer Coordinator')
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['edit_event'] = "Save and Continue"
        response = self.client.post(self.url, data=data, follow=True)
        self.assertRedirects(response, "%s?volunteer_open=True" % self.url)
        assert_alert_exists(
            response, 'success', 'Success',
            'Occurrence has been updated.<br>%s, Start Time: %s 11:00 AM' %
            (data['e_title'], self.extra_day.day.strftime(GBE_DATE_FORMAT)))
        self.assertContains(response, data['e_title'])
        self.assertContains(response, data['e_description'])
        assert_option_state(response, self.extra_day.pk,
                            self.extra_day.day.strftime(GBE_DATE_FORMAT), True)
        self.assertContains(response, 'name="max_volunteer" value="3"')
        self.assertContains(response, 'name="duration" value="2.5"')

    def test_auth_user_bad_user_assign(self):
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['alloc_0-role'] = "bad role"
        data['alloc_1-role'] = "bad role"
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(response,
                            "bad role is not one of the available choices.")

    def test_auth_user_bad_schedule_assign(self):
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['location'] = ""
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(response, "This field is required.")

    def test_auth_user_bad_room_assign(self):
        not_this_room = RoomFactory()
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['location'] = not_this_room.pk
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(
            response, "That choice is not one of the available choices.")

    def test_auth_user_bad_generic_booking_assign(self):
        login_as(self.privileged_user, self)
        data = self.edit_event()
        data['e_title'] = ""
        response = self.client.post(self.url, data=data, follow=True)
        self.assertContains(response, "This field is required.")

    def test_post_bad_occurrence(self):
        login_as(self.privileged_user, self)
        self.url = reverse(self.view_name,
                           args=[
                               self.context.conference.conference_slug,
                               self.context.sched_event.pk + 1000
                           ],
                           urlconf='gbe.scheduling.urls')
        response = self.client.post(self.url, follow=True)
        self.assertRedirects(
            response,
            reverse('manage_event_list',
                    urlconf='gbe.scheduling.urls',
                    args=[self.context.conference.conference_slug]))
        self.assertContains(
            response, "Occurrence id %d not found" %
            (self.context.sched_event.pk + 1000))