Beispiel #1
0
    def test_second_report_reminder(self):
        """ Verify that reminder email is sent if second grantee report due"""

        today = timezone.now().date()

        giving_project_grant = factories.GivingProjectGrant(
            first_report_due=(today - timedelta(days=97)),
            second_report_due=(today + timedelta(days=7)),
        )

        self.assertEqual(giving_project_grant.next_report_due(),
                         giving_project_grant.first_report_due)

        # submit first report
        report = factories.GranteeReport(
            giving_project_grant=giving_project_grant)

        # verify that second report is due in 7 days
        self.assertEqual(giving_project_grant.next_report_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)
Beispiel #2
0
    def test_submit(self):
        """ Verify that rollover submit works:
      New draft is created for the selected giving_project_grant
      User is redirected to edit draft """

        # create giving_project_grant and report
        giving_project_grant = factories.GivingProjectGrant(
            projectapp__application__organization=self.org)
        report = factories.GranteeReport(
            giving_project_grant=giving_project_grant)
        # create 2nd giving_project_grant without report
        giving_project_grant2 = factories.GivingProjectGrant(
            projectapp__application__organization=self.org)

        self.assertFalse(
            models.GranteeReportDraft.objects.filter(
                giving_project_grant=giving_project_grant2).exists())

        post_data = {
            'report': report.pk,
            'giving_project_grant': giving_project_grant2.pk
        }

        res = self.client.post(self.url, post_data)

        self.assertEqual(res.status_code, 302)
        self.assertTrue(
            res.url.endswith(_get_report_url(giving_project_grant2.pk)))
        self.assertTrue(
            models.GranteeReportDraft.objects.filter(
                giving_project_grant=giving_project_grant2).exists())
Beispiel #3
0
    def test_start_second_report(self):
        giving_project_grant = factories.GivingProjectGrant(
            projectapp__application__organization=self.org, second_amount=8000)
        report = factories.GranteeReport(
            giving_project_grant=giving_project_grant)

        self.assertFalse(
            models.GranteeReportDraft.objects.filter(
                giving_project_grant=giving_project_grant).exists())

        res = self.client.get(_get_report_url(giving_project_grant.pk))

        self.assertTemplateUsed(res, 'grants/grantee_report_form.html')
        expected_title = 'Grantee Report for {:%b %d, %Y} - {:%b %d, %Y}'.format(
            giving_project_grant.first_report_due,
            giving_project_grant.first_report_due.replace(
                year=giving_project_grant.first_report_due.year + 1))
        self.assertContains(res, expected_title)

        application = giving_project_grant.projectapp.application
        self.assertEqual(res.context['form']['website'].value(),
                         application.website)
        self.assert_count(
            models.GranteeReportDraft.objects.filter(
                giving_project_grant=giving_project_grant), 1)
Beispiel #4
0
    def test_two_completed(self):
        # two year giving_project_grant with both report submitted
        giving_project_grant = factories.GivingProjectGrant(
            projectapp__application__organization=self.org,
            amount=8000,
            second_amount=4000,
            first_report_due=timezone.now() - timedelta(days=200))
        factories.GranteeReport(giving_project_grant=giving_project_grant)
        factories.GranteeReport(giving_project_grant=giving_project_grant)

        res = self.client.get(self.url)

        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed('grants/org_home.html')
        self.assertContains(res, 'Grantee report</a> submitted', count=2)
        self.assertNotContains(
            res,
            '<a href="{}>'.format(_get_report_url(giving_project_grant.pk)))
Beispiel #5
0
    def test_not_logged_in(self):
        report = factories.GranteeReport()

        url = reverse(views.view_grantee_report,
                      kwargs={'report_id': report.pk})
        res = self.client.get(url, follow=True)

        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'grants/org_login.html')
Beispiel #6
0
    def test_second_report_complete(self):
        """ Verify that reminder email is not sent if second grantee report completed"""

        today = timezone.now()
        giving_project_grant = factories.GivingProjectGrant(
            first_report_due=(today +
                              timedelta(days=7)).replace(year=today.year - 1),
            second_amount=9000)
        factories.GranteeReport(giving_project_grant=giving_project_grant)
        factories.GranteeReport(giving_project_grant=giving_project_grant)

        self.assertEqual(giving_project_grant.next_report_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)
