Beispiel #1
0
    def test_admin_settings(self):
        """
        Admins should have the full range of settings available.
        """
        admin = User.objects.get(username='******')
        form = forms.NotificationsForm(instance=admin)
        choice_len = len(form.CHOICES + form.ADMIN_CHOICES)
        self.assertEqual(len(form.fields['notifications'].choices), choice_len)
        self.assertEqual(
            form.initial, {
                'notifications': [
                    'video_approved', 'video_comment', 'comment_post_comment',
                    'newsletter', 'admin_new_playlist'
                ]
            })

        superuser = User.objects.get(username='******')
        form = forms.NotificationsForm(instance=superuser)
        self.assertEqual(len(form.fields['notifications'].choices), choice_len)
        self.assertEqual(
            form.initial, {
                'notifications': [
                    'video_approved', 'video_comment', 'comment_post_comment',
                    'newsletter', 'admin_new_playlist'
                ]
            })
Beispiel #2
0
def notifications(request):
    if request.method == 'POST':
        form = forms.NotificationsForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(request.path)
    else:
        form = forms.NotificationsForm(instance=request.user)

    return render_to_response('localtv/user_profile/notifications.html',
                              {'form': form},
                              context_instance=RequestContext(request))
Beispiel #3
0
 def test_save_admin_settings(self):
     """
     Saving the form should save the admin's settings.
     """
     for username in 'admin', 'superuser':
         admin = User.objects.get(username=username)
         form = forms.NotificationsForm({'notifications': [
                     'admin_new_comment',
                     'admin_new_submission',
                     'admin_new_playlist',
                     'admin_queue_daily',
                     'admin_queue_weekly']}, instance=admin)
         self.assertTrue(form.is_valid(), form.errors)
         form.save()
         for label in ('video_comment', 'video_approved',
                       'comment_post_comment'):
             notice_type = notification.NoticeType.objects.get(label=label)
             self.assertFalse(notification.should_send(admin, notice_type,
                                                       "1"))
         for label in ('admin_new_comment', 'admin_new_submission',
                       'admin_new_playlist', 'admin_queue_daily',
                       'admin_queue_weekly'):
             notice_type = notification.NoticeType.objects.get(label=label)
             self.assertTrue(notification.should_send(admin, notice_type,
                                                      "1"))
Beispiel #4
0
    def test_save_user_settings(self):
        """
        Saving the form should save the user's settings.
        """
        user = User.objects.get(username='******')
        form = forms.NotificationsForm({'notifications': []}, instance=user)
        self.assertTrue(form.is_valid(), form.errors)
        form.save()
        for label in 'video_comment', 'video_approved', 'comment_post_comment':
            notice_type = notification.NoticeType.objects.get(label=label)
            self.assertFalse(notification.should_send(user, notice_type, "1"))

        form = forms.NotificationsForm({'notifications': ['video_approved']},
                                       instance=user)
        self.assertTrue(form.is_valid(), form.errors)
        form.save()
        notice_type = notification.NoticeType.objects.get(
            label='video_approved')
        self.assertTrue(notification.should_send(user, notice_type, "1"))
Beispiel #5
0
 def test_user_settings(self):
     """
     A regular user should only see the 'video_approved' and 'video_comment'
     notifications.  The initial data for the form should have those
     settings enabled, since they're on by default.
     """
     user = User.objects.get(username='******')
     form = forms.NotificationsForm(instance=user)
     self.assertEquals(len(form.fields['notifications'].choices), 2)
     self.assertEquals(form.initial, {
             'notifications': ['video_approved', 'video_comment']
             })