Beispiel #1
0
class UserNotificationOnAddComment(TestCase):
    """Test that a user receives an email when an authenticated user
    adds a comment on a report.
    """
    fixtures = ['demo_users.json', 'demo_reports.json']

    def setUp(self):
        self.date = datetime.datetime.now()
        self.user = User.objects.get(username='******')
        self.user_profile = self.user.userprofile
        self.report = Report.objects.get(pk=1)
        self.commenter = self.user.userprofile.mentor
        self.new_comment = ReportComment(user=self.commenter,
                                         created_on=self.date,
                                         report=self.report)

    def test_send_email_on_add_comment_with_receive_mail_True(self):
        """Test sending email when a new comment is added.
        Default option: True
        """
        self.new_comment.save()
        eq_(len(mail.outbox), 1)

    def test_send_email_on_add_comment_with_receive_mail_False(self):
        """Test sending email when a new comment is added and
        user has the option disabled in his/her settings.
        """
        self.user_profile.receive_email_on_add_comment = False
        self.user_profile.save()

        self.new_comment.save()
        eq_(len(mail.outbox), 0)
Beispiel #2
0
class UserNotificationOnAddComment(TestCase):
    """Test that a user receives an email when an authenticated user
    adds a comment on a report.
    """
    fixtures = ['demo_users.json', 'demo_reports.json']

    def setUp(self):
        self.date = datetime.datetime.now()
        self.user = User.objects.get(username='******')
        self.user_profile = self.user.userprofile
        self.report = Report.objects.get(pk=1)
        self.commenter = self.user.userprofile.mentor
        self.new_comment = ReportComment(user=self.commenter,
                                         created_on=self.date,
                                         report=self.report)

    def test_send_email_on_add_comment_with_receive_mail_True(self):
        """Test sending email when a new comment is added.
        Default option: True
        """
        self.new_comment.save()
        eq_(len(mail.outbox), 1)

    def test_send_email_on_add_comment_with_receive_mail_False(self):
        """Test sending email when a new comment is added and
        user has the option disabled in his/her settings.
        """
        self.user_profile.receive_email_on_add_comment = False
        self.user_profile.save()

        self.new_comment.save()
        eq_(len(mail.outbox), 0)
Beispiel #3
0
 def setUp(self):
     self.date = datetime.datetime.now()
     self.user = User.objects.get(username='******')
     self.user_profile = self.user.userprofile
     self.report = Report.objects.get(pk=1)
     self.commenter = self.user.userprofile.mentor
     self.new_comment = ReportComment(user=self.commenter,
                                      created_on=self.date,
                                      report=self.report)
Beispiel #4
0
def view_report(request, display_name, year, month):
    """View report view."""
    month_number = utils.month2number(month)
    report = get_object_or_404(Report,
                               user__userprofile__display_name=display_name,
                               month__year=int(year),
                               month__month=month_number)

    if request.method == 'POST':
        if not request.user.is_authenticated():
            messages.error(request, 'Permission denied.')
            return redirect('main')

        report_comment = ReportComment(report=report, user=request.user)
        report_comment_form = forms.ReportCommentForm(request.POST,
                                                      instance=report_comment)
        if report_comment_form.is_valid():
            report_comment_form.save()
            messages.success(request, 'Comment saved.')

            # provide a new clean form
            report_comment_form = forms.ReportCommentForm()
    else:
        report_comment_form = forms.ReportCommentForm()

    report_url = reverse('reports_view_report',
                         kwargs={
                             'display_name': display_name,
                             'year': year,
                             'month': month
                         })

    if (request.user.groups.filter(name='Admin').exists()
            or (request.user == report.user)
            or (request.user.is_authenticated()
                and report.user in request.user.mentees.all())):
        editable = True
    else:
        editable = False

    q = Q(name='Admin') | Q(name='Council') | Q(name='Mentor')
    if (request.user.groups.filter(q).exists() or request.user == report.user):
        view_status = True
    else:
        view_status = False

    return render(
        request, 'view_report.html', {
            'pageuser': report.user,
            'user_profile': report.user.userprofile,
            'editable': editable,
            'view_status': view_status,
            'report': report,
            'month': month,
            'year': year,
            'comments': report.reportcomment_set.all(),
            'report_comment_form_url': report_url,
            'report_comment_form': report_comment_form
        })
Beispiel #5
0
 def setUp(self):
     self.date = datetime.datetime.now()
     self.user = User.objects.get(username='******')
     self.user_profile = self.user.userprofile
     self.report = Report.objects.get(pk=1)
     self.commenter = self.user.userprofile.mentor
     self.new_comment = ReportComment(user=self.commenter,
                                      created_on=self.date,
                                      report=self.report)