Beispiel #7
0
    def test_display_second_yr_missing(self):
        """ Verify form if org has completed one but not both reports for their grant """
        giving_project_grant = factories.GivingProjectGrant(
            projectapp__application__organization=self.org, second_amount=8000)
        factories.GranteeReport(giving_project_grant=giving_project_grant)

        res = self.client.get(self.url, follow=True)
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'grants/report_rollover.html')
        self.assertContains(res, 'option value', count=4)
        self.assertContains(res, 'This form lets you')
Beispiel #8
0
 def test_valid(self):
   award = factories.GivingProjectGrant()
   report = factories.GranteeReport(giving_project_grant=award)
   cycle_report_question = models.CycleReportQuestion.objects.filter(
     grant_cycle=award.projectapp.application.grant_cycle).first()
   answer = models.ReportAnswer(
     cycle_report_question=cycle_report_question,
     grantee_report=report,
     text='Here is my answer'
   )
   self.assertEqual(answer.get_question_text(), cycle_report_question.report_question.text)
Beispiel #9
0
    def test_org_author(self):
        self.login_as_org()
        report = factories.GranteeReport(
            giving_project_grant__projectapp__application__organization=self.
            org)

        url = reverse(views.view_grantee_report,
                      kwargs={'report_id': report.pk})
        res = self.client.get(url)

        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'grants/view_grantee_report.html')
Beispiel #10
0
    def test_other_org(self):
        self.login_as_org()
        app = factories.GrantApplication()
        report = factories.GranteeReport(
            giving_project_grant__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, 'grantee report')
Beispiel #11
0
    def test_display_all_reports_done(self):
        """ Verify error msg, no form if org has reports for all grants """
        giving_project_grant = factories.GivingProjectGrant(
            projectapp__application__organization=self.org)
        factories.GranteeReport(giving_project_grant=giving_project_grant)

        res = self.client.get(self.url, follow=True)
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'grants/report_rollover.html')
        self.assertRegexpMatches(
            res.context['error_msg'],
            'You have a submitted or draft year-end report for all of your grants'
        )
Beispiel #12
0
    def test_second_home_link(self):
        # make giving_project_grant be two-year
        giving_project_grant = factories.GivingProjectGrant(
            projectapp__application__organization=self.org,
            amount=8000,
            second_amount=4000,
            first_report_due=timezone.now() - timedelta(days=20),
            second_report_due=timezone.now() + timedelta(days=15))
        # submit first report
        first_report = factories.GranteeReport(
            giving_project_grant=giving_project_grant)

        res = self.client.get(self.url)

        self._assert_link(res, giving_project_grant)
        self.assertContains(res, 'Grantee report</a> submitted', count=1)
Beispiel #13
0
    def test_report_complete(self):
        """ Verify that an email is not sent if a year-end report has been completed """

        # create giving_project_grant where report is due in 7 days, with report completed
        giving_project_grant = factories.GivingProjectGrant(
            first_report_due=timezone.now().date() + timedelta(days=7))
        report = factories.GranteeReport(
            giving_project_grant=giving_project_grant)

        # verify that no more are due
        self.assertEqual(giving_project_grant.next_report_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)
Beispiel #14
0
    def test_display_form(self):
        """ Verify display of form when there is a valid rollover option """

        # create giving_project_grant and report
        giving_project_grant = factories.GivingProjectGrant(
            projectapp__application__organization=self.org)
        factories.GranteeReport(giving_project_grant=giving_project_grant)

        # create 2nd giving_project_grant without report
        giving_project_grant = 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/report_rollover.html')
        self.assertContains(res, 'option value', count=4)
        self.assertContains(res, 'This form lets you')
Beispiel #15
0
 def setUp(self):
     super(GrantReading, self).setUp()
     award = factories.GivingProjectGrant(first_report_due=timezone.now())
     report = factories.GranteeReport(giving_project_grant=award)
     self.report_id = report.pk