def test_two_completed(self): # two year award with both YER submitted award = factories.GivingProjectGrant( projectapp__application__organization=self.org, amount=8000, second_amount=4000, first_yer_due=timezone.now() - timedelta(days=200)) factories.YearEndReport(award=award) factories.YearEndReport(award=award) res = self.client.get(self.url) self.assertEqual(res.status_code, 200) self.assertTemplateUsed('grants/org_home.html') self.assertContains(res, 'Year end report</a> submitted', count=2) self.assertNotContains(res, '<a href="{}>'.format(_get_yer_url(award.pk)))
def test_not_logged_in(self): yer = factories.YearEndReport() url = reverse(views.view_yer, kwargs={'report_id': yer.pk}) res = self.client.get(url) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'grants/blocked.html')
def test_second_yer_complete(self): """ Verify that reminder email is not sent if second year end report completed""" today = timezone.now() award = factories.GivingProjectGrant( first_yer_due=(today + timedelta(days=7)).replace(year=today.year - 1), second_amount=9000) factories.YearEndReport(award=award) factories.YearEndReport(award=award) self.assertEqual(award.next_yer_due(), None) # verify that email is not sent self.assert_length(mail.outbox, 0) res = self.client.get(self.url) self.assertEqual(res.status_code, 200) self.assert_length(mail.outbox, 0)
def test_org_author(self): self.login_as_org() yer = factories.YearEndReport( award__projectapp__application__organization=self.org) url = reverse(views.view_yer, kwargs={'report_id': yer.pk}) res = self.client.get(url) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'grants/yer_display.html')
def test_other_org(self): self.login_as_org() app = factories.GrantApplication() yer = factories.YearEndReport(award__projectapp__application=app) res = self.client.get(self._get_url(app.pk)) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'grants/reading.html') self.assertEqual(0, res.context['perm']) self.assertNotContains(res, 'year end report')
def test_display_second_yr_missing(self): """ Verify form if org has completed one but not both reports for their grant """ award = factories.GivingProjectGrant( projectapp__application__organization=self.org, second_amount=8000) factories.YearEndReport(award=award) res = self.client.get(self.url, follow=True) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'grants/yer_rollover.html') self.assertContains(res, 'option value', count=4) self.assertContains(res, 'This form lets you')
def test_display_all_reports_done(self): """ Verify error msg, no form if org has reports for all grants """ award = factories.GivingProjectGrant( projectapp__application__organization=self.org) factories.YearEndReport(award=award) res = self.client.get(self.url, follow=True) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'grants/yer_rollover.html') self.assertRegexpMatches( res.context['error_msg'], 'You have a submitted or draft year-end report for all of your grants' )
def test_second_home_link(self): # make award be two-year award = factories.GivingProjectGrant( projectapp__application__organization=self.org, amount=8000, second_amount=4000, first_yer_due=timezone.now() - timedelta(days=20)) # submit first YER first_yer = factories.YearEndReport(award=award) res = self.client.get(self.url) self._assert_link(res, award) self.assertContains(res, 'Year end report</a> submitted', count=1)
def test_yer_complete(self): """ Verify that an email is not sent if a year-end report has been completed """ # create award where yer is due in 7 days, with YER completed award = factories.GivingProjectGrant( first_yer_due=timezone.now().date() + timedelta(days=7)) yer = factories.YearEndReport(award=award) # verify that no more are due self.assertEqual(award.next_yer_due(), None) # verify that email is not sent self.assert_length(mail.outbox, 0) res = self.client.get(self.url) self.assertEqual(res.status_code, 200) self.assert_length(mail.outbox, 0)
def test_display_form(self): """ Verify display of form when there is a valid rollover option """ # create award and YER award = factories.GivingProjectGrant( projectapp__application__organization=self.org) factories.YearEndReport(award=award) # create 2nd award without YER award = factories.GivingProjectGrant( projectapp__application__organization=self.org) res = self.client.get(self.url, follow=True) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'grants/yer_rollover.html') self.assertContains(res, 'option value', count=4) self.assertContains(res, 'This form lets you')
def test_start_second_report(self): award = factories.GivingProjectGrant( projectapp__application__organization=self.org, second_amount=8000) yer = factories.YearEndReport(award=award) self.assertFalse(models.YERDraft.objects.filter(award=award).exists()) res = self.client.get(_get_yer_url(award.pk)) self.assertTemplateUsed(res, 'grants/yer_form.html') expected_title = 'Year-end Report for {:%b %d, %Y} - {:%b %d, %Y}'.format( award.first_yer_due, award.first_yer_due.replace(year=award.first_yer_due.year + 1)) self.assertContains(res, expected_title) application = award.projectapp.application self.assertEqual(res.context['form']['website'].value(), application.website) self.assert_count(models.YERDraft.objects.filter(award=award), 1)
def test_submit(self): """ Verify that rollover submit works: New draft is created for the selected award User is redirected to edit draft """ # create award and YER award = factories.GivingProjectGrant( projectapp__application__organization=self.org) report = factories.YearEndReport(award=award) # create 2nd award without YER award2 = factories.GivingProjectGrant( projectapp__application__organization=self.org) self.assertFalse(models.YERDraft.objects.filter(award=award2).exists()) post_data = {'report': report.pk, 'award': award2.pk} res = self.client.post(self.url, post_data) self.assertEqual(res.status_code, 302) self.assertTrue(res.url.endswith(_get_yer_url(award2.pk))) self.assertTrue(models.YERDraft.objects.filter(award=award2).exists())
def test_second_yer_reminder(self): """ Verify that reminder email is sent if second year end report due""" today = timezone.now().date() award = factories.GivingProjectGrant( first_yer_due=(today + timedelta(days=7)).replace(year=today.year - 1), second_amount=9000) self.assertEqual(award.next_yer_due(), award.first_yer_due) # submit first YER yer = factories.YearEndReport(award=award) # verify that second yer is due in 7 days self.assertEqual(award.next_yer_due(), today + timedelta(days=7)) # verify that email is sent self.assert_length(mail.outbox, 0) res = self.client.get(self.url) self.assertEqual(res.status_code, 200) self.assert_length(mail.outbox, 1)
def setUp(self): super(GrantReading, self).setUp() award = factories.GivingProjectGrant(first_yer_due=timezone.now()) yer = factories.YearEndReport(award=award) self.yer_id = yer.pk