Exemplo n.º 1
0
  def test_draft_rollover(self):
    """ scenario: take complete draft, make it belong to new org, rollover to cycle 1
        verify:
          success (status code & template)
          new draft created
          new draft contents = old draft contents (ignoring cycle q)
          new draft files = old draft files  """

    draft = DraftGrantApplication.objects.get(pk=2)
    draft.organization = Organization.objects.get(pk=1)
    draft.save()
    # prior to rollover, make sure target draft does not exist
    self.assertEqual(0,
        DraftGrantApplication.objects.filter(organization_id=1, grant_cycle_id=1).count())

    response = self.client.post('/apply/copy',
        {'cycle': '1', 'draft': '2', 'application': ''}, follow=True)

    self.assertEqual(response.status_code, 200)
    self.assertTemplateUsed(response, 'grants/org_app.html')
    self.assertEqual(1,
        DraftGrantApplication.objects.filter(organization_id=1, grant_cycle_id=1).count())
    new_draft = DraftGrantApplication.objects.get(organization_id=1, grant_cycle_id=1)
    old_contents = json.loads(draft.contents)
    old_cycle_q = old_contents.pop('cycle_question', None)
    new_contents = json.loads(new_draft.contents)
    new_cycle_q = new_contents.pop('cycle_question', '')
    self.assertEqual(old_contents, new_contents)
    self.assertNotEqual(old_cycle_q, new_cycle_q)
    for field in GrantApplication.file_fields():
      if hasattr(draft, field):
        self.assertEqual(getattr(draft, field), getattr(new_draft, field))
Exemplo n.º 2
0
    def test_draft_rollover(self):
        draft = factories.DraftGrantApplication(organization=self.org)
        target_cycle = factories.GrantCycle(status='open')

        response = self.client.post('/apply/copy', {
            'cycle': target_cycle.pk,
            'draft': draft.pk,
            'application': ''
        },
                                    follow=True)

        ids = {
            'organization_id': self.org.pk,
            'grant_cycle_id': target_cycle.pk
        }
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'grants/org_app.html')

        new_draft = DraftGrantApplication.objects.get(**ids)
        old_contents = json.loads(draft.contents)
        new_contents = json.loads(new_draft.contents)
        self.assertEqual(old_contents, new_contents)
        for field in GrantApplication.file_fields():
            if hasattr(draft, field):
                self.assertEqual(getattr(draft, field),
                                 getattr(new_draft, field))
Exemplo n.º 3
0
  def test_merge_both_have_objs(self):
    cycles = factories.GrantCycle.create_batch(5)

    a = factories.Organization()
    factories.GrantApplication.create_batch(2, organization=a)
    factories.SponsoredProgramGrant(organization=a)

    b = factories.Organization()
    app = factories.GrantApplication(organization=b)

    # get draft & app IDs that were associated with secondary org
    sec_apps = list(sec_org.grantapplication_set.values_list('pk', flat=True))
    sec_drafts = list(sec_org.draftgrantapplication_set.values_list('pk', flat=True))
    sec_papps = ProjectApp.objects.filter(application__organization_id=sec)
    self.assert_length(sec_apps, 2)
    self.assert_length(sec_drafts, 2)
    self.assert_count(sec_papps, 1)
    sponsored = SponsoredProgramGrant(organization_id=sec, amount=400)
    sponsored.save()

    # create app for primary org
    app = GrantApplication(organization_id=primary, grant_cycle_id=4,
        founded='1998', budget_last=300, budget_current=600, amount_requested=99)
    app.save()
    papp = ProjectApp(application_id=app.pk, giving_project_id=3)
    papp.save()
    gpg = GivingProjectGrant(projectapp_id=papp.pk, amount=199, first_report_due='2017-01-03')
    gpg.save()

    url = reverse('sjfnw.grants.views.merge_orgs', kwargs={'id_a': sec, 'id_b': primary})
    post_data = {'primary': primary}
    res = self.client.post(url, post_data, follow=True)

    self.assertEqual(res.status_code, 200)
    self.assertTemplateUsed(res, 'admin/change_form.html')
    self.assert_message(res, 'Merge successful. Redirected to new organization page')

    apps = GrantApplication.objects.filter(organization_id=primary)
    drafts = DraftGrantApplication.objects.filter(organization_id=primary)
    papps = ProjectApp.objects.filter(application__organization_id=primary)
    sponsored = SponsoredProgramGrant.objects.filter(organization_id=primary)
    self.assert_length(apps, 3)
    self.assert_length(drafts, 2)
    self.assert_count(papps, 2)
    self.assert_count(sponsored, 1)
Exemplo n.º 4
0
  def test_merge_both_have_objs(self):

    primary = 1
    sec = 2
    sec_org = Organization.objects.get(pk=sec)

    # get draft & app IDs that were associated with secondary org
    sec_apps = list(sec_org.grantapplication_set.values_list('pk', flat=True))
    sec_drafts = list(sec_org.draftgrantapplication_set.values_list('pk', flat=True))
    sec_papps = ProjectApp.objects.filter(application__organization_id=sec)
    self.assert_length(sec_apps, 2)
    self.assert_length(sec_drafts, 2)
    self.assert_count(sec_papps, 1)
    sponsored = SponsoredProgramGrant(organization_id=sec, amount=400)
    sponsored.save()

    # create app for primary org
    app = GrantApplication(organization_id=primary, grant_cycle_id=4,
        founded='1998', budget_last=300, budget_current=600, amount_requested=99)
    app.save()
    papp = ProjectApp(application_id=app.pk, giving_project_id=3)
    papp.save()
    gpg = GivingProjectGrant(projectapp_id=papp.pk, amount=199, first_yer_due='2017-01-03')
    gpg.save()

    url = reverse('sjfnw.grants.views.merge_orgs', kwargs={'id_a': sec, 'id_b': primary})
    post_data = {'primary': primary}
    res = self.client.post(url, post_data, follow=True)

    self.assertEqual(res.status_code, 200)
    self.assertTemplateUsed(res, 'admin/change_form.html')
    self.assert_message(res, 'Merge successful. Redirected to new organization page')

    apps = GrantApplication.objects.filter(organization_id=primary)
    drafts = DraftGrantApplication.objects.filter(organization_id=primary)
    papps = ProjectApp.objects.filter(application__organization_id=primary)
    sponsored = SponsoredProgramGrant.objects.filter(organization_id=primary)
    self.assert_length(apps, 3)
    self.assert_length(drafts, 2)
    self.assert_count(papps, 2)
    self.assert_count(sponsored, 1)
Exemplo n.º 5
0
  def test_start_conflicting_apps(self):
    a_pk = 1
    b_pk = 2

    # a has no drafts - rules out conflict over drafts
    self.assert_count(DraftGrantApplication.objects.filter(organization_id=a_pk), 0)

    # b has app; create draft for same cycle for a
    self.assert_count(
      GrantApplication.objects.filter(organization_id=b_pk, grant_cycle_id=5), 1)
    app = GrantApplication(organization_id=a_pk, grant_cycle_id=5,
        founded='1978', budget_last=300, budget_current=600, amount_requested=99)
    app.save()

    post_data = {
      'action': 'merge',
      '_selected_action': [1, 2]
    }
    res = self.client.post(self.admin_url, post_data, follow=True)

    self.assertTemplateUsed(res, 'admin/grants/organization/change_list.html')
    self.assert_message(res, r'same grant cycle. Cannot be automatically merged.$', regex=True)