Example #1
0
 def test_can_create_with_org_and_sub(self):
     form_submission = models.FormSubmission.objects.first()
     organization = user_account_models.Organization.objects.get(slug="cfa")
     application = models.Application(form_submission=form_submission,
                                      organization=organization)
     application.save()
     self.assertTrue(application.id)
Example #2
0
def transfer_application(author, application, to_organization, reason):
    """Transfers an application from one organization to another.
    Returns three things as a tuple:
        - a new ApplicationTransfer instance
        - a new StatusUpdate instance
        - a new Application instance for the to_organization
    """
    transferred_status_type = models.StatusType.objects.get(slug='transferred')
    transfer_status_update = models.StatusUpdate(
        status_type=transferred_status_type,
        author_id=author.id,
        application=application)
    transfer_status_update.save()
    new_application = models.Application(
        form_submission_id=application.form_submission_id,
        organization=to_organization)
    new_application.save()
    transfer = models.ApplicationTransfer(
        status_update=transfer_status_update,
        new_application=new_application,
        reason=reason)
    transfer.save()
    application.was_transferred_out = True
    application.save()
    EventsService.app_transferred(application, new_application, author)
    EventsService.user_app_transferred(application, new_application, author)
    return transfer, transfer_status_update, new_application
Example #3
0
 def add_orgs_to_sub(self, *orgs):
     sub = self.extract_sub()
     if sub and orgs:
         applications = [
             intake_models.Application(form_submission=sub,
                                       organization_id=org_id)
             for org_id in coerce_to_ids(orgs)
         ]
         intake_models.Application.objects.bulk_create(applications)
Example #4
0
 def test_has_intended_default_fields(self):
     form_submission = models.FormSubmission.objects.first()
     organization = user_account_models.Organization.objects.get(slug="cfa")
     application = models.Application(form_submission=form_submission,
                                      organization=organization)
     application.save()
     self.assertTrue(application.updated)
     self.assertTrue(application.created)
     self.assertEqual(application.was_transferred_out, False)
Example #5
0
 def add_orgs_to_sub(self, *orgs):
     args, kwargs = self._constructor_args
     if len(args) == 1 and orgs:
         if isinstance(args[0], intake_models.FormSubmission):
             sub = args[0]
             applications = [
                 intake_models.Application(form_submission=sub,
                                           organization_id=org_id)
                 for org_id in coerce_to_ids(orgs)
             ]
             intake_models.Application.objects.bulk_create(applications)
Example #6
0
def transfer_application(author, application, to_organization, reason):
    """Transfers an application from one organization to another.
    Returns three things as a tuple:
        - a new ApplicationTransfer instance
        - a new StatusUpdate instance
        - a new Application instance for the to_organization
    """
    transfer_status_update = models.StatusUpdate(
        status_type_id=models.status_type.TRANSFERRED,
        author_id=author.id,
        application=application)
    transfer_status_update.save()
    new_application = models.Application(
        form_submission_id=application.form_submission_id,
        organization=to_organization)
    new_application.save()
    transfer = models.ApplicationTransfer(status_update=transfer_status_update,
                                          new_application=new_application,
                                          reason=reason)
    transfer.save()
    application.was_transferred_out = True
    application.save()
    return transfer, transfer_status_update, new_application
