def test_post_comment_on_report(self): """Test post comment on report.""" # Test with anonymous user. c = Client() ReportFactory.create(user=self.user, empty=True, mentor=self.mentor, month=datetime.date(2012, 1, 1)) report_view_url = reverse('reports_view_report', kwargs={'display_name': self.up.display_name, 'year': '2012', 'month': 'January'}) response = c.post(report_view_url, {'comment': 'This is comment'}, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'error') # Test with logged in user. c.login(username='******', password='******') response = c.post(report_view_url, {'comment': 'This is comment'}, follow=True) self.assertTemplateUsed(response, 'view_report.html') for m in response.context['messages']: pass eq_(m.tags, u'success') self.assertIn('This is comment', response.content)
def test_post_comment_on_report(self): """Test post comment on report.""" # Test with anonymous user. c = Client() ReportFactory.create(user=self.user, empty=True, mentor=self.mentor, month=datetime.date(2012, 1, 1)) report_view_url = reverse('reports_view_report', kwargs={ 'display_name': self.up.display_name, 'year': '2012', 'month': 'January' }) response = c.post(report_view_url, {'comment': 'This is comment'}, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'error') # Test with logged in user. c.login(username='******', password='******') response = c.post(report_view_url, {'comment': 'This is comment'}, follow=True) self.assertTemplateUsed(response, 'view_report.html') for m in response.context['messages']: pass eq_(m.tags, u'success') self.assertIn('This is comment', response.content)
def test_send_email_on_edit_report_with_receive_mail_True(self): """Test sending an email when a report is edited and Mentor has the option in his/her settings enabled. """ self.mentor_profile.receive_email_on_edit_report = True self.mentor_profile.save() ReportFactory.create(user=self.user, mentor=self.mentor) eq_(len(mail.outbox), 1)
def test_send_email_on_edit_report_with_receive_mail_False(self): """Test sending an email when a report is edited. Default option: False """ self.mentor_profile.receive_email_on_edit_report = False self.mentor_profile.receive_email_on_add_report = False self.mentor_profile.save() ReportFactory.create(user=self.user, mentor=self.mentor) eq_(len(mail.outbox), 0)
def setUp(self): """Initialize data for the tests.""" self.mentor = UserFactory.create(username='******', groups=['Mentor']) self.user = UserFactory.create( username='******', groups=['Rep'], userprofile__mentor=self.mentor, userprofile__date_joined_program=date(2011, 1, 1)) ReportFactory.create(user=self.user, month=date(2012, 1, 1), empty=False, overdue=True) ReportFactory.create(user=self.user, month=date(2012, 2, 1), empty=True, overdue=False)
def test_delete_report(self): """Test delete report.""" c = Client() ReportFactory.create(user=self.user, empty=True, mentor=self.mentor, month=datetime.date(2012, 2, 1)) delete_url = reverse('reports_delete_report', kwargs={ 'display_name': self.up.display_name, 'year': '2012', 'month': 'February' }) tmp_data = self.data.copy() tmp_data['delete_report'] = True # Test with anonymous user. response = c.post(delete_url, tmp_data, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'warning') # Test with logged in user. c.login(username='******', password='******') response = c.post(delete_url, tmp_data, 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, tmp_data, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'error') # Test with mentor. c.login(username='******', password='******') response = c.post(delete_url, tmp_data, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'error') # Test with admin. c.login(username='******', password='******') response = c.post(delete_url, tmp_data, follow=True) self.assertTemplateUsed(response, 'profiles_view.html') for m in response.context['messages']: pass eq_(m.tags, u'success')
def test_view_report_page(self): """Test view report page.""" # check that there is comment # check that there is comment form ReportFactory.create(user=self.user, empty=True, mentor=self.mentor, month=datetime.date(2012, 1, 1)) c = Client() response = c.get(reverse('reports_view_report', kwargs={'display_name': self.up.display_name, 'year': '2012', 'month': 'January'})) self.assertTemplateUsed(response, 'view_report.html')
def test_delete_report(self): """Test delete report.""" c = Client() ReportFactory.create(user=self.user, empty=True, mentor=self.mentor, month=datetime.date(2012, 2, 1)) delete_url = reverse('reports_delete_report', kwargs={'display_name': self.up.display_name, 'year': '2012', 'month': 'February'}) tmp_data = self.data.copy() tmp_data['delete_report'] = True # Test with anonymous user. response = c.post(delete_url, tmp_data, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'warning') # Test with logged in user. c.login(username='******', password='******') response = c.post(delete_url, tmp_data, 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, tmp_data, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'error') # Test with mentor. c.login(username='******', password='******') response = c.post(delete_url, tmp_data, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'error') # Test with admin. c.login(username='******', password='******') response = c.post(delete_url, tmp_data, follow=True) self.assertTemplateUsed(response, 'profiles_view.html') for m in response.context['messages']: pass eq_(m.tags, u'success')
def test_view_edit_report_page(self): """Test view edit report page.""" # test my edit report # test without permission other user's # test with permission other user's # test with report from the future ReportFactory.create(user=self.user, empty=True, mentor=self.mentor, month=datetime.date(2011, 2, 1)) edit_page_url = reverse('reports_edit_report', kwargs={ 'display_name': self.up.display_name, 'year': '2011', 'month': 'February' }) # Try to access edit report page as anonymous. c = Client() response = c.get(edit_page_url, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'warning') # Try to access edit report page as owner. c.login(username='******', password='******') response = c.get(edit_page_url, follow=True) self.assertTemplateUsed(response, 'edit_report.html') # Try to access edit report page as admin. c.login(username='******', password='******') response = c.get(edit_page_url, follow=True) self.assertTemplateUsed(response, 'edit_report.html') # Try to access edit report page as user's mentor. c.login(username='******', password='******') response = c.get(edit_page_url, follow=True) self.assertTemplateUsed(response, 'edit_report.html') # Try to access edit report page as other user. c.login(username='******', password='******') response = c.get(edit_page_url, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'error')
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 test_view_report_page(self): """Test view report page.""" # check that there is comment # check that there is comment form ReportFactory.create(user=self.user, empty=True, mentor=self.mentor, month=datetime.date(2012, 1, 1)) c = Client() response = c.get( reverse('reports_view_report', kwargs={ 'display_name': self.up.display_name, 'year': '2012', 'month': 'January' })) self.assertTemplateUsed(response, 'view_report.html')
def setUp(self): """Initialize data for the tests.""" self.mentor = UserFactory.create(username='******', groups=['Mentor']) self.user = UserFactory.create(username='******', groups=['Rep'], userprofile__mentor=self.mentor, userprofile__date_joined_program=date( 2011, 1, 1)) ReportFactory.create(user=self.user, month=date(2012, 1, 1), empty=False, overdue=True) ReportFactory.create(user=self.user, month=date(2012, 2, 1), empty=True, overdue=False)
def test_view_edit_report_page(self): """Test view edit report page.""" # test my edit report # test without permission other user's # test with permission other user's # test with report from the future ReportFactory.create(user=self.user, empty=True, mentor=self.mentor, month=datetime.date(2011, 2, 1)) edit_page_url = reverse('reports_edit_report', kwargs={'display_name': self.up.display_name, 'year': '2011', 'month': 'February'}) # Try to access edit report page as anonymous. c = Client() response = c.get(edit_page_url, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'warning') # Try to access edit report page as owner. c.login(username='******', password='******') response = c.get(edit_page_url, follow=True) self.assertTemplateUsed(response, 'edit_report.html') # Try to access edit report page as admin. c.login(username='******', password='******') response = c.get(edit_page_url, follow=True) self.assertTemplateUsed(response, 'edit_report.html') # Try to access edit report page as user's mentor. c.login(username='******', password='******') response = c.get(edit_page_url, follow=True) self.assertTemplateUsed(response, 'edit_report.html') # Try to access edit report page as other user. c.login(username='******', password='******') response = c.get(edit_page_url, follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'error')
def test_overdue_true_2(self, fake_requests_obj): """Test overdue report (second test).""" today = datetime.datetime.today() # act like it's OVERDUE_DAY + 1 fake_date = datetime.datetime(year=today.year, month=today.month, day=OVERDUE_DAY + 1) (fake_requests_obj.expects_call().returns(fake_date)) month_year = go_back_n_months(today) report = ReportFactory.create(user=self.user, month=month_year) eq_(report.overdue, True)
def setUp(self): """Setup tests.""" self.new_mentor = UserFactory.create(username='******', groups=['Mentor']) self.user_mentor = UserFactory.create(username='******', groups=['Mentor']) self.user = UserFactory.create(username='******', groups=['Rep'], userprofile__mentor=self.user_mentor) self.month_year = datetime.date(year=2012, month=1, day=10) self.report = ReportFactory.create(user=self.user, month=self.month_year, mentor=self.user.userprofile.mentor)
def test_view_current_report_page(self): """Test view report page.""" # If anonymous, return an error. c = Client() response = c.get(reverse('reports_view_current_report'), follow=True) self.assertTemplateUsed(response, 'main.html') for m in response.context['messages']: pass eq_(m.tags, u'warning') # Login. c.login(username='******', password='******') # If report does not exist, render edit page. response = c.get(reverse('reports_view_current_report'), follow=True) self.assertTemplateUsed(response, 'edit_report.html') # If report exists, render report. ReportFactory.create(user=self.user, empty=True, mentor=self.mentor, month=go_back_n_months(datetime.date.today())) response = c.get(reverse('reports_view_current_report'), follow=True) self.assertTemplateUsed(response, 'view_report.html')
def test_overdue_true_2(self, fake_requests_obj): """Test overdue report (second test).""" today = datetime.datetime.today() # act like it's OVERDUE_DAY + 1 fake_date = datetime.datetime(year=today.year, month=today.month, day=OVERDUE_DAY + 1) (fake_requests_obj.expects_call().returns(fake_date)) month_year = go_back_n_months(today) report = ReportFactory.create(user=self.user, month=month_year) ok_(report.overdue)
def test_overdue_false_2(self, fake_requests_obj): """Test not overdue report (first test).""" # marginal case today = datetime.datetime.today() # act like it's OVERDUE_DAY fake_date = datetime.datetime(year=today.year, month=today.month, day=OVERDUE_DAY) (fake_requests_obj.expects_call().returns(fake_date)) month_year = go_back_n_months(today) report = ReportFactory.create(user=self.user, month=month_year) eq_(report.overdue, False)
def test_overdue_false_2(self, fake_requests_obj): """Test not overdue report (first test).""" # marginal case today = datetime.datetime.today() # act like it's OVERDUE_DAY fake_date = datetime.datetime(year=today.year, month=today.month, day=OVERDUE_DAY) (fake_requests_obj.expects_call().returns(fake_date)) month_year = go_back_n_months(today) report = ReportFactory.create(user=self.user, month=month_year) ok_(not report.overdue)
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)
def test_overdue_false(self): """Test not overdue report (first test).""" # Change report created_on, so report is not overdue month_year = datetime.date(year=2020, month=1, day=10) report = ReportFactory.create(user=self.user, month=month_year) eq_(report.overdue, False)
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 test_overdue_false(self): """Test not overdue report (first test).""" # Change report created_on, so report is not overdue month_year = datetime.date(year=2020, month=1, day=10) report = ReportFactory.create(user=self.user, month=month_year) ok_(not report.overdue)