Пример #1
0
    def test_comment_multiple_users(self):
        """Test sending email when a new comment is added on a NGReport
        and the users have the option enabled in their settings.
        """
        commenter = UserFactory.create()
        reporter = UserFactory.create(
            userprofile__receive_email_on_add_comment=True)
        report = NGReportFactory.create(user=reporter)
        users_with_comments = UserFactory.create_batch(
            2, userprofile__receive_email_on_add_comment=True)
        # disconnect the signals in order to add two users in NGReportComment
        for user_obj in users_with_comments:
            NGReportCommentFactoryNoSignals.create(
                user=user_obj, report=report, comment='This is a comment')
        NGReportCommentFactory.create(user=commenter, report=report,
                                      comment='This is a comment')

        eq_(len(mail.outbox), 3)
        recipients = ['%s <%s>' % (reporter.get_full_name(), reporter.email),
                      '%s <%s>' % (users_with_comments[0].get_full_name(),
                                   users_with_comments[0].email),
                      '%s <%s>' % (users_with_comments[1].get_full_name(),
                                   users_with_comments[1].email)]
        receivers = [mail.outbox[0].to[0], mail.outbox[1].to[0],
                     mail.outbox[2].to[0]]
        eq_(set(recipients), set(receivers))
        msg = ('[Report] User {0} commented on {1}'
               .format(commenter.get_full_name(), report))
        eq_(mail.outbox[0].subject, msg)
Пример #2
0
    def test_send_email_on_report_comment_settings_True_multiple_users(self):
        """Test sending email when a new comment is added on a NGReport

        and the users have the option enabled in their settings.
        """
        commenter = UserFactory.create()
        reporter = UserFactory.create(
            userprofile__receive_email_on_add_comment=True)
        report = NGReportFactory.create(user=reporter)
        users_with_comments = UserFactory.create_batch(
            2, userprofile__receive_email_on_add_comment=True)
        # disconnect the signals in order to add two users in NGReportComment
        for user_obj in users_with_comments:
            NGReportCommentFactoryNoSignals.create(user=user_obj,
                                                   report=report,
                                                   comment='This is a comment')
        NGReportCommentFactory.create(user=commenter,
                                      report=report,
                                      comment='This is a comment')

        eq_(len(mail.outbox), 3)
        recipients = [
            reporter.email, users_with_comments[0].email,
            users_with_comments[1].email
        ]
        receivers = [
            mail.outbox[0].to[0], mail.outbox[1].to[0], mail.outbox[2].to[0]
        ]
        eq_(set(recipients), set(receivers))
        msg = ('[Report] User {0} commented on {1}'.format(
            commenter.get_full_name(), report))
        eq_(mail.outbox[0].subject, msg)
Пример #3
0
    def test_comment_multiple_users(self, mocked_mail):
        """Test sending email when a new comment is added on a NGReport
        and the users have the option enabled in their settings.
        """
        commenter = UserFactory.create()
        reporter = UserFactory.create(
            userprofile__receive_email_on_add_comment=True)
        report = NGReportFactory.create(user=reporter)
        users_with_comments = UserFactory.create_batch(
            2, userprofile__receive_email_on_add_comment=True)
        # disconnect the signals in order to add two users in NGReportComment
        with mute_signals(post_save):
            for user_obj in users_with_comments:
                NGReportCommentFactory.create(user=user_obj,
                                              report=report,
                                              comment='This is a comment')
        NGReportCommentFactory.create(user=commenter,
                                      report=report,
                                      comment='This is a comment')

        ok_(mocked_mail.called)
        eq_(mocked_mail.call_count, 3)
        msg = '[Report] User {0} commented on {1}'.format(
            commenter.get_full_name(), report)
        mocked_data = mocked_mail.call_args_list[0][1]
        eq_(mocked_data['subject'], msg)
Пример #4
0
 def test_one_user_settings_False(self, mocked_mail):
     """Test sending email when a new comment is added on a NGReport
     and the user has the option disabled in his/her settings.
     """
     comment_user = UserFactory.create()
     user = UserFactory.create(
         userprofile__receive_email_on_add_comment=False)
     report = NGReportFactory.create(user=user)
     NGReportCommentFactory.create(user=comment_user, report=report,
                                   comment='This is a comment')
     ok_(not mocked_mail.called)
Пример #5
0
 def test_one_user_settings_False(self, mocked_mail):
     """Test sending email when a new comment is added on a NGReport
     and the user has the option disabled in his/her settings.
     """
     comment_user = UserFactory.create()
     user = UserFactory.create(
         userprofile__receive_email_on_add_comment=False)
     report = NGReportFactory.create(user=user)
     NGReportCommentFactory.create(user=comment_user,
                                   report=report,
                                   comment='This is a comment')
     ok_(not mocked_mail.called)
