示例#1
0
 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))
示例#2
0
 def setUpClass(cls):
     super().setUpClass()
     # users & subs for two orgs
     # combo sub
     # a staff user with followup permissions
     this_profile = UserProfileFactory()
     other_profile = UserProfileFactory()
     cls.org_user = this_profile.user
     cls.staff_user = UserFactory(is_staff=True)
     UserProfileFactory(user=cls.staff_user)
     cls.staff_user.user_permissions.add(*get_all_followup_permissions())
     answers = dict(first_name='Jorge Luis',
                    last_name='Borges',
                    email='*****@*****.**',
                    phone_number='4152124848')
     cls.these_subs = [
         FormSubmissionWithOrgsFactory(
             organizations=[this_profile.organization], answers=answers)
         for i in (1, 2)
     ]
     cls.other_subs = [
         FormSubmissionWithOrgsFactory(
             organizations=[other_profile.organization], answers=answers)
         for i in (1, 2)
     ]
     cls.combo_sub = FormSubmissionWithOrgsFactory(organizations=[
         this_profile.organization, other_profile.organization
     ],
                                                   answers=answers)
示例#3
0
 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))
示例#4
0
 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))
示例#5
0
    def test_get_referral_emails_returns_active_emails_who_should_get_notifications(self):
        user_profile = UserProfileFactory()

        user_profile.should_get_notifications = True
        user_profile.save()

        user_profile.user.is_active = True
        user_profile.user.save()

        emails = user_profile.organization.get_referral_emails()
        self.assertIn(user_profile.user.email, emails)
示例#6
0
 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_calls_remove_pdf_task_when_opened(self, remove_application_pdfs):
     profile = UserProfileFactory()
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[profile.organization], answers={})
     AppsService.handle_apps_opened(Mock(**{'request.user': profile.user}),
                                    sub.applications.all())
     remove_application_pdfs.assert_called_with(sub.applications.first().id)
示例#8
0
 def setUp(self):
     super().setUp()
     org = FakeOrganizationFactory(slug='yolo')
     self.profile = UserProfileFactory(organization=org,
                                       name='Jane Doe',
                                       user=UserFactory(
                                           username="******",
                                           email='*****@*****.**'))
示例#9
0
    def test_request_is_cleared(self):
        # log in user
        user = UserProfileFactory().user
        self.client.login(
            username=user.username, password=settings.TEST_USER_PASSWORD)

        # do action
        self.client.get('/')
        # check if request is cleared
        self.assertIsNone(get_current_request())
        self.assertIsNone(get_current_user())
示例#10
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())
示例#11
0
    def test_get_referral_emails_only_returns_users_who_should_get_notifications(self):
        no_notifications_user_profile = UserProfileFactory()
        notifications_user_profile = UserProfileFactory()

        no_notifications_user_profile.organization = notifications_user_profile.organization
        no_notifications_user_profile.should_get_notifications = False
        no_notifications_user_profile.save()

        emails = no_notifications_user_profile.organization.get_referral_emails()
        self.assertNotIn(no_notifications_user_profile.user.email, emails)
 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]))
示例#13
0
    def test_get_referral_emails_only_returns_active_users(self):
        inactive_user_profile = UserProfileFactory()
        active_user_profile = UserProfileFactory()

        inactive_user_profile.organization = active_user_profile.organization
        inactive_user_profile.should_get_notifications = True
        inactive_user_profile.save()

        inactive_user_profile.user.is_active = False
        inactive_user_profile.user.save()

        emails = inactive_user_profile.organization.get_referral_emails()
        self.assertNotIn(inactive_user_profile.user.email, emails)
示例#14
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)
示例#15
0
def create_fake_applications(context, count, org_slug=None, status=None):
    count = int(count)
    if org_slug:
        org = Organization.objects.get(slug=org_slug)
        factories.FormSubmissionWithOrgsFactory.create_batch(
            count, organizations=[org])
        if status:
            for sub in FormSubmission.objects.all():
                app = sub.applications.first()
                app.has_been_opened = True
                app.save()
            if status == "read and updated":
                profile = UserProfileFactory(organization=org)
                for sub in FormSubmission.objects.all():
                    factories.StatusUpdateFactory(
                        application=sub.applications.first(),
                        author=profile.user)

    else:
        factories.FormSubmissionWithOrgsFactory.create_batch(count)
示例#16
0
 def email_and_org(self):
     profile = UserProfileFactory()
     return profile.user.email, profile.organization