Exemple #1
0
 def test_event_remove_approval(self):
     """Deleting an Event DOES remove associated Approval."""
     event = Event.objects.get(id=22)
     approval = Approval(event=event)
     approval.save()
     self._successful_delete(event)
     self._refresh_ok(approval, exists=False)
Exemple #2
0
 def test_approval_remove(self):
     """Deleting an Approval does not delete associated Event."""
     event = Event.objects.get(id=22)
     approval = Approval(event=event)
     approval.save()
     self._successful_delete(approval)
     self._refresh_ok(event)
Exemple #3
0
 def test_approval_remove(self):
     """Deleting an Approval does not delete associated Event."""
     event = Event.objects.get(id=22)
     approval = Approval(event=event)
     approval.save()
     self._successful_delete(approval)
     self._refresh_ok(event)
Exemple #4
0
 def test_event_remove_approval(self):
     """Deleting an Event DOES remove associated Approval."""
     event = Event.objects.get(id=22)
     approval = Approval(event=event)
     approval.save()
     self._successful_delete(event)
     self._refresh_ok(approval, exists=False)
Exemple #5
0
 def test_user_remove(self):
     """Deleting a User does not delete associated Approval."""
     event = Event.objects.get(id=22)
     user = User.objects.get(id=1)
     approval = Approval(event=event, user=user)
     approval.save()
     self._successful_delete(user)
     self._refresh_ok(approval)
Exemple #6
0
 def test_user_remove(self):
     """Deleting a User does not delete associated Approval."""
     event = Event.objects.get(id=22)
     user = User.objects.get(id=1)
     approval = Approval(event=event, user=user)
     approval.save()
     self._successful_delete(user)
     self._refresh_ok(approval)
Exemple #7
0
 def test_group_remove(self):
     """Deleting a Group does not delete associated Approval."""
     event = Event.objects.get(id=22)
     group = Group.objects.create(name='testapprover')
     approval = Approval(event=event, group=group)
     approval.save()
     self._successful_delete(group)
     self._refresh_ok(approval)
Exemple #8
0
 def test_group_remove(self):
     """Deleting a Group does not delete associated Approval."""
     event = Event.objects.get(id=22)
     group = Group.objects.get(id=1)
     approval = Approval(event=event, group=group)
     approval.save()
     self._successful_delete(group)
     self._refresh_ok(approval)
Exemple #9
0
 def test_event(self):
     """Event view page loads correctly if the event is public and
        scheduled and approved; request a login otherwise."""
     event = Event.objects.get(title='Test event')
     group = Group.objects.get()
     approval = Approval(event=event, group=group)
     approval.save()
     event_page = reverse('main:event', kwargs={'slug': event.slug})
     response_fail_approval = self.client.get(event_page)
     eq_(response_fail_approval.status_code, 200)
     ok_('not approved' in response_fail_approval.content)
     approval.approved = True
     approval.processed = True
     approval.save()
     response_ok = self.client.get(event_page)
     eq_(response_ok.status_code, 200)
     event.public = False
     event.save()
     response_fail = self.client.get(event_page)
     self.assertRedirects(response_fail, reverse('main:login'))
     event.public = True
     event.status = Event.STATUS_INITIATED
     event.save()
     response_fail = self.client.get(event_page)
     eq_(response_fail.status_code, 200)
     ok_('not scheduled' in response_fail.content)
Exemple #10
0
 def test_approval_review(self):
     app = Approval(event=Event.objects.get(id=22),
                    group=Group.objects.get(id=1))
     app.save()
     url = reverse('manage:approval_review', kwargs={'id': app.id})
     response_not_in_group = self.client.get(url)
     self.assertRedirects(response_not_in_group,
                          reverse('manage:approvals'))
     User.objects.get(username='******').groups.add(1)
     response = self.client.get(url)
     eq_(response.status_code, 200)
     response_approve = self.client.post(url, {'approve': 'approve'})
     self.assertRedirects(response_approve, reverse('manage:approvals'))
     app = Approval.objects.get(id=app.id)
     ok_(app.approved)
     ok_(app.processed)
     eq_(app.user, User.objects.get(username='******'))
Exemple #11
0
 def test_approval_review(self):
     app = Approval(event=Event.objects.get(id=22),
                    group=Group.objects.get(id=1))
     app.save()
     url = reverse('manage:approval_review', kwargs={'id': app.id})
     response_not_in_group = self.client.get(url)
     self.assertRedirects(response_not_in_group,
                          reverse('manage:approvals'))
     User.objects.get(username='******').groups.add(1)
     response = self.client.get(url)
     eq_(response.status_code, 200)
     response_approve = self.client.post(url, {'approve': 'approve'})
     self.assertRedirects(response_approve, reverse('manage:approvals'))
     app = Approval.objects.get(id=app.id)
     ok_(app.approved)
     ok_(app.processed)
     eq_(app.user, User.objects.get(username='******'))