Пример #6
0
    def test_send_email_on_report_comment_settings_False_one_user(self):
        """Test sending email when a new comment is added on a NGReport

        and the user has the option disabled in his/her settings.
        """
        comment_user = UserFactory.create()
        user = UserFactory.create(
            userprofile__receive_email_on_add_comment=False)
        report = NGReportFactory.create(user=user)
        NGReportCommentFactory.create(user=comment_user, report=report,
                                      comment='This is a comment')

        eq_(len(mail.outbox), 0)
Пример #7
0
    def test_send_email_on_report_comment_settings_False_one_user(self):
        """Test sending email when a new comment is added on a NGReport

        and the user has the option disabled in his/her settings.
        """
        comment_user = UserFactory.create()
        user = UserFactory.create(
            userprofile__receive_email_on_add_comment=False)
        report = NGReportFactory.create(user=user)
        NGReportCommentFactory.create(user=comment_user,
                                      report=report,
                                      comment='This is a comment')

        eq_(len(mail.outbox), 0)
Пример #8
0
    def test_comment_one_user(self, mocked_mail):
        """Test sending email when a new comment is added on a NGReport
        and the user has the option enabled in his/her settings.
        """
        commenter = UserFactory.create()
        reporter = UserFactory.create(userprofile__receive_email_on_add_comment=True)
        report = NGReportFactory.create(user=reporter)
        NGReportCommentFactory.create(user=commenter, report=report, comment='This is a comment')

        ok_(mocked_mail.called)
        eq_(mocked_mail.call_count, 1)
        mocked_data = mocked_mail.call_args_list[0][1]
        msg = '[Report] User {0} commented on {1}'.format(commenter.get_full_name(), report)
        eq_(mocked_data['subject'], msg)
Пример #9
0
 def test_get(self):
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     with self.login(report.user) as client:
         client.get(report_comment.get_absolute_delete_url(),
                    user=report.user)
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())
Пример #10
0
 def test_as_other_rep(self):
     user = UserFactory.create()
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     with self.login(user) as client:
         client.post(report_comment.get_absolute_delete_url(), user=user)
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())
Пример #11
0
 def test_as_admin(self, redirect_mock):
     user = UserFactory.create(groups=['Admin'])
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     self.post(user=user, url=report_comment.get_absolute_delete_url())
     ok_(not NGReportComment.objects.filter(pk=report_comment.id).exists())
     redirect_mock.assert_called_with(report.get_absolute_url())
Пример #12
0
    def test_comment_one_user(self):
        """Test sending email when a new comment is added on a NGReport
        and the user has the option enabled in his/her settings.
        """
        commenter = UserFactory.create()
        reporter = UserFactory.create(
            userprofile__receive_email_on_add_comment=True)
        report = NGReportFactory.create(user=reporter)
        NGReportCommentFactory.create(user=commenter, report=report,
                                      comment='This is a comment')

        eq_(len(mail.outbox), 1)
        eq_(reporter.email, mail.outbox[0].to[0])
        msg = ('[Report] User {0} commented on {1}'
               .format(commenter.get_full_name(), report))
        eq_(mail.outbox[0].subject, msg)
Пример #13
0
 def test_as_other_rep(self):
     user = UserFactory.create()
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     with self.login(user) as client:
         client.post(report_comment.get_absolute_delete_url(), user=user)
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())
Пример #14
0
 def test_as_owner(self, redirect_mock):
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     with self.login(report.user) as client:
         client.post(report_comment.get_absolute_delete_url(), user=report.user)
     ok_(not NGReportComment.objects.filter(pk=report_comment.id).exists())
     redirect_mock.assert_called_with(report.get_absolute_url())
Пример #15
0
 def test_as_admin(self, redirect_mock):
     user = UserFactory.create(groups=['Admin'])
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     self.post(user=user, url=report_comment.get_absolute_delete_url())
     ok_(not NGReportComment.objects.filter(pk=report_comment.id).exists())
     redirect_mock.assert_called_with(report.get_absolute_url())
Пример #16
0
 def test_as_mentor(self, redirect_mock):
     user = UserFactory.create(groups=['Mentor'])
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     with self.login(user) as client:
         client.post(report_comment.get_absolute_delete_url(), user=user)
     ok_(not NGReportComment.objects.filter(pk=report_comment.id).exists())
     redirect_mock.assert_called_with(report.get_absolute_url())
