def test_delete_comment(self): """Test delete report comment.""" report = ReportFactory.create(user=self.user, empty=True, mentor=self.mentor, month=datetime.date(2012, 2, 1)) ReportCommentFactory.create(report=report, id=9, user=self.user) c = Client() delete_url = reverse('reports_delete_report_comment', kwargs={'display_name': self.up.display_name, 'year': '2012', 'month': 'February', 'comment_id': '9'}) # Test with anonymous user. response = c.post(delete_url, {}, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'warning') # Test with other user. c.login(username='******', password='******') response = c.post(delete_url, {}, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'error') # Test with owner. c.login(username='******', password='******') response = c.post(delete_url, {}, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'error') # Test with user's mentor. c.login(username='******', password='******') response = c.post(delete_url, {}, follow=True) self.assertTemplateUsed(response, 'view_report.html') for m in response.context['messages']: pass eq_(m.tags, u'success') ok_(not ReportComment.objects.filter(pk=9).exists()) # Test with admin. ReportCommentFactory.create(report=report, id=10, user=self.user) delete_url = reverse('reports_delete_report_comment', kwargs={'display_name': self.up.display_name, 'year': '2012', 'month': 'February', 'comment_id': '10'}) c.login(username='******', password='******') response = c.post(delete_url, {}, follow=True) self.assertTemplateUsed(response, 'view_report.html') for m in response.context['messages']: pass eq_(m.tags, u'success') ok_(not ReportComment.objects.filter(pk=10).exists())
def setUp(self): self.date = datetime.datetime.now() self.mentor = UserFactory.create( username='******', groups=['Mentor'], userprofile__receive_email_on_add_report=False) self.user = UserFactory.create(username='******', groups=['Rep'], userprofile__mentor=self.mentor) self.user_profile = self.user.userprofile self.report = ReportFactory.create(user=self.user, month=self.date, mentor=self.user.userprofile.mentor) self.new_comment = ReportCommentFactory.build(user=self.mentor, created_on=self.date, report=self.report) self.month_year = datetime.date(year=2012, month=1, day=10)