Exemple #12
0
 def test_event(self):
     """Event view page loads correctly if the event is public and
        scheduled and approved; request a login otherwise."""
     event = Event.objects.get(title='Test event')
     group = Group.objects.get()
     approval = Approval(event=event, group=group)
     approval.save()
     event_page = reverse('main:event', kwargs={'slug': event.slug})
     response_fail_approval = self.client.get(event_page)
     eq_(response_fail_approval.status_code, 200)
     ok_('not approved' in response_fail_approval.content)
     approval.approved = True
     approval.processed = True
     approval.save()
     response_ok = self.client.get(event_page)
     eq_(response_ok.status_code, 200)
     event.public = False
     event.save()
     response_fail = self.client.get(event_page)
     self.assertRedirects(response_fail, reverse('main:login'))
     event.public = True
     event.status = Event.STATUS_INITIATED
     event.save()
     response_fail = self.client.get(event_page)
     eq_(response_fail.status_code, 200)
     ok_('not scheduled' in response_fail.content)
Exemple #13
0
 def test_event_upcoming(self):
     """View an upcoming event and it should show the local time"""
     event = Event.objects.get(title='Test event')
     date = datetime.datetime(2099, 1, 1, 18, 0, 0).replace(tzinfo=utc)
     event.start_time = date
     event.save()
     group = Group.objects.get()
     approval = Approval(event=event, group=group)
     approval.approved = True
     approval.save()
     event_page = reverse('main:event', kwargs={'slug': event.slug})
     response = self.client.get(event_page)
     eq_(response.status_code, 200)
     assert event.location
     ok_(event.location.name in response.content)
     # 18:00 in UTC on that 1st Jan 2099 is 10AM in Pacific time
     assert event.location.timezone == 'US/Pacific'
     ok_('10:00AM' in response.content)
Exemple #14
0
def _event_process(request, form, event):
    """Generate and clean associated event data for an event request
       or event edit:  timezone application, approvals update and
       notifications, creator and modifier."""
    if not event.creator:
        event.creator = request.user
    event.modified_user = request.user
    tz = pytz.timezone(request.POST['timezone'])
    event.start_time = tz_apply(event.start_time, tz)
    if event.archive_time:
        event.archive_time = tz_apply(event.archive_time, tz)
    if 'approvals' in form.cleaned_data:
        event.save()
        approvals_old = [app.group for app in event.approval_set.all()]
        approvals_new = form.cleaned_data['approvals']
        approvals_add = set(approvals_new).difference(approvals_old)
        approvals_remove = set(approvals_old).difference(approvals_new)
        for approval in approvals_add:
            group = Group.objects.get(name=approval)
            app = Approval(group=group, event=event)
            app.save()
            emails = [u.email for u in group.user_set.all()]
            subject = ('[Air Mozilla] Approval requested: "%s"' %
                       event.title)
            message = render_to_string(
                'manage/_email_approval.html',
                {
                    'group': group.name,
                    'manage_url': request.build_absolute_uri(
                        reverse('manage:approvals')
                    ),
                    'title': event.title,
                    'creator': event.creator.email,
                    'datetime': event.start_time,
                    'description': event.description
                }
            )
            email = EmailMessage(subject, message,
                                 settings.EMAIL_FROM_ADDRESS, emails)
            email.send()
        for approval in approvals_remove:
            app = Approval.objects.get(group=approval, event=event)
            app.delete()