Пример #17
0
 def test_get_absolute_delete_url(self):
     report = NGReportFactory.create(
         report_date=datetime.date(2012, 01, 01), id=9999)
     report_comment = NGReportCommentFactory.create(report=report,
                                                    user=report.user)
     eq_(report_comment.get_absolute_delete_url(),
         ('/u/%s/r/2012/January/1/9999/comment/%s/delete/'
          % (report.user.userprofile.display_name, report_comment.id)))
Пример #18
0
    def test_send_email_on_report_comment_settings_True_one_user(self):
        """Test sending email when a new comment is added on a NGReport

        and the user has the option enabled in his/her settings.
        """
        commenter = UserFactory.create()
        reporter = UserFactory.create(
            userprofile__receive_email_on_add_comment=True)
        report = NGReportFactory.create(user=reporter)
        NGReportCommentFactory.create(user=commenter,
                                      report=report,
                                      comment='This is a comment')

        eq_(len(mail.outbox), 1)
        eq_(reporter.email, mail.outbox[0].to[0])
        msg = ('[Report] User {0} commented on {1}'.format(
            commenter.get_full_name(), report))
        eq_(mail.outbox[0].subject, msg)
Пример #19
0
 def test_get_absolute_delete_url(self):
     report = NGReportFactory.create(report_date=datetime.date(2012, 1, 1),
                                     id=9999)
     report_comment = NGReportCommentFactory.create(report=report,
                                                    user=report.user)
     eq_(
         report_comment.get_absolute_delete_url(),
         '/u/{0}/r/2012/January/1/9999/comment/{1}/delete/'.format(
             report.user.userprofile.display_name, report_comment.id))
Пример #20
0
    def test_comment_one_user(self, mocked_mail):
        """Test sending email when a new comment is added on a NGReport
        and the user has the option enabled in his/her settings.
        """
        commenter = UserFactory.create()
        reporter = UserFactory.create(
            userprofile__receive_email_on_add_comment=True)
        report = NGReportFactory.create(user=reporter)
        NGReportCommentFactory.create(user=commenter,
                                      report=report,
                                      comment='This is a comment')

        ok_(mocked_mail.called)
        eq_(mocked_mail.call_count, 1)
        mocked_data = mocked_mail.call_args_list[0][1]
        msg = '[Report] User {0} commented on {1}'.format(
            commenter.get_full_name(), report)
        eq_(mocked_data['subject'], msg)
Пример #21
0
    def test_comment_multiple_users(self, mocked_mail):
        """Test sending email when a new comment is added on a NGReport
        and the users have the option enabled in their settings.
        """
        commenter = UserFactory.create()
        reporter = UserFactory.create(userprofile__receive_email_on_add_comment=True)
        report = NGReportFactory.create(user=reporter)
        users_with_comments = UserFactory.create_batch(
            2, userprofile__receive_email_on_add_comment=True)
        # disconnect the signals in order to add two users in NGReportComment
        with mute_signals(post_save):
            for user_obj in users_with_comments:
                NGReportCommentFactory.create(user=user_obj, report=report,
                                              comment='This is a comment')
        NGReportCommentFactory.create(user=commenter, report=report,
                                      comment='This is a comment')

        ok_(mocked_mail.called)
        eq_(mocked_mail.call_count, 3)
        msg = '[Report] User {0} commented on {1}'.format(commenter.get_full_name(), report)
        mocked_data = mocked_mail.call_args_list[0][1]
        eq_(mocked_data['subject'], msg)
Пример #22
0
 def test_get(self):
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     with self.login(report.user) as client:
         client.get(report_comment.get_absolute_delete_url(), user=report.user)
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())
Пример #23
0
 def test_as_anonymous(self):
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     client = Client()
     client.post(report_comment.get_absolute_delete_url(), data={})
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())
Пример #24
0
 def test_get(self):
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     self.get(user=report.user,
              url=report_comment.get_absolute_delete_url())
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())
Пример #25
0
 def test_as_other_rep(self):
     user = UserFactory.create()
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     self.post(user=user, url=report_comment.get_absolute_delete_url())
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())
Пример #26
0
 def test_as_anonymous(self):
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     client = Client()
     client.post(report_comment.get_absolute_delete_url(), data={})
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())
Пример #27
0
 def test_as_other_rep(self):
     user = UserFactory.create()
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     self.post(user=user, url=report_comment.get_absolute_delete_url())
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())
Пример #28
0
 def test_get(self):
     report = NGReportFactory.create()
     report_comment = NGReportCommentFactory.create(report=report)
     self.get(user=report.user,
              url=report_comment.get_absolute_delete_url())
     ok_(NGReportComment.objects.filter(pk=report_comment.id).exists())