Example #1
0
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
Example #2
0
def test_sends_case_study_email_to_expected_users(mock_task):
    eight_days_ago = timezone.now() - timedelta(days=8)
    twelve_days_ago = timezone.now() - timedelta(days=12)
    suppliers = SupplierFactory.create_batch(10, date_joined=eight_days_ago)
    SupplierFactory.create_batch(3, date_joined=twelve_days_ago)
    for supplier in suppliers[:4]:
        CompanyCaseStudyFactory(company=supplier.company)
    SupplierEmailNotificationFactory(supplier=suppliers[9],
                                     category='no_case_studies')
    SupplierEmailNotificationFactory(supplier=suppliers[8],
                                     category='hasnt_logged_in')

    notifications.no_case_studies()

    assert len(mock_task.delay.call_args_list) == 5
    supplier1 = mock_task.delay.call_args_list[0][1]['recipient_email']
    supplier2 = mock_task.delay.call_args_list[1][1]['recipient_email']
    supplier3 = mock_task.delay.call_args_list[2][1]['recipient_email']
    supplier4 = mock_task.delay.call_args_list[3][1]['recipient_email']
    supplier5 = mock_task.delay.call_args_list[4][1]['recipient_email']

    assert supplier1 == suppliers[4].company_email
    assert supplier2 == suppliers[5].company_email
    assert supplier3 == suppliers[6].company_email
    assert supplier4 == suppliers[7].company_email
    assert supplier5 == suppliers[8].company_email

    objs = SupplierEmailNotification.objects.all()
    assert objs.count() == 7
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
Example #4
0
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_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_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()
Example #7
0
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
Example #8
0
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]
Example #10
0
def test_sends_log_in_email_to_expected_users(mock_task, settings):
    suppliers = SupplierFactory.create_batch(4)
    mocked_json = [
        {
            'id': suppliers[0].sso_id,
            'last_login': '******'
        },
        {
            'id': suppliers[1].sso_id,
            'last_login': '******'
        },
        {
            'id': suppliers[2].sso_id,
            'last_login': '******'
        },
    ]
    mocked_api = MagicMock(return_value=MagicMock(json=MagicMock(
        return_value=mocked_json)))
    SupplierEmailNotificationFactory(supplier=suppliers[1],
                                     category='no_case_studies')
    SupplierEmailNotificationFactory(supplier=suppliers[0],
                                     category='hasnt_logged_in')

    with patch(LAST_LOGIN_API_METHOD, mocked_api):
        notifications.hasnt_logged_in()

    assert mock_task.delay.call_count == 2
    call_args = mock_task.delay.call_args_list
    assert len(call_args) == 2
    assert call_args[0][1]['recipient_email'] == suppliers[1].company_email
    assert call_args[1][1]['recipient_email'] == suppliers[2].company_email
    expected_url = settings.FAB_NOTIFICATIONS_UNSUBSCRIBE_URL
    assert expected_url in call_args[0][1]['text_body']
    objs = SupplierEmailNotification.objects.all()
    assert objs.count() == 4
Example #11
0
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_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_sends_log_in_email_to_expected_users(settings):
    suppliers = SupplierFactory.create_batch(4)
    mocked_json = [
        {
            'id': suppliers[0].sso_id,
            'last_login': '******'
        },
        {
            'id': suppliers[1].sso_id,
            'last_login': '******'
        },
        {
            'id': suppliers[2].sso_id,
            'last_login': '******'
        },
    ]
    mocked_api = MagicMock(return_value=MagicMock(json=MagicMock(
        return_value=mocked_json)))
    SupplierEmailNotificationFactory(supplier=suppliers[1],
                                     category='no_case_studies')
    SupplierEmailNotificationFactory(supplier=suppliers[0],
                                     category='hasnt_logged_in')
    mail.outbox = []  # reset after emails sent by signals

    with patch(LAST_LOGIN_API_METHOD, mocked_api):
        notifications.hasnt_logged_in()

    assert len(mail.outbox) == 2
    assert mail.outbox[0].to == [suppliers[1].company_email]
    assert mail.outbox[1].to == [suppliers[2].company_email]
    objs = SupplierEmailNotification.objects.all()
    assert objs.count() == 4  # 2 + 2 created in setup
    assert settings.FAB_NOTIFICATIONS_UNSUBSCRIBE_URL in mail.outbox[0].body
