示例#1
0
 def test_get_county_choices_query_default(self):
     live_org = FakeOrganizationFactory(county=factories.CountyFactory(),
                                        is_live=True)
     not_live_org = FakeOrganizationFactory(
         county=factories.CountyFactory(), is_live=False)
     not_listed = models.County.objects.get(slug='not_listed')
     results = list(models.County.objects.get_county_choices_query())
     self.assertIn(live_org.county, results)
     self.assertIn(live_org.county, results)
     self.assertNotIn(not_listed, results)
示例#2
0
    def test_get_visible_set_returns_only_live_orgs_when_only_show_live_counties_is_false(self):
        live_org = FakeOrganizationFactory(is_live=True)
        non_receiving_org = FakeOrganizationFactory(is_live=True, is_receiving_agency=False)
        not_live_org = FakeOrganizationFactory(is_live=False)

        with self.settings(ONLY_SHOW_LIVE_COUNTIES=False):
            results = models.Organization.objects.get_visible_set()
            self.assertIn(live_org, results)
            self.assertIn(non_receiving_org, results)
            self.assertIn(not_live_org, results)
示例#3
0
    def test_get_visible_organizations_returns_only_live_orgs_when_only_show_live_counties_is_true(
            self):
        county = factories.CountyFactory()
        live_org = FakeOrganizationFactory(county=county, is_live=True)
        not_live_org = FakeOrganizationFactory(county=county, is_live=False)

        with self.settings(ONLY_SHOW_LIVE_COUNTIES=True):
            results = county.get_visible_organizations()
            self.assertIn(live_org, results)
            self.assertNotIn(not_live_org, results)
示例#4
0
 def test_get_county_choices_query_live(self):
     live_org = FakeOrganizationFactory(county=factories.CountyFactory(),
                                        is_live=True)
     not_live_org = FakeOrganizationFactory(
         county=factories.CountyFactory(), is_live=False)
     not_listed = models.County.objects.get(slug='not_listed')
     with self.settings(LIVE_COUNTY_CHOICES=True):
         results = list(models.County.objects.get_county_choices_query())
     self.assertIn(live_org.county, results)
     self.assertNotIn(not_live_org.county, results)
     self.assertNotIn(not_listed, results)
示例#5
0
 def setUp(self):
     self.org = FakeOrganizationFactory(name="Alameda County Pubdef",
                                        is_live=True)
     self.user = UserFactory(last_login=over_1_month_ago)
     UserProfileFactory(user=self.user, organization=self.org)
     self.sub = FormSubmissionWithOrgsFactory(
         organizations=[self.org],
         answers={},
         date_received=over_1_month_ago)
     FormSubmissionWithOrgsFactory(organizations=[self.org],
                                   answers={},
                                   date_received=timezone.now())
 def test_mark_only_users_app_opened(self):
     fake_org_1 = FakeOrganizationFactory()
     fake_org_2 = FakeOrganizationFactory()
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[fake_org_1, fake_org_2], answers={})
     org_1_user = UserProfileFactory(organization=fake_org_1).user
     AppsService.handle_apps_opened(Mock(**{'request.user': org_1_user}),
                                    sub.applications.all())
     org_1_apps = sub.applications.filter(organization=fake_org_1)
     org_2_apps = sub.applications.filter(organization=fake_org_2)
     self.assertTrue(all([app.has_been_opened for app in org_1_apps]))
     self.assertFalse(any([app.has_been_opened for app in org_2_apps]))
示例#7
0
class TestCommand(TestCase):
    def setUp(self):
        self.org = FakeOrganizationFactory(name="Alameda County Pubdef",
                                           is_live=True)
        self.user = UserFactory(last_login=over_1_month_ago)
        UserProfileFactory(user=self.user, organization=self.org)
        self.sub = FormSubmissionWithOrgsFactory(
            organizations=[self.org],
            answers={},
            date_received=over_1_month_ago)
        FormSubmissionWithOrgsFactory(organizations=[self.org],
                                      answers={},
                                      date_received=timezone.now())

    def run_command(self):
        command = Command()
        with self.settings(DEFAULT_HOST='localhost:8000'):
            command.handle()

    def test_unopened_application_older_than_1_month(self):
        self.run_command()
        self.assertEqual(1, len(mail.outbox))
        email = mail.outbox[0]
        expected_subject = "Inactive organization on localhost:8000"
        expected_body = "Alameda County Pubdef has 2 unopened applications, " \
                        "the oldest from {}".format(
                            over_1_month_ago.strftime("%-m/%-d/%y"))
        self.assertEqual(expected_subject, email.subject)
        self.assertIn(expected_body, email.body)

    def test_unopened_application_newer_than_1_month(self):
        self.sub.date_received = timezone.now() - timedelta(days=29)
        self.sub.save()
        self.run_command()
        self.assertEqual(0, len(mail.outbox))

    def test_no_alert_with_no_logins_and_unopened_apps(self):
        self.user.last_login = None
        self.user.save()
        self.run_command()
        self.assertEqual(0, len(mail.outbox))

    def test_no_alert_with_logins_unopened_apps_and_org_not_live(self):
        self.org.is_live = False
        self.org.save()
        self.run_command()
        self.assertEqual(0, len(mail.outbox))

    def test_no_alert_with_logins_but_no_unopened_apps(self):
        self.sub.applications.update(has_been_opened=True)
        self.run_command()
        self.assertEqual(0, len(mail.outbox))
