Ejemplo n.º 1
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def test_sends_ver_code_email_to_expected_users(mock_task):
    eight_days_ago = timezone.now() - timedelta(days=8)
    twelve_days_ago = timezone.now() - timedelta(days=12)
    sixteen_days_ago = timezone.now() - timedelta(days=16)
    SupplierFactory.create_batch(
        3,
        company__verified_with_code=True,
        company__date_verification_letter_sent=eight_days_ago)
    suppliers8 = SupplierFactory.create_batch(
        3,
        company__verified_with_code=False,
        company__date_verification_letter_sent=eight_days_ago)
    SupplierFactory.create_batch(
        3,
        company__verified_with_code=False,
        company__date_verification_letter_sent=twelve_days_ago)
    suppliers16 = SupplierFactory.create_batch(
        3,
        company__verified_with_code=False,
        company__date_verification_letter_sent=sixteen_days_ago)
    SupplierFactory.create_batch(
        3,
        company__verified_with_code=True,
        company__date_verification_letter_sent=sixteen_days_ago)
    SupplierEmailNotificationFactory(supplier=suppliers8[2],
                                     category='verification_code_not_given')
    SupplierEmailNotificationFactory(supplier=suppliers16[2],
                                     category='verification_code_2nd_email')
    for supplier in suppliers16:
        SupplierEmailNotificationFactory(
            supplier=supplier,
            category='verification_code_not_given',
            date_sent=eight_days_ago)
    SupplierEmailNotificationFactory(supplier=suppliers8[1],
                                     category='hasnt_logged_in')
    SupplierEmailNotificationFactory(supplier=suppliers16[1],
                                     category='hasnt_logged_in')
    notifications.verification_code_not_given()

    assert mock_task.delay.call_count == 4
    call_args = mock_task.delay.call_args_list
    assert len(call_args) == 4
    assert call_args[0][1]['recipient_email'] == suppliers8[1].company_email
    assert call_args[1][1]['recipient_email'] == suppliers8[0].company_email
    assert call_args[2][1]['recipient_email'] == suppliers16[1].company_email
    assert call_args[3][1]['recipient_email'] == suppliers16[0].company_email
    objs = SupplierEmailNotification.objects.all()

    assert objs.count() == 11
Ejemplo n.º 9
0
def test_sends_ver_code_email_to_expected_users():
    eight_days_ago = timezone.now() - timedelta(days=8)
    twelve_days_ago = timezone.now() - timedelta(days=12)
    sixteen_days_ago = timezone.now() - timedelta(days=16)
    SupplierFactory.create_batch(
        3,
        company__verified_with_code=True,
        company__date_verification_letter_sent=eight_days_ago)
    suppliers8 = SupplierFactory.create_batch(
        3,
        company__verified_with_code=False,
        company__date_verification_letter_sent=eight_days_ago)
    SupplierFactory.create_batch(
        3,
        company__verified_with_code=False,
        company__date_verification_letter_sent=twelve_days_ago)
    suppliers16 = SupplierFactory.create_batch(
        3,
        company__verified_with_code=False,
        company__date_verification_letter_sent=sixteen_days_ago)
    SupplierFactory.create_batch(
        3,
        company__verified_with_code=True,
        company__date_verification_letter_sent=sixteen_days_ago)
    SupplierEmailNotificationFactory(supplier=suppliers8[2],
                                     category='verification_code_not_given')
    SupplierEmailNotificationFactory(supplier=suppliers16[2],
                                     category='verification_code_2nd_email')
    for supplier in suppliers16:
        SupplierEmailNotificationFactory(
            supplier=supplier,
            category='verification_code_not_given',
            date_sent=eight_days_ago)
    SupplierEmailNotificationFactory(supplier=suppliers8[1],
                                     category='hasnt_logged_in')
    SupplierEmailNotificationFactory(supplier=suppliers16[1],
                                     category='hasnt_logged_in')
    mail.outbox = []  # reset after emails sent by signals

    notifications.verification_code_not_given()

    assert len(mail.outbox) == 4
    assert mail.outbox[0].to == [suppliers8[1].company_email]
    assert mail.outbox[1].to == [suppliers8[0].company_email]
    assert mail.outbox[2].to == [suppliers16[1].company_email]
    assert mail.outbox[3].to == [suppliers16[0].company_email]
    objs = SupplierEmailNotification.objects.all()
    assert objs.count() == 11  # 4 + 7 created in setup
