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)
def setUp(self): super().setUp() self.santa_clara_pubdef = Organization.objects.get( slug='santa_clara_pubdef') self.fresno_pubdef = Organization.objects.get(slug='fresno_pubdef') self.sf_pubdef = Organization.objects.get(slug='sf_pubdef') self.sub = FormSubmissionWithOrgsFactory(organizations=[ self.santa_clara_pubdef, self.fresno_pubdef, self.sf_pubdef ]) self.edit_url = self.sub.get_edit_url()
def test_nonlive_application_doesnt_break_stats_page(self): self.be_monitor_user() non_live_org = Organization(name="Maquis", slug="maquis", is_receiving_agency=True, is_live=False, county=models.County.objects.first()) non_live_org.save() FormSubmissionWithOrgsFactory.create(organizations=[non_live_org], answers={}) response = self.client.get(reverse('intake-stats')) self.assertEqual(response.status_code, 200)
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())
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))
def test_messages_both_contain_intro(self, messages, notifications): # given: # - status update data # - application # - organization # - submission # - notification data # assert: # - base and sent messages both have intro message mock_request = Mock() org = Organization.objects.filter(is_live=True).last() profile = org.profiles.first() submission = FormSubmissionWithOrgsFactory(organizations=[org]) application = submission.applications.first() status_update_data = dict( author=profile.user, application=application, status_type=models.StatusType.objects.first(), next_steps=[], additional_information="") notification_data = dict(sent_message="hey there") services.status_notifications.send_and_save_new_status( mock_request, notification_data, status_update_data) expected_intro_message = \ services.status_notifications.get_notification_intro(profile) latest_update = models.StatusUpdate.objects.filter( application=application).latest('updated') notification = latest_update.notification self.assertIn(expected_intro_message, notification.base_message) self.assertIn(expected_intro_message, notification.sent_message) args = notifications.send_simple_front_notification.call_args[0] self.assertIn(expected_intro_message, args[1])
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))
def test_diff_dates_same_sub_no_change(self): # make sure that if the application times differ slightly, it does # not affect the count one_org = Organization(name="House Stark", slug='stark') one_org.save() other_org = Organization(name="House Tyrell", slug='tyrell') other_org.save() sub = FormSubmissionWithOrgsFactory( organizations=[one_org, other_org], answers={}) app = sub.applications.first() app.created = app.created + datetime.timedelta(milliseconds=1) app.save() results = statistics.rollup_subs( statistics.get_app_dates_sub_ids_org_ids()) self.assertEqual(len(results), 1)
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_only_gets_correct_emails(self): # users who shouldn't get notifications at an org that would fresno_user_w_notifications = app_reviewer('fresno_pubdef') fresno_user_without_notifications = app_reviewer( 'fresno_pubdef', username='******') fresno_user_without_notifications.should_get_notifications = False fresno_user_without_notifications.save() santa_clara_user = app_reviewer('santa_clara_pubdef') app_reviewer('sf_pubdef') submission = FormSubmissionWithOrgsFactory(organizations=[ santa_clara_user.organization, fresno_user_w_notifications.organization ]) resulting_emails = set(get_emails_to_notify_of_edits(submission.id)) expected_emails = { fresno_user_w_notifications.user.email, santa_clara_user.user.email } self.assertEqual(expected_emails, resulting_emails)
def test_next_step_intro_if_next_steps(self): mock_request = Mock() org = Organization.objects.filter(is_live=True).last() profile = org.profiles.first() submission = FormSubmissionWithOrgsFactory(organizations=[org]) application = submission.applications.first() status_update_data = dict( author=profile.user, application=application, status_type=models.StatusType.objects.first(), next_steps=[models.NextStep.objects.first()], additional_information="") result = services.status_notifications\ .get_base_message_from_status_update_data( mock_request, status_update_data ) next_step_intro = 'Here are your next steps:' self.assertIn(next_step_intro, result)
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))
class TestAppEditView(TestCase): fixtures = ['counties', 'organizations', 'groups'] def setUp(self): super().setUp() self.santa_clara_pubdef = Organization.objects.get( slug='santa_clara_pubdef') self.fresno_pubdef = Organization.objects.get(slug='fresno_pubdef') self.sf_pubdef = Organization.objects.get(slug='sf_pubdef') self.sub = FormSubmissionWithOrgsFactory(organizations=[ self.santa_clara_pubdef, self.fresno_pubdef, self.sf_pubdef ]) self.edit_url = self.sub.get_edit_url() # access control def test_anonymous_user_redirected_to_login(self): response = self.client.get(self.edit_url) self.assertEqual(302, response.status_code) self.assertIn(reverse('user_accounts-login'), response.url) def test_incorrect_org_user_gets_404(self): different_org_user_profile = app_reviewer('a_pubdef') self.client.login(username=different_org_user_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) self.assertEqual(404, response.status_code) def test_matching_org_user_gets_200(self): matching_org_user_profile = app_reviewer('fresno_pubdef') self.client.login(username=matching_org_user_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) self.assertEqual(200, response.status_code) def test_cfa_user_gets_200(self): cfa_user_profile = followup_user() self.client.login(username=cfa_user_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) self.assertEqual(200, response.status_code) # getting the form def test_org_user_gets_expected_form_for_their_org(self): fresno_profile = app_reviewer('fresno_pubdef') self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) fresno_expected_fields = [ F.ContactPreferences, F.FirstName, F.MiddleName, F.LastName, F.Aliases, F.PhoneNumberField, F.AlternatePhoneNumberField, F.AddressField, F.DriverLicenseOrIDNumber, F.EmailField, F.DateOfBirthField, F.CaseNumber ] fresno_unexpected_fields = [F.SocialSecurityNumberField, F.USCitizen] for field in fresno_expected_fields: with self.subTest(field=field): self.assertContains(response, field.context_key) for field in fresno_unexpected_fields: with self.subTest(field=field): self.assertNotContains(response, field.context_key) self.client.logout() santa_clara_profile = app_reviewer('santa_clara_pubdef') self.client.login(username=santa_clara_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) santa_clara_expected_fields = [ F.ContactPreferences, F.FirstName, F.MiddleName, F.LastName, F.PhoneNumberField, F.AlternatePhoneNumberField, F.AddressField, F.EmailField, F.DateOfBirthField ] santa_clara_unexpected_fields = [ F.SocialSecurityNumberField, F.Aliases, F.DriverLicenseOrIDNumber, F.CaseNumber, F.MonthlyIncome ] for field in santa_clara_expected_fields: with self.subTest(field=field): self.assertContains(response, field.context_key) for field in santa_clara_unexpected_fields: with self.subTest(field=field): self.assertNotContains(response, field.context_key) def test_cfa_user_gets_expected_form(self): santa_clara_expected_fields = { F.ContactPreferences, F.FirstName, F.MiddleName, F.LastName, F.PhoneNumberField, F.AlternatePhoneNumberField, F.AddressField, F.EmailField, F.DateOfBirthField } fresno_expected_fields = { F.ContactPreferences, F.FirstName, F.MiddleName, F.LastName, F.Aliases, F.PhoneNumberField, F.AlternatePhoneNumberField, F.AddressField, F.DriverLicenseOrIDNumber, F.EmailField, F.DateOfBirthField, F.CaseNumber } cfa_user_profile = followup_user() self.client.login(username=cfa_user_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) for field in santa_clara_expected_fields | fresno_expected_fields: with self.subTest(field=field): self.assertContains(response, field.context_key) self.assertContains(response, 'existing_' + field.context_key) def test_edit_form_contains_existing_data_and_errors(self): fresno_profile = app_reviewer('fresno_pubdef') self.sub.answers['email'] = 'notgood@example' self.sub.answers['phone_number'] = '5555555555' self.sub.answers['alternate_phone_number'] = '5555555555' self.sub.answers['dob'] = { 'month': 'February', 'day': 3, 'year': '19714' } self.sub.save() self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) self.assertContains(response, self.sub.answers['first_name']) self.assertContains(response, self.sub.answers['last_name']) assertInputHasValue(response, 'phone_number', '') assertInputHasValue(response, 'existing_phone_number', '5555555555') assertInputHasValue(response, 'alternate_phone_number', '') assertInputHasValue(response, 'existing_alternate_phone_number', '5555555555') assertInputHasValue(response, 'email', 'notgood@example') assertInputHasValue(response, 'existing_email', 'notgood@example') assertInputHasValue(response, 'dob.day', '3') assertInputHasValue(response, 'existing_dob.day', '3') assertInputHasValue(response, 'dob.month', '') assertInputHasValue(response, 'existing_dob.month', 'February') assertInputHasValue(response, 'dob.year', '19714') assertInputHasValue(response, 'existing_dob.year', '19714') # submitting the form def test_successful_edit_submission_redirects_to_app_detail(self): fresno_profile = app_reviewer('fresno_pubdef') self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) post_data = dict_to_post_data( response.context_data['form'].raw_input_data) post_data.update({ 'first_name': 'Foo', 'last_name': 'Bar', 'email': '*****@*****.**' }) response = self.client.post(self.edit_url, post_data) self.assertRedirects(response, self.sub.get_absolute_url(), fetch_redirect_response=False) def test_user_sees_success_flash_and_updated_info_after_submission(self): fresno_profile = app_reviewer('fresno_pubdef') self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) post_data = dict_to_post_data( response.context_data['form'].raw_input_data) post_data.update({ 'first_name': 'Foo', 'last_name': 'Bar', 'email': '*****@*****.**' }) response = self.client.post(self.edit_url, post_data, follow=True) expected_flash_message = 'Saved new information for Foo Bar' self.assertContains(response, expected_flash_message) def test_submitting_unchanged_existing_bad_data_is_not_allowed(self): # add existing bad data self.sub.answers['email'] = 'notgood@example' self.sub.save() fresno_profile = app_reviewer('fresno_pubdef') self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) post_data = dict_to_post_data( response.context_data['form'].raw_input_data) post_data.update({'first_name': 'Foo', 'last_name': 'Bar'}) response = self.client.post(self.edit_url, post_data) self.assertEqual(200, response.status_code) def test_submitting_new_bad_data_is_not_allowed(self): self.sub.answers['email'] = 'notgood@example' self.sub.save() fresno_profile = app_reviewer('fresno_pubdef') self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) post_data = dict_to_post_data( response.context_data['form'].raw_input_data) post_data.update({ 'first_name': 'Foo', 'last_name': 'Bar', 'email': 'notgood@butdifferent' }) response = self.client.post(self.edit_url, post_data) self.assertEqual(200, response.status_code) self.assertTrue(response.context_data['form'].errors) def test_deleting_data_required_by_other_orgs_is_not_allowed(self): sf_pubdef = app_reviewer('sf_pubdef') self.client.login(username=sf_pubdef.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) post_data = dict_to_post_data( response.context_data['form'].raw_input_data) post_data.update({ 'first_name': 'Foo', 'last_name': 'Bar', 'dob.day': '3', 'dob.month': '', 'dob.year': '' }) response = self.client.post(self.edit_url, post_data) self.assertEqual(200, response.status_code) self.assertTrue(response.context_data['form'].errors) def test_updating_data_creates_audit_record(self): fresno_profile = app_reviewer('fresno_pubdef') self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) post_data = dict_to_post_data( response.context_data['form'].raw_input_data) post_data.update({'first_name': 'Foo', 'last_name': 'Bar'}) response = self.client.post(self.edit_url, post_data, follow=True) latest_crud_event = CRUDEvent.objects.filter( content_type__app_label='intake', content_type__model='formsubmission').latest('datetime') self.assertEqual(CRUDEvent.UPDATE, latest_crud_event.event_type) data = json.loads(latest_crud_event.object_json_repr)[0]['fields'] self.assertEqual(data['first_name'], 'Foo') self.assertEqual(data['last_name'], 'Bar') self.assertEqual(data['answers']['first_name'], 'Foo') self.assertEqual(data['answers']['last_name'], 'Bar') @patch('intake.views.app_edit_view.app_edited_org_email_notification') def test_notifies_org_user_with_safe_data_diff(self, notification_patch): fresno_profile = app_reviewer('fresno_pubdef') santa_clara_profile = app_reviewer('santa_clara_pubdef') self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) post_data = dict_to_post_data( response.context_data['form'].raw_input_data) post_data.update({ 'first_name': 'Foo', 'last_name': 'Bar', 'driver_license_or_id': '9123462907890387', 'email': '*****@*****.**' }) expected_safe_diff = { 'First name': { 'before': self.sub.first_name, 'after': 'Foo' }, 'Last name': { 'before': self.sub.last_name, 'after': 'Bar' }, 'Email': { 'before': self.sub.email, 'after': '*****@*****.**' } } self.client.post(self.edit_url, post_data) notification_patch.send.assert_any_call( to=[santa_clara_profile.user.email], editor_email=fresno_profile.user.email, editor_org_name=fresno_profile.organization.name, app_detail_url=self.sub.get_external_url(), submission_id=self.sub.id, applicant_name='Foo Bar', safe_data_diff=expected_safe_diff, unsafe_changed_keys=['Driver License/ID']) notification_patch.send.assert_any_call( to=[fresno_profile.user.email], editor_email=fresno_profile.user.email, editor_org_name=fresno_profile.organization.name, app_detail_url=self.sub.get_external_url(), submission_id=self.sub.id, applicant_name='Foo Bar', safe_data_diff=expected_safe_diff, unsafe_changed_keys=['Driver License/ID']) self.assertEqual(2, len(notification_patch.send.mock_calls)) @patch('intake.views.app_edit_view.app_edited_applicant_email_notification' ) @patch('intake.views.app_edit_view.app_edited_applicant_sms_notification') def test_notifies_applicant_of_changed_data_at_old_and_new_contact_info( self, sms_notification_patch, email_notification_patch): fresno_profile = app_reviewer('fresno_pubdef') self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) post_data = dict_to_post_data( response.context_data['form'].raw_input_data) post_data.update({ 'first_name': 'Foo', 'last_name': 'Bar', 'driver_license_or_id': '9123462907890387', 'email': '*****@*****.**', 'phone_number': '4153016005' }) self.client.post(self.edit_url, post_data) organization = fresno_profile.organization expected_changed_fields = [ 'Driver License/ID', 'Email', 'First name', 'Last name', 'Phone number' ] email_notification_patch.send.assert_any_call( to=['*****@*****.**'], org_contact_info=organization.get_contact_info_message(), org_name='the Fresno County Public Defender', changed_fields=expected_changed_fields, is_old_contact_info=False) email_notification_patch.send.assert_any_call( to=[self.sub.email], org_contact_info=organization.get_contact_info_message(), org_name='the Fresno County Public Defender', changed_fields=expected_changed_fields, is_old_contact_info=True) self.assertEqual(2, len(email_notification_patch.send.mock_calls)) sms_notification_patch.send.assert_any_call( to=['(415) 212-4848'], org_contact_info=organization.get_contact_info_message(), org_name='the Fresno County Public Defender', changed_fields=expected_changed_fields, is_old_contact_info=True) sms_notification_patch.send.assert_any_call( to=['4153016005'], org_contact_info=organization.get_contact_info_message(), org_name='the Fresno County Public Defender', changed_fields=expected_changed_fields, is_old_contact_info=False) self.assertEqual(2, len(sms_notification_patch.send.mock_calls)) @patch('intake.views.app_edit_view.app_edited_applicant_email_notification' ) @patch('intake.views.app_edit_view.app_edited_applicant_sms_notification') def test_does_not_send_notifications_if_contact_info_does_not_exist( self, sms_notification_patch, email_notification_patch): self.sub.email = '' self.sub.phone_number = '' self.sub.answers['email'] = '' self.sub.answers['phone_number'] = '' self.sub.answers['contact_preferences'] = [] self.sub.save() fresno_profile = app_reviewer('fresno_pubdef') self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) post_data = dict_to_post_data( response.context_data['form'].raw_input_data) post_data.update({ 'first_name': 'Foo', 'last_name': 'Bar', 'phone_number': '4153016005' }) self.client.post(self.edit_url, post_data) organization = fresno_profile.organization expected_changed_fields = ['First name', 'Last name', 'Phone number'] email_notification_patch.send.assert_not_called() sms_notification_patch.send.assert_called_once_with( to=['4153016005'], org_contact_info=organization.get_contact_info_message(), org_name='the Fresno County Public Defender', changed_fields=expected_changed_fields, is_old_contact_info=False) @patch('intake.views.app_edit_view.app_edited_org_email_notification') @patch('intake.views.app_edit_view.app_edited_applicant_email_notification' ) def test_does_not_notify_if_unchanged(self, applicant_notification_patch, org_notification_patch): fresno_profile = app_reviewer('fresno_pubdef') self.client.login(username=fresno_profile.user.username, password=settings.TEST_USER_PASSWORD) response = self.client.get(self.edit_url) post_data = dict_to_post_data( response.context_data['form'].raw_input_data) self.client.post(self.edit_url, post_data) org_notification_patch.assert_not_called() applicant_notification_patch.assert_not_called()
def setUp(self): self.org = FakeOrganizationFactory(name="Alameda County Pubdef", is_live=True) self.sub = FormSubmissionWithOrgsFactory(organizations=[self.org], answers={})
def test_factory_doesnt_initiate_validation(self, validate): cfa = Organization.objects.get(slug='cfa') sub = FormSubmissionWithOrgsFactory(organizations=[cfa]) validate.assert_not_called()