示例#8
0
 def setUp(self):
     super().setUp()
     org = FakeOrganizationFactory(slug='yolo')
     self.profile = UserProfileFactory(organization=org,
                                       name='Jane Doe',
                                       user=UserFactory(
                                           username="******",
                                           email='*****@*****.**'))
 def test_set_pdf_to_empty_bytes(self):
     prebuilt = models.PrebuiltPDFBundle(
         organization=FakeOrganizationFactory())
     bytes_ = b''
     prebuilt.set_bytes(bytes_)
     prebuilt.save()
     # pull from db to ensure cahnges persist
     fetched = models.PrebuiltPDFBundle.objects.first()
     self.assertFalse(fetched.pdf)
 def test_set_pdf_to_bytes(self):
     org = FakeOrganizationFactory()
     prebuilt = models.PrebuiltPDFBundle(organization=org)
     bytes_ = b'zomg'
     prebuilt.set_bytes(bytes_)
     prebuilt.save()
     expected_filename = org.slug + '_newapps'
     # pull from db to ensure changes persist
     fetched = models.PrebuiltPDFBundle.objects.first()
     self.assertIn(expected_filename, fetched.pdf.name)
     self.assertEqual(bytes_, fetched.pdf.read())
 def test_default_attributes(self):
     fake_org = FakeOrganizationFactory()
     subs = FormSubmissionWithOrgsFactory.create_batch(
         4, organizations=[fake_org], answers={})
     sub_ids = [sub.id for sub in subs]
     fake_apps = models.Application.objects.filter(
         form_submission__id__in=sub_ids)
     prebuilt = models.PrebuiltPDFBundle(organization=fake_org)
     prebuilt.save()
     prebuilt.applications.add(*fake_apps)
     self.assertFalse(prebuilt.pdf)
     self.assertEqual(prebuilt.organization, fake_org)
     self.assertEqual(set(prebuilt.applications.all()), set(fake_apps))
     self.assertIn('Unbuilt', str(prebuilt))
示例#12
0
    def test_two_orgs_one_without_alert_followed_by_one_with_alert(self):
        self.org_2 = FakeOrganizationFactory(
            name="Aardvark alphabetically before Alameda", is_live=True)
        self.user_2 = UserFactory(last_login=over_1_month_ago)
        UserProfileFactory(user=self.user_2, organization=self.org_2)
        FormSubmissionWithOrgsFactory(organizations=[self.org_2],
                                      answers={},
                                      date_received=timezone.now())

        self.run_command()
        self.assertEqual(1, len(mail.outbox))
        email = mail.outbox[0]
        expected_subject = "Inactive organization on localhost:8000"
        expected_body = "Alameda County Pubdef has 2 unopened applications, " \
                        "the oldest from {}".format(
                            over_1_month_ago.strftime("%-m/%-d/%y"))
        self.assertEqual(expected_subject, email.subject)
        self.assertIn(expected_body, email.body)
示例#13
0
class TestCommand(TestCase):
    def setUp(self):
        self.org = FakeOrganizationFactory(name="Alameda County Pubdef",
                                           is_live=True)
        self.user = UserFactory(last_login=over_1_month_ago)
        UserProfileFactory(user=self.user, organization=self.org)
        self.sub = FormSubmissionWithOrgsFactory(
            organizations=[self.org],
            answers={},
            date_received=over_1_month_ago)
        FormSubmissionWithOrgsFactory(organizations=[self.org],
                                      answers={},
                                      date_received=timezone.now())

    def run_command(self):
        command = Command()
        with self.settings(DEFAULT_HOST='localhost:8000'):
            command.handle()

    def test_unopened_application_older_than_1_month(self):
        self.run_command()
        self.assertEqual(1, len(mail.outbox))
        email = mail.outbox[0]
        expected_subject = "Inactive organization on localhost:8000"
        expected_body = "Alameda County Pubdef has 2 unopened applications, " \
                        "the oldest from {}".format(
                            over_1_month_ago.strftime("%-m/%-d/%y"))
        self.assertEqual(expected_subject, email.subject)
        self.assertIn(expected_body, email.body)

    def test_unopened_application_older_than_1_month_with_status_update(self):
        application = Application.objects.get(organization=self.org,
                                              form_submission=self.sub)
        status = StatusUpdate(application=application,
                              author=self.user,
                              status_type=StatusTypeFactory())
        status.save()
        self.run_command()
        self.assertEqual(
            0, len(mail.outbox),
            "No alert should be raised if application has status update")

    def test_two_orgs_one_without_alert_followed_by_one_with_alert(self):
        self.org_2 = FakeOrganizationFactory(
            name="Aardvark alphabetically before Alameda", is_live=True)
        self.user_2 = UserFactory(last_login=over_1_month_ago)
        UserProfileFactory(user=self.user_2, organization=self.org_2)
        FormSubmissionWithOrgsFactory(organizations=[self.org_2],
                                      answers={},
                                      date_received=timezone.now())

        self.run_command()
        self.assertEqual(1, len(mail.outbox))
        email = mail.outbox[0]
        expected_subject = "Inactive organization on localhost:8000"
        expected_body = "Alameda County Pubdef has 2 unopened applications, " \
                        "the oldest from {}".format(
                            over_1_month_ago.strftime("%-m/%-d/%y"))
        self.assertEqual(expected_subject, email.subject)
        self.assertIn(expected_body, email.body)

    def test_unopened_application_newer_than_1_month(self):
        self.sub.date_received = timezone.now() - timedelta(days=29)
        self.sub.save()
        self.run_command()
        self.assertEqual(0, len(mail.outbox))

    def test_no_alert_with_no_logins_and_unopened_apps(self):
        self.user.last_login = None
        self.user.save()
        self.run_command()
        self.assertEqual(0, len(mail.outbox))

    def test_no_alert_with_logins_unopened_apps_and_org_not_live(self):
        self.org.is_live = False
        self.org.save()
        self.run_command()
        self.assertEqual(0, len(mail.outbox))

    def test_no_alert_with_logins_but_no_unopened_apps(self):
        self.sub.applications.update(has_been_opened=True)
        self.run_command()
        self.assertEqual(0, len(mail.outbox))
