예제 #1
0
 def test_returns_apps_opened_by_other_org(self, slack):
     # assume we have a multi-org app opened by a user from one org
     cc_pubdef = Organization.objects.get(
         slug=constants.Organizations.COCO_PUBDEF)
     a_pubdef = Organization.objects.get(
         slug=constants.Organizations.ALAMEDA_PUBDEF)
     cc_pubdef_user = UserProfile.objects.filter(
         organization=cc_pubdef).first().user
     sub = FormSubmission.objects.annotate(
         org_count=Count('organizations')).filter(org_count__gte=3).first()
     SubmissionsService.mark_opened(sub, cc_pubdef_user)
     # assert that it shows up in unopened apps
     self.assertEqual(
         True,
         sub.applications.filter(
             organization=cc_pubdef).first().has_been_opened)
     self.assertFalse(
         False,
         all([
             app.has_been_opened for app in sub.applications.exclude(
                 organization=cc_pubdef)]))
     cc_pubdef_subs = \
         SubmissionsService.get_unopened_submissions_for_org(cc_pubdef)
     a_pubdef_subs = \
         SubmissionsService.get_unopened_submissions_for_org(a_pubdef)
     self.assertIn(sub, a_pubdef_subs)
     self.assertNotIn(sub, cc_pubdef_subs)
예제 #2
0
 def test_returns_apps_opened_by_other_org(self, slack):
     # assume we have a multi-org app opened by a user from one org
     cc_pubdef = Organization.objects.get(
         slug=constants.Organizations.COCO_PUBDEF)
     a_pubdef = Organization.objects.get(
         slug=constants.Organizations.ALAMEDA_PUBDEF)
     cc_pubdef_user = UserProfile.objects.filter(
         organization=cc_pubdef).first().user
     sub = FormSubmission.objects.annotate(
         org_count=Count('organizations')).filter(org_count__gte=3).first()
     SubmissionsService.mark_opened(sub, cc_pubdef_user)
     # assert that it shows up in unopened apps
     self.assertEqual(
         True,
         sub.applications.filter(
             organization=cc_pubdef).first().has_been_opened)
     self.assertFalse(
         False,
         all([
             app.has_been_opened
             for app in sub.applications.exclude(organization=cc_pubdef)
         ]))
     cc_pubdef_subs = \
         SubmissionsService.get_unopened_submissions_for_org(cc_pubdef)
     a_pubdef_subs = \
         SubmissionsService.get_unopened_submissions_for_org(a_pubdef)
     self.assertIn(sub, a_pubdef_subs)
     self.assertNotIn(sub, cc_pubdef_subs)
예제 #3
0
 def test_returns_all_apps_if_no_open_events(self):
     ebclc = Organization.objects.get(slug=constants.Organizations.EBCLC)
     for org in Organization.objects.filter(is_receiving_agency=True):
         subs = SubmissionsService.get_unopened_submissions_for_org(org)
         if org == ebclc:
             self.assertEqual(subs.count(), 2)
         else:
             self.assertEqual(subs.count(), 3)
예제 #4
0
 def test_returns_apps_opened_by_other_org(self):
     # assume we have a multi-org app opened by a user from one org
     cc_pubdef = Organization.objects.get(
         slug=constants.Organizations.COCO_PUBDEF)
     a_pubdef = Organization.objects.get(
         slug=constants.Organizations.ALAMEDA_PUBDEF)
     cc_pubdef_user = UserProfile.objects.filter(
             organization=cc_pubdef).first().user
     sub = FormSubmission.objects.annotate(
         org_count=Count('organizations')).filter(org_count__gte=3).first()
     ApplicationLogEntry.log_opened([sub.id], cc_pubdef_user)
     # assert that it shows up in unopened apps
     cc_pubdef_subs = \
         SubmissionsService.get_unopened_submissions_for_org(cc_pubdef)
     a_pubdef_subs = \
         SubmissionsService.get_unopened_submissions_for_org(a_pubdef)
     self.assertIn(sub, a_pubdef_subs)
     self.assertNotIn(sub, cc_pubdef_subs)