Exemple #15
0
    def test_event(self):
        """Event view page loads correctly if the event is public and
           scheduled and approved; request a login otherwise."""
        event = Event.objects.get(title='Test event')
        group = Group.objects.get()
        approval = Approval(event=event, group=group)
        approval.save()
        event_page = reverse('main:event', kwargs={'slug': event.slug})
        response_fail_approval = self.client.get(event_page)
        eq_(response_fail_approval.status_code, 200)
        ok_('not approved' in response_fail_approval.content)
        approval.approved = True
        approval.processed = True
        approval.save()
        response_ok = self.client.get(event_page)
        eq_(response_ok.status_code, 200)
        event.privacy = Event.PRIVACY_COMPANY
        event.save()
        response_fail = self.client.get(event_page)
        self.assertRedirects(response_fail, reverse('main:login'))
        event.privacy = Event.PRIVACY_CONTRIBUTORS
        event.save()
        response_fail = self.client.get(event_page)
        self.assertRedirects(response_fail, reverse('main:login'))
        event.privacy = Event.PRIVACY_PUBLIC
        event.status = Event.STATUS_INITIATED
        event.save()
        response_fail = self.client.get(event_page)
        eq_(response_fail.status_code, 200)
        ok_('not scheduled' in response_fail.content)

        self.client.logout()
        event.privacy = Event.PRIVACY_COMPANY
        event.status = Event.STATUS_SCHEDULED
        event.save()
        response_fail = self.client.get(event_page)
        self.assertRedirects(response_fail, reverse('main:login'))

        nigel = User.objects.create_user('nigel', '*****@*****.**', 'secret')
        UserProfile.objects.create(user=nigel, contributor=True)
        assert self.client.login(username='******', password='******')

        response_fail = self.client.get(event_page)
        self.assertRedirects(response_fail, reverse('main:login'))

        event.privacy = Event.PRIVACY_CONTRIBUTORS
        event.save()
        response_ok = self.client.get(event_page)
        eq_(response_ok.status_code, 200)
    def test_event(self):
        """Event view page loads correctly if the event is public and
           scheduled and approved; request a login otherwise."""
        event = Event.objects.get(title="Test event")
        group = Group.objects.get()
        approval = Approval(event=event, group=group)
        approval.save()
        event_page = reverse("main:event", kwargs={"slug": event.slug})
        response_fail_approval = self.client.get(event_page)
        eq_(response_fail_approval.status_code, 200)
        ok_("not approved" in response_fail_approval.content)
        approval.approved = True
        approval.processed = True
        approval.save()
        response_ok = self.client.get(event_page)
        eq_(response_ok.status_code, 200)
        event.privacy = Event.PRIVACY_COMPANY
        event.save()
        response_fail = self.client.get(event_page)
        self.assertRedirects(response_fail, reverse("main:login"))
        event.privacy = Event.PRIVACY_CONTRIBUTORS
        event.save()
        response_fail = self.client.get(event_page)
        self.assertRedirects(response_fail, reverse("main:login"))
        event.privacy = Event.PRIVACY_PUBLIC
        event.status = Event.STATUS_INITIATED
        event.save()
        response_fail = self.client.get(event_page)
        eq_(response_fail.status_code, 200)
        ok_("not scheduled" in response_fail.content)

        self.client.logout()
        event.privacy = Event.PRIVACY_COMPANY
        event.status = Event.STATUS_SCHEDULED
        event.save()
        response_fail = self.client.get(event_page)
        self.assertRedirects(response_fail, reverse("main:login"))

        nigel = User.objects.create_user("nigel", "*****@*****.**", "secret")
        UserProfile.objects.create(user=nigel, contributor=True)
        assert self.client.login(username="******", password="******")

        response_fail = self.client.get(event_page)
        self.assertRedirects(response_fail, reverse("main:login"))

        event.privacy = Event.PRIVACY_CONTRIBUTORS
        event.save()
        response_ok = self.client.get(event_page)
        eq_(response_ok.status_code, 200)
Exemple #17
0
def _event_process(request, form, event):
    """Generate and clean associated event data for an event request
       or event edit:  timezone application, approvals update and
       notifications, creator and modifier."""
    if not event.creator:
        event.creator = request.user
    event.modified_user = request.user
    tz = pytz.timezone(request.POST['timezone'])
    event.start_time = tz_apply(event.start_time, tz)
    if event.archive_time:
        event.archive_time = tz_apply(event.archive_time, tz)
    if 'approvals' in form.cleaned_data:
        event.save()
        approvals_old = [app.group for app in event.approval_set.all()]
        approvals_new = form.cleaned_data['approvals']
        approvals_add = set(approvals_new).difference(approvals_old)
        approvals_remove = set(approvals_old).difference(approvals_new)
        for approval in approvals_add:
            group = Group.objects.get(name=approval)
            app = Approval(group=group, event=event)
            app.save()
            emails = [u.email for u in group.user_set.all()]
            subject = ('[Air Mozilla] Approval requested: "%s"' % event.title)
            message = render_to_string(
                'manage/_email_approval.html', {
                    'group':
                    group.name,
                    'manage_url':
                    request.build_absolute_uri(reverse('manage:approvals')),
                    'title':
                    event.title,
                    'creator':
                    event.creator.email,
                    'datetime':
                    event.start_time,
                    'description':
                    event.description
                })
            email = EmailMessage(subject, message, settings.EMAIL_FROM_ADDRESS,
                                 emails)
            email.send()
        for approval in approvals_remove:
            app = Approval.objects.get(group=approval, event=event)
            app.delete()