示例#14
0
 def setUp(self):
     self.org = FakeOrganizationFactory(name="Alameda County Pubdef",
                                        is_live=True)
     self.sub = FormSubmissionWithOrgsFactory(organizations=[self.org],
                                              answers={})
示例#15
0
class TestCommand(TestCase):
    def setUp(self):
        self.org = FakeOrganizationFactory(name="Alameda County Pubdef",
                                           is_live=True)
        self.sub = FormSubmissionWithOrgsFactory(organizations=[self.org],
                                                 answers={})

    def run_command(self):
        command = Command()
        with self.settings(DEFAULT_HOST='localhost:8000'):
            command.handle()

    def test_alerts_with_old_logins_and_unopened_apps(self):
        user1 = UserFactory(last_login=old_login_date)
        user2 = UserFactory(last_login=old_login_date - timedelta(days=2))
        user3 = UserFactory(last_login=None)
        UserProfileFactory(user=user1, organization=self.org)
        UserProfileFactory(user=user2, organization=self.org)
        UserProfileFactory(user=user3, organization=self.org)
        self.run_command()
        self.assertEqual(1, len(mail.outbox))
        email = mail.outbox[0]
        expected_subject = "Inactive organization on localhost:8000"
        expected_body = "Alameda County Pubdef has not logged in since " \
                        "{} and has 1 unopened applications".format(
                            old_login_date.strftime("%a %b %-d %Y"))
        self.assertEqual(expected_subject, email.subject)
        self.assertIn(expected_body, email.body)

    def test_no_alert_with_no_logins_and_unopened_apps(self):
        user1 = UserFactory(last_login=None)
        user2 = UserFactory(last_login=None)
        UserProfileFactory(user=user1, organization=self.org)
        UserProfileFactory(user=user2, organization=self.org)
        self.run_command()
        self.assertEqual(0, len(mail.outbox))

    def test_no_alert_with_old_logins_unopened_apps_and_org_not_live(self):
        user1 = UserFactory(last_login=old_login_date)
        user2 = UserFactory(last_login=old_login_date - timedelta(days=2))
        user3 = UserFactory(last_login=None)
        self.org.is_live = False
        self.org.save()
        UserProfileFactory(user=user1, organization=self.org)
        UserProfileFactory(user=user2, organization=self.org)
        UserProfileFactory(user=user3, organization=self.org)
        self.run_command()
        self.assertEqual(0, len(mail.outbox))

    def test_no_alert_with_old_logins_but_no_unopened_apps(self):
        user1 = UserFactory(last_login=old_login_date)
        user2 = UserFactory(last_login=old_login_date - timedelta(days=2))
        user3 = UserFactory(last_login=None)
        UserProfileFactory(user=user1, organization=self.org)
        UserProfileFactory(user=user2, organization=self.org)
        UserProfileFactory(user=user3, organization=self.org)
        self.sub.applications.update(has_been_opened=True)
        self.run_command()
        self.assertEqual(0, len(mail.outbox))

    def test_no_alert_with_recent_logins_and_unopened_apps(self):
        user1 = UserFactory(last_login=recent_login_date)
        user2 = UserFactory(last_login=old_login_date)
        user3 = UserFactory(last_login=None)
        UserProfileFactory(user=user1, organization=self.org)
        UserProfileFactory(user=user2, organization=self.org)
        UserProfileFactory(user=user3, organization=self.org)
        self.run_command()
        self.assertEqual(0, len(mail.outbox))