Example #7
0
def build_seed_submissions():
    create_seed_users()
    from user_accounts.models import Organization
    from formation.forms import county_form_selector
    cc_pubdef = Organization.objects.get(
        slug=constants.Organizations.COCO_PUBDEF)
    a_pubdef = Organization.objects.get(
        slug=constants.Organizations.ALAMEDA_PUBDEF)
    ebclc = Organization.objects.get(
        slug=constants.Organizations.EBCLC)
    sf_pubdef = Organization.objects.get(
        slug=constants.Organizations.SF_PUBDEF)
    monterey_pubdef = Organization.objects.get(
        slug=constants.Organizations.MONTEREY_PUBDEF)
    solano_pubdef = Organization.objects.get(
        slug=constants.Organizations.SOLANO_PUBDEF)
    san_diego_pubdef = Organization.objects.get(
        slug=constants.Organizations.SAN_DIEGO_PUBDEF)
    san_joaquin_pubdef = Organization.objects.get(
        slug=constants.Organizations.SAN_JOAQUIN_PUBDEF)
    santa_clara_pubdef = Organization.objects.get(
        slug=constants.Organizations.SANTA_CLARA_PUBDEF)
    fresno_pubdef = Organization.objects.get(
        slug=constants.Organizations.FRESNO_PUBDEF)
    receiving_orgs = [
        cc_pubdef, a_pubdef, ebclc, sf_pubdef, monterey_pubdef,
        solano_pubdef, san_diego_pubdef, san_joaquin_pubdef,
        santa_clara_pubdef, fresno_pubdef]
    answer_pairs = {
        sf_pubdef.slug: fake.sf_county_form_answers,
        cc_pubdef.slug: fake.contra_costa_county_form_answers,
        ebclc.slug: fake.ebclc_answers,
        a_pubdef.slug: fake.alameda_pubdef_answers,
        monterey_pubdef.slug: fake.monterey_pubdef_answers,
        solano_pubdef.slug: fake.solano_pubdef_answers,
        san_diego_pubdef.slug: fake.san_diego_pubdef_answers,
        san_joaquin_pubdef.slug: fake.san_joaquin_pubdef_answers,
        santa_clara_pubdef.slug: fake.santa_clara_pubdef_answers,
        fresno_pubdef.slug: fake.fresno_pubdef_answers,
    }
    form_pairs = {
        org.slug: county_form_selector.get_combined_form_class(
            counties=[org.county.slug])
        for org in receiving_orgs
    }
    # make 2 submissions to each org
    applicants = []
    subs = []
    for org in receiving_orgs:
        for i in range(2):
            raw_answers = answer_pairs[org.slug]()
            Form = form_pairs[org.slug]
            form = Form(raw_answers, validate=True)
            applicant = models.Applicant()
            applicant.save()
            applicants.append(applicant)
            sub = models.FormSubmission(
                applicant=applicant,
                answers=form.cleaned_data
                )
            if org in (a_pubdef, santa_clara_pubdef, monterey_pubdef):
                letter = fake.declaration_letter_answers()
                sub.answers.update(letter)
            sub.save()
            application = models.Application(
                organization=org, form_submission=sub)
            application.save()
            StatusUpdateFactory.create(
                application=application, author=org.profiles.first().user)
            subs.append(sub)
    # make 1 submission to multiple orgs
    target_orgs = [
        a_pubdef, cc_pubdef, sf_pubdef, monterey_pubdef, solano_pubdef,
        san_diego_pubdef, san_joaquin_pubdef, santa_clara_pubdef,
        fresno_pubdef]
    answers = fake.all_county_answers()
    Form = county_form_selector.get_combined_form_class(
        counties=[org.county.slug for org in target_orgs])
    form = Form(answers, validate=True)
    applicant = models.Applicant()
    applicant.save()
    applicants.append(applicant)
    multi_org_sub = models.FormSubmission(
            applicant=applicant, answers=form.cleaned_data)
    multi_org_sub.answers.update(fake.declaration_letter_answers())
    multi_org_sub.save()
    applications = [
        models.Application(organization=org, form_submission=multi_org_sub)
        for org in target_orgs
    ]
    models.Application.objects.bulk_create(applications)
    subs.append(multi_org_sub)
    # fake the date received for each sub
    for sub in subs:
        sub.date_received = local(fake.date_time_between('-2w', 'now'))
        sub.save()
    # make a bundle for each org
    for org in receiving_orgs:
        org_subs = []
        for sub in subs:
            has_app = sub.applications.filter(organization=org).exists()
            if has_app and sub != multi_org_sub:
                org_subs.append(sub)
        bundle = BundlesService.create_bundle_from_submissions(
            organization=org,
            submissions=org_subs,
            skip_pdf=True)
        # save bundle
        filename = 'mock_1_bundle_to_' + org.slug + ".json"
        dump_as_json([bundle], fixture_path(filename))
        filename = 'mock_{}_submissions_to_{}.json'.format(
            len(org_subs), org.slug)
        serialize_subs(org_subs, fixture_path(filename))
    serialize_subs(
        [multi_org_sub],
        fixture_path('mock_1_submission_to_multiple_orgs.json'))
    events = []
    for applicant in applicants:
        events.extend(
            make_mock_submission_event_sequence(applicant))
    dump_as_json(events, fixture_path('mock_application_events.json'))
Example #8
0
 def test_cannot_create_without_form_submission(self):
     organization = user_account_models.Organization.objects.first()
     application = models.Application(organization=organization)
     with self.assertRaises(IntegrityError):
         application.save()
Example #9
0
 def test_cannot_create_without_organization(self):
     form_submission = models.FormSubmission.objects.first()
     application = models.Application(form_submission=form_submission)
     with self.assertRaises(IntegrityError):
         application.save()