def test_ver_code_email_uses_settings_for_no_of_days_and_subject_for_email2( settings): expected_subject = email.VerificationStillWaitingNotification.subject settings.VERIFICATION_CODE_NOT_GIVEN_DAYS_2ND_EMAIL = 1 settings.VERIFICATION_CODE_NOT_GIVEN_SUBJECT_2ND_EMAIL = 'bla bla' one_day_ago = timezone.now() - timedelta(days=1) sixteen_days_ago = timezone.now() - timedelta(days=16) SupplierFactory(company__verified_with_code=False, company__date_verification_letter_sent=sixteen_days_ago) supplier = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=one_day_ago) SupplierEmailNotificationFactory(supplier=supplier, category='verification_code_not_given', date_sent=(timezone.now() - timedelta(days=8))) mail.outbox = [] # reset after emails sent by signals notifications.verification_code_not_given() assert len(mail.outbox) == 1 assert mail.outbox[0].to == [supplier.company_email] assert mail.outbox[0].subject == expected_subject # 1 created + 1 in set up assert SupplierEmailNotification.objects.all().count() == 2
def test_sends_ver_code_email_when_not_input_for_8_days(mock_task, settings): expected_subject = email.VerificationWaitingNotification.subject seven_days_ago = timezone.now() - timedelta(days=7) eight_days_ago = timezone.now() - timedelta(days=8) nine_days_ago = timezone.now() - timedelta(days=9) SupplierFactory(company__verified_with_code=False, company__date_verification_letter_sent=seven_days_ago) supplier = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=eight_days_ago) supplier_with_reminder = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=nine_days_ago) SupplierEmailNotificationFactory(supplier=supplier_with_reminder, category='verification_code_not_given', date_sent=(timezone.now() - timedelta(days=1))) notifications.verification_code_not_given() assert mock_task.delay.call_count == 1 assert len(mock_task.delay.call_args_list) == 1 call_args = mock_task.delay.call_args[1] assert call_args['recipient_email'] == supplier.company_email assert call_args['subject'] == expected_subject assert call_args['from_email'] == settings.FAB_FROM_EMAIL assert SupplierEmailNotification.objects.all().count() == 2
def test_sends_ver_code_email_when_not_input_for_8_days(settings): expected_subject = email.VerificationWaitingNotification.subject seven_days_ago = timezone.now() - timedelta(days=7) eight_days_ago = timezone.now() - timedelta(days=8) nine_days_ago = timezone.now() - timedelta(days=9) SupplierFactory(company__verified_with_code=False, company__date_verification_letter_sent=seven_days_ago) supplier = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=eight_days_ago) supplier_with_reminder = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=nine_days_ago) SupplierEmailNotificationFactory(supplier=supplier_with_reminder, category='verification_code_not_given', date_sent=(timezone.now() - timedelta(days=1))) mail.outbox = [] # reset after emails sent by signals notifications.verification_code_not_given() assert len(mail.outbox) == 1 assert mail.outbox[0].to == [supplier.company_email] assert mail.outbox[0].subject == expected_subject assert mail.outbox[0].from_email == settings.FAB_FROM_EMAIL # 1 created + 1 from setup assert SupplierEmailNotification.objects.all().count() == 2 instance = SupplierEmailNotification.objects.get(supplier=supplier) assert instance.category == 'verification_code_not_given' assert instance.date_sent == timezone.now()
def test_sends_ver_code_email_when_16_days_passed_but_not_to_the_minute( settings): supplier2_verification_sent = datetime(2016, 11, 30, 23, 59, 59) supplier1 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=datetime(2016, 11, 30, 0, 0, 1)) supplier2 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=supplier2_verification_sent) SupplierEmailNotificationFactory(supplier=supplier1, category='verification_code_not_given', date_sent=datetime( 2016, 11, 8, 23, 59, 59)) SupplierEmailNotificationFactory(supplier=supplier2, category='verification_code_not_given', date_sent=datetime( 2016, 11, 8, 23, 59, 59)) mail.outbox = [] # reset after emails sent by signals notifications.verification_code_not_given() assert len(mail.outbox) == 2 assert mail.outbox[0].to == [supplier1.company_email] assert mail.outbox[1].to == [supplier2.company_email] # 2 created + 2 in set up assert SupplierEmailNotification.objects.all().count() == 4
def test_sends_ver_code_email_when_16_days_passed_but_not_to_the_minute( mock_task, settings): supplier2_verification_sent = datetime(2016, 11, 30, 23, 59, 59) supplier1 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=datetime(2016, 11, 30, 0, 0, 1)) supplier2 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=supplier2_verification_sent) SupplierEmailNotificationFactory(supplier=supplier1, category='verification_code_not_given', date_sent=datetime( 2016, 11, 8, 23, 59, 59)) SupplierEmailNotificationFactory(supplier=supplier2, category='verification_code_not_given', date_sent=datetime( 2016, 11, 8, 23, 59, 59)) notifications.verification_code_not_given() assert mock_task.delay.call_count == 2 assert len(mock_task.delay.call_args_list) == 2 call_args = mock_task.delay.call_args_list assert call_args[0][1]['recipient_email'] == supplier1.company_email assert call_args[1][1]['recipient_email'] == supplier2.company_email assert SupplierEmailNotification.objects.all().count() == 4
def test_case_study_email_uses_settings_for_no_of_days_and_subject( mock_task, settings): settings.NO_CASE_STUDIES_DAYS = 1 expected_subject = email.NoCaseStudiesNotification.subject one_day_ago = timezone.now() - timedelta(days=1) eight_days_ago = timezone.now() - timedelta(days=8) SupplierFactory(date_joined=eight_days_ago) supplier = SupplierFactory(date_joined=one_day_ago) notifications.no_case_studies() assert len(mock_task.delay.call_args_list) == 1 call_args = mock_task.delay.call_args[1] assert call_args['from_email'] == settings.FAB_FROM_EMAIL assert call_args['recipient_email'] == supplier.company_email assert call_args['subject'] == expected_subject
def test_sends_case_study_email_when_8_days_ago_but_not_to_the_minute( mock_task, settings): supplier1 = SupplierFactory(date_joined=datetime(2016, 12, 8, 0, 0, 1)) supplier2 = SupplierFactory(date_joined=datetime(2016, 12, 8, 23, 59, 59)) SupplierFactory(date_joined=datetime(2016, 12, 7, 23, 59, 59)) SupplierFactory(date_joined=datetime(2016, 12, 9, 0, 0, 1)) notifications.no_case_studies() assert len(mock_task.delay.call_args_list) == 2 first_email_call_args = mock_task.delay.call_args_list[0][1] second_email_call_args = mock_task.delay.call_args_list[1][1] assert first_email_call_args['from_email'] == settings.FAB_FROM_EMAIL assert first_email_call_args['recipient_email'] == supplier1.company_email assert second_email_call_args['from_email'] == settings.FAB_FROM_EMAIL assert second_email_call_args['recipient_email'] == supplier2.company_email
def test_log_in_email_has_expected_vars_in_template(settings): settings.HASNT_LOGGED_IN_URL = 'http://great.gov.uk/looooogin?next=a' settings.HASNT_LOGGED_IN_UTM = 'utm=1' expected_url = 'http://great.gov.uk/looooogin?next=a&utm=1' supplier = SupplierFactory() mocked_json = [ { 'id': supplier.sso_id, 'last_login': '******' }, ] mocked_api = MagicMock(return_value=MagicMock(json=MagicMock( return_value=mocked_json))) mail.outbox = [] # reset after emails sent by signals with patch(LAST_LOGIN_API_METHOD, mocked_api): notifications.hasnt_logged_in() assert len(mail.outbox) == 1 assert supplier.name in mail.outbox[0].body assert supplier.name in mail.outbox[0].alternatives[0][0] assert expected_url in mail.outbox[0].body assert expected_url in mail.outbox[0].alternatives[0][0] assert 'http://help.zendesk.com' in mail.outbox[0].body assert 'http://help.zendesk.com' in mail.outbox[0].alternatives[0][0]
def test_case_study_email_uses_settings_for_no_of_days_and_subject(settings): settings.NO_CASE_STUDIES_DAYS = 1 expected_subject = email.NoCaseStudiesNotification.subject one_day_ago = timezone.now() - timedelta(days=1) eight_days_ago = timezone.now() - timedelta(days=8) SupplierFactory(date_joined=eight_days_ago) supplier = SupplierFactory(date_joined=one_day_ago) mail.outbox = [] # reset after emails sent by signals notifications.no_case_studies() assert len(mail.outbox) == 1 assert mail.outbox[0].from_email == settings.FAB_FROM_EMAIL assert mail.outbox[0].to == [supplier.company_email] assert mail.outbox[0].subject == expected_subject assert SupplierEmailNotification.objects.all().count() == 1
def test_log_in_email_has_expected_vars_in_template(mock_task, settings): settings.HASNT_LOGGED_IN_URL = 'http://great.gov.uk/looooogin?next=a' settings.HASNT_LOGGED_IN_UTM = 'utm=1' expected_url = 'http://great.gov.uk/looooogin?next=a&utm=1' supplier = SupplierFactory() mocked_json = [ { 'id': supplier.sso_id, 'last_login': '******' }, ] mocked_api = MagicMock(return_value=MagicMock(json=MagicMock( return_value=mocked_json))) mail.outbox = [] # reset after emails sent by signals with patch(LAST_LOGIN_API_METHOD, mocked_api): notifications.hasnt_logged_in() assert len(mock_task.delay.call_args_list) == 1 call_args = mock_task.delay.call_args[1] assert call_args['from_email'] == settings.FAB_FROM_EMAIL assert supplier.name in call_args['text_body'] assert supplier.name in call_args['html_body'] assert expected_url in call_args['text_body'] assert expected_url in call_args['html_body'] assert 'http://help.zendesk.com' in call_args['text_body'] assert 'http://help.zendesk.com' in call_args['html_body']
def test_sends_case_study_email_when_8_days_ago_but_not_to_the_minute( settings): supplier1 = SupplierFactory(date_joined=datetime(2016, 12, 8, 0, 0, 1)) supplier2 = SupplierFactory(date_joined=datetime(2016, 12, 8, 23, 59, 59)) SupplierFactory(date_joined=datetime(2016, 12, 7, 23, 59, 59)) SupplierFactory(date_joined=datetime(2016, 12, 9, 0, 0, 1)) mail.outbox = [] # reset after emails sent by signals notifications.no_case_studies() assert len(mail.outbox) == 2 assert mail.outbox[0].from_email == settings.FAB_FROM_EMAIL assert mail.outbox[0].to == [supplier1.company_email] assert mail.outbox[1].from_email == settings.FAB_FROM_EMAIL assert mail.outbox[1].to == [supplier2.company_email] assert SupplierEmailNotification.objects.all().count() == 2
def test_log_in_email_uses_settings_for_no_of_days_and_subject( mock_task, settings): settings.HASNT_LOGGED_IN_DAYS = 1 expected_subject = email.HasNotLoggedInRecentlyNotification.subject supplier = SupplierFactory() mocked_json = [ { 'id': supplier.sso_id, 'last_login': '******' }, ] mocked_api = MagicMock(return_value=MagicMock(json=MagicMock( return_value=mocked_json))) with patch(LAST_LOGIN_API_METHOD, mocked_api): notifications.hasnt_logged_in() mocked_api.assert_called_once_with( start=datetime(2017, 3, 31, 0, 0, 0, 0), end=datetime(2017, 3, 31, 23, 59, 59, 999999), ) call_args = mock_task.delay.call_args_list assert len(call_args) == 1 assert call_args[0][1]['subject'] == expected_subject
def test_sends_ver_code_email_when_8_days_passed_but_not_to_the_minute( mock_task, settings): supplier2_verification_sent = datetime(2016, 12, 8, 23, 59, 59) supplier1 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=datetime(2016, 12, 8, 0, 0, 1)) supplier2 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=supplier2_verification_sent) notifications.verification_code_not_given() assert len(mock_task.delay.call_args_list) == 2 call_args = mock_task.delay.call_args_list assert call_args[0][1]['recipient_email'] == supplier1.company_email assert call_args[1][1]['recipient_email'] == supplier2.company_email
def test_supplier_unsubscribed(mock_task): supplier = SupplierFactory() notifications.supplier_unsubscribed(supplier) assert len(mock_task.delay.call_args_list) == 1 call_args = mock_task.delay.call_args[1] assert call_args['recipient_email'] == supplier.company_email assert supplier.name in call_args['text_body']
def test_sends_case_study_email_only_when_registered_8_days_ago( mock_task, settings): expected_subject = email.NoCaseStudiesNotification.subject seven_days_ago = timezone.now() - timedelta(days=7) eight_days_ago = timezone.now() - timedelta(days=8) nine_days_ago = timezone.now() - timedelta(days=9) SupplierFactory(date_joined=seven_days_ago) supplier = SupplierFactory(date_joined=eight_days_ago) SupplierFactory(date_joined=nine_days_ago) notifications.no_case_studies() mock_task.delay.assert_called_once_with( from_email=settings.FAB_FROM_EMAIL, html_body=ANY, text_body=ANY, recipient_email=supplier.company_email, subject=expected_subject, )
def test_doesnt_send_ver_code_email_when_user_has_input_ver_code(mock_task): eight_days_ago = timezone.now() - timedelta(days=8) sixteen_days_ago = timezone.now() - timedelta(days=16) SupplierFactory(company__verified_with_code=True, company__date_verification_letter_sent=eight_days_ago) SupplierFactory(company__verified_with_code=True, company__date_verification_letter_sent=sixteen_days_ago) supplier_with_reminder = SupplierFactory( company__verified_with_code=True, company__date_verification_letter_sent=sixteen_days_ago) SupplierEmailNotificationFactory(supplier=supplier_with_reminder, category='verification_code_not_given', date_sent=eight_days_ago) notifications.verification_code_not_given() assert mock_task.delay.called is False # just the one created in setup assert SupplierEmailNotification.objects.all().count() == 1
def test_sends_ver_code_email_when_not_input_for_16_days(settings): expected_subject = email.VerificationStillWaitingNotification.subject fifteen_days_ago = timezone.now() - timedelta(days=15) sixteen_days_ago = timezone.now() - timedelta(days=16) seventeen_days_ago = timezone.now() - timedelta(days=17) supplier15 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=fifteen_days_ago) supplier16 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=sixteen_days_ago) supplier17 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=seventeen_days_ago) SupplierEmailNotificationFactory(supplier=supplier15, category='verification_code_not_given', date_sent=(timezone.now() - timedelta(days=7))) email_notification = SupplierEmailNotificationFactory( supplier=supplier16, category='verification_code_not_given', date_sent=(timezone.now() - timedelta(days=8))) SupplierEmailNotificationFactory(supplier=supplier17, category='verification_code_not_given', date_sent=(timezone.now() - timedelta(days=9))) SupplierEmailNotificationFactory(supplier=supplier17, category='verification_code_2nd_email', date_sent=(timezone.now() - timedelta(days=1))) mail.outbox = [] # reset after emails sent by signals notifications.verification_code_not_given() assert len(mail.outbox) == 1 assert mail.outbox[0].from_email == settings.FAB_FROM_EMAIL assert mail.outbox[0].to == [supplier16.company_email] assert mail.outbox[0].subject == expected_subject # 1 created + 4 in set up assert SupplierEmailNotification.objects.all().count() == 5 instance = SupplierEmailNotification.objects.exclude( pk=email_notification.pk).get(supplier=supplier16) assert instance.category == 'verification_code_2nd_email' assert instance.date_sent == timezone.now()
def test_ver_code_email_uses_settings_for_no_of_days_and_subject_for_email1( mock_task, settings): expected_subject = email.VerificationWaitingNotification.subject settings.VERIFICATION_CODE_NOT_GIVEN_DAYS = 1 settings.VERIFICATION_CODE_NOT_GIVEN_SUBJECT = 'bla bla' one_day_ago = timezone.now() - timedelta(days=1) eight_days_ago = timezone.now() - timedelta(days=8) SupplierFactory(company__verified_with_code=False, company__date_verification_letter_sent=eight_days_ago) supplier = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=one_day_ago) notifications.verification_code_not_given() assert len(mock_task.delay.call_args_list) == 1 call_args = mock_task.delay.call_args[1] assert call_args['recipient_email'] == supplier.company_email assert call_args['subject'] == expected_subject
def test_doesnt_send_case_study_email_when_user_has_case_studies(): eight_days_ago = timezone.now() - timedelta(days=8) company = SupplierFactory(date_joined=eight_days_ago).company CompanyCaseStudyFactory(company=company) mail.outbox = [] # reset after emails sent by signals notifications.no_case_studies() assert len(mail.outbox) == 0 assert SupplierEmailNotification.objects.all().count() == 0
def test_preverified_retrieve_company_already_claimed(authed_client): supplier = SupplierFactory() url = reverse( 'enrolment-preverified', kwargs={'key': signing.Signer().sign(supplier.company.number)} ) response = authed_client.get(url) assert response.status_code == 404
def test_doesnt_send_ver_code_email_when_user_has_input_ver_code(): eight_days_ago = timezone.now() - timedelta(days=8) sixteen_days_ago = timezone.now() - timedelta(days=16) SupplierFactory(company__verified_with_code=True, company__date_verification_letter_sent=eight_days_ago) SupplierFactory(company__verified_with_code=True, company__date_verification_letter_sent=sixteen_days_ago) supplier_with_reminder = SupplierFactory( company__verified_with_code=True, company__date_verification_letter_sent=sixteen_days_ago) SupplierEmailNotificationFactory(supplier=supplier_with_reminder, category='verification_code_not_given', date_sent=eight_days_ago) mail.outbox = [] # reset after emails sent by signals notifications.verification_code_not_given() assert len(mail.outbox) == 0 # just the one created in setup assert SupplierEmailNotification.objects.all().count() == 1
def test_preverified_claim_company_already_claimed(authed_client): supplier = SupplierFactory() url = reverse( 'enrolment-claim-preverified', kwargs={'key': signing.Signer().sign(supplier.company.number)} ) response = authed_client.post(url, {'name': 'Foo bar'}) assert response.status_code == 404
def test_ver_code_email_uses_settings_for_no_of_days_and_subject_for_email1( settings): expected_subject = email.VerificationWaitingNotification.subject settings.VERIFICATION_CODE_NOT_GIVEN_DAYS = 1 settings.VERIFICATION_CODE_NOT_GIVEN_SUBJECT = 'bla bla' one_day_ago = timezone.now() - timedelta(days=1) eight_days_ago = timezone.now() - timedelta(days=8) SupplierFactory(company__verified_with_code=False, company__date_verification_letter_sent=eight_days_ago) supplier = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=one_day_ago) mail.outbox = [] # reset after emails sent by signals notifications.verification_code_not_given() assert len(mail.outbox) == 1 assert mail.outbox[0].to == [supplier.company_email] assert mail.outbox[0].subject == expected_subject assert SupplierEmailNotification.objects.all().count() == 1
def test_sends_ver_code_email_when_not_input_for_16_days(mock_task, settings): expected_subject = email.VerificationStillWaitingNotification.subject fifteen_days_ago = timezone.now() - timedelta(days=15) sixteen_days_ago = timezone.now() - timedelta(days=16) seventeen_days_ago = timezone.now() - timedelta(days=17) supplier15 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=fifteen_days_ago) supplier16 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=sixteen_days_ago) supplier17 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=seventeen_days_ago) SupplierEmailNotificationFactory(supplier=supplier15, category='verification_code_not_given', date_sent=(timezone.now() - timedelta(days=7))) SupplierEmailNotificationFactory(supplier=supplier16, category='verification_code_not_given', date_sent=(timezone.now() - timedelta(days=8))) SupplierEmailNotificationFactory(supplier=supplier17, category='verification_code_not_given', date_sent=(timezone.now() - timedelta(days=9))) SupplierEmailNotificationFactory(supplier=supplier17, category='verification_code_2nd_email', date_sent=(timezone.now() - timedelta(days=1))) notifications.verification_code_not_given() assert mock_task.delay.call_count == 1 assert len(mock_task.delay.call_args_list) == 1 call_args = mock_task.delay.call_args[1] assert call_args['from_email'] == settings.FAB_FROM_EMAIL assert call_args['recipient_email'] == supplier16.company_email assert call_args['subject'] == expected_subject assert SupplierEmailNotification.objects.all().count() == 5
def test_sends_case_study_email_only_when_registered_8_days_ago(settings): expected_subject = email.NoCaseStudiesNotification.subject seven_days_ago = timezone.now() - timedelta(days=7) eight_days_ago = timezone.now() - timedelta(days=8) nine_days_ago = timezone.now() - timedelta(days=9) SupplierFactory(date_joined=seven_days_ago) supplier = SupplierFactory(date_joined=eight_days_ago) SupplierFactory(date_joined=nine_days_ago) mail.outbox = [] # reset after emails sent by signals notifications.no_case_studies() assert len(mail.outbox) == 1 assert mail.outbox[0].to == [supplier.company_email] assert mail.outbox[0].subject == expected_subject assert mail.outbox[0].from_email == settings.FAB_FROM_EMAIL assert SupplierEmailNotification.objects.all().count() == 1 instance = SupplierEmailNotification.objects.get() assert instance.supplier == supplier assert instance.category == 'no_case_studies' assert instance.date_sent == timezone.now()
def test_doesnt_send_ver_code_email_if_email_already_sent(mock_task): eight_days_ago = timezone.now() - timedelta(days=8) sixteen_days_ago = timezone.now() - timedelta(days=16) supplier1 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=eight_days_ago) supplier2 = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=sixteen_days_ago) SupplierEmailNotificationFactory(supplier=supplier1, category='verification_code_not_given') SupplierEmailNotificationFactory(supplier=supplier2, category='verification_code_2nd_email') SupplierEmailNotificationFactory(supplier=supplier2, category='verification_code_not_given', date_sent=eight_days_ago) notifications.verification_code_not_given() assert mock_task.delay.called is False # what we created in data setup, no new obj created assert SupplierEmailNotification.objects.all().count() == 3
def test_supplier_unsubscribed(): supplier = SupplierFactory() mail.outbox = [] # reset after emails sent by signals notifications.supplier_unsubscribed(supplier) assert len(mail.outbox) == 1 assert mail.outbox[0].to == [supplier.company_email] assert supplier.name in mail.outbox[0].body notification_record = SupplierEmailNotification.objects.first() assert SupplierEmailNotification.objects.count() == 1 assert notification_record.supplier == supplier assert notification_record.category == constants.UNSUBSCRIBED
def test_ver_code_email_uses_settings_for_no_of_days_and_subject_for_email2( mock_task, settings): expected_subject = email.VerificationStillWaitingNotification.subject settings.VERIFICATION_CODE_NOT_GIVEN_DAYS_2ND_EMAIL = 1 settings.VERIFICATION_CODE_NOT_GIVEN_SUBJECT_2ND_EMAIL = 'bla bla' one_day_ago = timezone.now() - timedelta(days=1) sixteen_days_ago = timezone.now() - timedelta(days=16) SupplierFactory(company__verified_with_code=False, company__date_verification_letter_sent=sixteen_days_ago) supplier = SupplierFactory( company__verified_with_code=False, company__date_verification_letter_sent=one_day_ago) SupplierEmailNotificationFactory(supplier=supplier, category='verification_code_not_given', date_sent=(timezone.now() - timedelta(days=8))) mail.outbox = [] # reset after emails sent by signals notifications.verification_code_not_given() assert len(mock_task.delay.call_args_list) == 1 call_args = mock_task.delay.call_args[1] assert call_args['recipient_email'] == supplier.company_email assert call_args['subject'] == expected_subject
def test_upload_suppliers_csv_to_s3(mocked_upload_file_object_to_s3): SupplierFactory.create_batch(5) SupplierFactory( sso_id=123, name='foobar', company_email='*****@*****.**', company=None, is_company_owner=True, ) call_command('generate_suppliers_csv_dump') assert mocked_upload_file_object_to_s3.called assert mocked_upload_file_object_to_s3.call_args == mock.call( file_object=mock.ANY, key=settings.SUPPLIERS_CSV_FILE_NAME, bucket=settings.CSV_DUMP_BUCKET_NAME, )
def test_case_study_email_has_expected_vars_in_template(mock_task, settings): settings.NO_CASE_STUDIES_URL = 'http://great.gov.uk/case-studies/add' settings.NO_CASE_STUDIES_UTM = 'utm=1' eight_days_ago = timezone.now() - timedelta(days=8) supplier = SupplierFactory(date_joined=eight_days_ago) notifications.no_case_studies() assert len(mock_task.delay.call_args_list) == 1 call_args = mock_task.delay.call_args[1] assert call_args['from_email'] == settings.FAB_FROM_EMAIL assert supplier.name in call_args['text_body'] assert supplier.name in call_args['html_body'] assert ('http://great.gov.uk/case-studies/add?utm=1' in call_args['text_body']) assert ('http://great.gov.uk/case-studies/add?utm=1' in call_args['html_body']) assert 'http://help.zendesk.com' in call_args['text_body'] assert 'http://help.zendesk.com' in call_args['html_body']