예제 #5
0
 def test_returns_all_apps_if_no_open_events(self):
     ebclc = Organization.objects.get(
         slug=constants.Organizations.EBCLC)
     for org in Organization.objects.filter(
             is_receiving_agency=True):
         subs = SubmissionsService.get_unopened_submissions_for_org(org)
         if org == ebclc:
             self.assertEqual(subs.count(), 2)
         else:
             self.assertEqual(subs.count(), 3)
예제 #6
0
 def test_deleted_opened_app_doesnt_inhibit_return_of_other_apps(
         self, from_logs):
     # https://code.djangoproject.com/ticket/25467?cversion=0&cnum_hist=2
     sf_pubdef = Organization.objects.get(
         slug=constants.Organizations.SF_PUBDEF)
     sf_pubdef_user = UserProfile.objects.filter(
         organization=sf_pubdef).first().user
     logs = ApplicationLogEntry.log_opened([None], user=sf_pubdef_user)
     self.assertTrue(logs[0].id)
     self.assertIsNone(logs[0].submission_id)
     unopened_subs = \
         SubmissionsService.get_unopened_submissions_for_org(sf_pubdef)
     self.assertEqual(unopened_subs.count(), 3)
예제 #7
0
 def test_deleted_opened_app_doesnt_inhibit_return_of_other_apps(
         self, from_logs):
     # https://code.djangoproject.com/ticket/25467?cversion=0&cnum_hist=2
     sf_pubdef = Organization.objects.get(
         slug=constants.Organizations.SF_PUBDEF)
     sf_pubdef_user = UserProfile.objects.filter(
         organization=sf_pubdef).first().user
     logs = ApplicationLogEntry.log_opened([None], user=sf_pubdef_user)
     self.assertTrue(logs[0].id)
     self.assertIsNone(logs[0].submission_id)
     unopened_subs = \
         SubmissionsService.get_unopened_submissions_for_org(sf_pubdef)
     self.assertEqual(unopened_subs.count(), 3)
예제 #8
0
def create_bundles_and_send_notifications_to_orgs():
    orgs = get_orgs_that_might_need_a_bundle_email_today()
    for org in orgs:
        emails = org.get_referral_emails()
        subs = list(SubmissionsService.get_unopened_submissions_for_org(org))
        if subs:
            ids = [sub.id for sub in subs]
            bundle = create_bundle_from_submissions(subs, organization=org)
            bundle_url = bundle.get_external_url()
            notifications.front_email_daily_app_bundle.send(
                to=emails, count=len(subs), bundle_url=bundle_url)
            ApplicationLogEntry.log_referred(ids, user=None, organization=org)
            notifications.slack_app_bundle_sent.send(submissions=subs,
                                                     emails=emails,
                                                     bundle_url=bundle_url)
예제 #9
0
def create_bundles_and_send_notifications_to_orgs():
    orgs = get_orgs_that_might_need_a_bundle_email_today()
    for org in orgs:
        emails = org.get_referral_emails()
        subs = list(SubmissionsService.get_unopened_submissions_for_org(org))
        if subs:
            bundle = create_bundle_from_submissions(subs, organization=org)
            bundle_url = bundle.get_external_url()
            notifications.front_email_daily_app_bundle.send(
                to=emails,
                count=len(subs),
                bundle_url=bundle_url,
                app_index_url=external_reverse('intake-app_index'))
            notifications.slack_app_bundle_sent.send(
                submissions=subs,
                emails=emails,
                bundle_url=bundle_url,
            )
예제 #10
0
 def test_uses_only_one_query(self):
     org = Organization.objects.filter(
         is_receiving_agency=True).first()
     subs = SubmissionsService.get_unopened_submissions_for_org(org)
     with self.assertNumQueries(1):
         list(subs)
예제 #11
0
 def test_uses_only_one_query(self):
     org = Organization.objects.filter(
         is_receiving_agency=True).first()
     subs = SubmissionsService.get_unopened_submissions_for_org(org)
     with self.assertNumQueries(1):
         list(subs)