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)