Ejemplo n.º 10
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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()
Ejemplo n.º 14
0
    def test_download_csv_supplier_email_notification(self):
        supplier_email_notification = SupplierEmailNotificationFactory()

        data = {
            'action': 'download_csv',
            '_selected_action': SupplierEmailNotification.objects.all(
            ).values_list('pk', flat=True)
        }
        response = self.client.post(
            reverse(
                'admin:notifications_supplieremailnotification_changelist'
            ),
            data,
            follow=True
        )

        expected_data = OrderedDict([
            ('category', str(supplier_email_notification.category)),
            ('date_sent', str(supplier_email_notification.date_sent)),
            ('id', str(supplier_email_notification.id)),
            ('supplier', str(supplier_email_notification.supplier.id)),
        ])
        actual = str(response.content, 'utf-8').split('\r\n')

        assert actual[0] == ','.join(expected_data.keys())
        assert actual[1] == ','.join(expected_data.values())
Ejemplo n.º 15
0
def test_doesnt_send_case_study_email_if_case_study_email_already_sent(
        settings):
    eight_days_ago = timezone.now() - timedelta(days=8)
    suppliers = SupplierFactory.create_batch(2, date_joined=eight_days_ago)
    SupplierEmailNotificationFactory(supplier=suppliers[0],
                                     category='no_case_studies')
    SupplierEmailNotificationFactory(supplier=suppliers[1],
                                     category='hasnt_logged_in')
    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 == [suppliers[1].company_email]
    # what we created in data setup + 1 new
    assert SupplierEmailNotification.objects.all().count() == 3
Ejemplo n.º 16
0
def test_doesnt_send_case_study_email_if_case_study_email_already_sent(
        mock_task, settings):
    eight_days_ago = timezone.now() - timedelta(days=8)
    suppliers = SupplierFactory.create_batch(2, date_joined=eight_days_ago)
    SupplierEmailNotificationFactory(supplier=suppliers[0],
                                     category='no_case_studies')
    SupplierEmailNotificationFactory(supplier=suppliers[1],
                                     category='hasnt_logged_in')

    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'] == suppliers[1].company_email

    assert SupplierEmailNotification.objects.all().count() == 3
Ejemplo n.º 17
0
    def test_download_csv_supplier_email_notification_no_company(self):
        SupplierEmailNotificationFactory(supplier__company=None)

        response = self.client.get(
            reverse('admin:notifications_supplieremailnotification_changelist')
        )

        assert response.status_code == 200
Ejemplo n.º 18
0
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()
Ejemplo n.º 19
0
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
Ejemplo n.º 20
0
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
Ejemplo n.º 21
0
def test_sends_case_study_email_to_expected_users():
    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')
    mail.outbox = []  # reset after emails sent by signals

    notifications.no_case_studies()

    assert len(mail.outbox) == 5
    assert mail.outbox[0].to == [suppliers[4].company_email]
    assert mail.outbox[1].to == [suppliers[5].company_email]
    assert mail.outbox[2].to == [suppliers[6].company_email]
    assert mail.outbox[3].to == [suppliers[7].company_email]
    assert mail.outbox[4].to == [suppliers[8].company_email]
    objs = SupplierEmailNotification.objects.all()
    assert objs.count() == 7  # 5 + 2 created in setup
Ejemplo n.º 22
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
Ejemplo n.º 23
0
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
Ejemplo n.º 24
0
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
Ejemplo n.º 25
0
def test_supplieremailnotifications_str_method():
    instance = SupplierEmailNotificationFactory.build(
        supplier__company_email='*****@*****.**',
        category='no_case_studies'
    )
    assert str(instance) == '[email protected]: no_case_studies'