Example #14
0
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']
Example #15
0
def test_doesnt_send_log_in_email_if_log_in_email_already_sent(mock_task):
    suppliers = SupplierFactory.create_batch(2)
    SupplierEmailNotificationFactory(supplier=suppliers[0],
                                     category='no_case_studies')
    SupplierEmailNotificationFactory(supplier=suppliers[1],
                                     category='hasnt_logged_in')
    mocked_json = [
        {
            'id': suppliers[0].sso_id,
            'last_login': '******'
        },
        {
            'id': suppliers[1].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()

    assert mock_task.delay.call_count == 1
    call_args = mock_task.delay.call_args_list
    assert len(call_args) == 1
    assert call_args[0][1]['recipient_email'] == suppliers[0].company_email

    assert SupplierEmailNotification.objects.all().count() == 3
def test_sends_log_in_email_when_not_logged_in_for_30_days():
    expected_subject = email.HasNotLoggedInRecentlyNotification.subject
    suppliers = SupplierFactory.create_batch(3)
    mocked_json = [
        {
            'id': suppliers[1].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()

    mocked_api.assert_called_once_with(start=datetime(2017, 1, 1, 0, 0, 0, 0),
                                       end=datetime(2017, 1, 1, 23, 59, 59,
                                                    999999))
    assert len(mail.outbox) == 1
    assert mail.outbox[0].to == [suppliers[1].company_email]
    assert mail.outbox[0].subject == expected_subject
    assert suppliers[1].name in mail.outbox[0].body
    assert suppliers[1].name in mail.outbox[0].alternatives[0][0]
    assert SupplierEmailNotification.objects.all().count() == 1
    instance = SupplierEmailNotification.objects.get()
    assert instance.supplier == suppliers[1]
    assert instance.category == 'hasnt_logged_in'
    assert instance.date_sent == timezone.now()
def test_if_ver_code_email_send_fails_previous_info_still_written_to_db_16():
    sixteen_days_ago = timezone.now() - timedelta(days=16)
    suppliers = SupplierFactory.create_batch(
        3,
        company__verified_with_code=False,
        company__date_verification_letter_sent=sixteen_days_ago)
    for supplier in suppliers:
        SupplierEmailNotificationFactory(
            supplier=supplier,
            category='verification_code_not_given',
            date_sent=(timezone.now() - timedelta(days=8)))
    send_method = 'django.core.mail.EmailMultiAlternatives.send'

    def mocked_send(self):
        # This will be the last email that will be sent to
        if self.to == [suppliers[0].company_email]:
            raise Exception

    with patch(send_method, mocked_send):
        try:
            notifications.verification_code_not_given()
        except:
            pass

    # 2 created (before email exception on 3rd) + 3 in set up
    assert SupplierEmailNotification.objects.all().count() == 5
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
Example #19
0
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_doesnt_send_log_in_email_if_log_in_email_already_sent():
    suppliers = SupplierFactory.create_batch(2)
    SupplierEmailNotificationFactory(supplier=suppliers[0],
                                     category='no_case_studies')
    SupplierEmailNotificationFactory(supplier=suppliers[1],
                                     category='hasnt_logged_in')
    mocked_json = [
        {
            'id': suppliers[0].sso_id,
            'last_login': '******'
        },
        {
            'id': suppliers[1].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 mail.outbox[0].to == [suppliers[0].company_email]
    # 2 in data setup + 1 new
    assert SupplierEmailNotification.objects.all().count() == 3
Example #21
0
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_if_log_in_email_send_fails_previous_info_still_written_to_db():
    suppliers = SupplierFactory.create_batch(3)
    mocked_json = [
        {
            'id': suppliers[0].sso_id,
            'last_login': '******'
        },
        {
            'id': suppliers[1].sso_id,
            'last_login': '******'
        },
        {
            'id': suppliers[2].sso_id,
            'last_login': '******'
        },
    ]
    mocked_api = MagicMock(return_value=MagicMock(json=MagicMock(
        return_value=mocked_json)))
    send_method = 'django.core.mail.EmailMultiAlternatives.send'

    def mocked_send(self):
        # This will be the last email that will be sent to
        if self.to == [suppliers[2].company_email]:
            raise Exception

    with patch(send_method, mocked_send):
        try:
            with patch(LAST_LOGIN_API_METHOD, mocked_api):
                notifications.hasnt_logged_in()
        except:
            pass

    # should have created the two objects before the email exception
    assert SupplierEmailNotification.objects.all().count() == 2
Example #23
0
def authed_supplier():
    """
    This fixture is used by sso_session_request_active_user fixture to ensure
    that core.authentication.SessionAuthenticationSSO authenticates.

    """

    return SupplierFactory.create(sso_id=999)
Example #24
0
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']
Example #25
0
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
Example #26
0
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_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()
Example #28
0
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
Example #29
0
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
Example #30
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