예제 #1
0
def test_can_get_email_providers(restore_provider_details):
    assert len(get_provider_details_by_notification_type('email')) == 2
    types = [
        provider.notification_type
        for provider in get_provider_details_by_notification_type('email')
    ]
    assert all('email' == notification_type for notification_type in types)
def test_can_get_email_providers(notify_db_session):
    assert len(get_provider_details_by_notification_type('email')) == 1
    types = [
        provider.notification_type
        for provider in get_provider_details_by_notification_type('email')
    ]
    assert all('email' == notification_type for notification_type in types)
def test_can_get_email_providers(setup_provider_details):
    email_providers = [
        provider for provider in setup_provider_details
        if provider.notification_type == 'email'
    ]
    assert len(get_provider_details_by_notification_type('email')) == len(
        email_providers)
    types = [
        provider.notification_type
        for provider in get_provider_details_by_notification_type('email')
    ]
    assert all('email' == notification_type for notification_type in types)
def test_should_return_highest_priority_active_provider(restore_provider_details):
    providers = provider_details_dao.get_provider_details_by_notification_type('sms')

    first = providers[0]
    second = providers[1]

    assert send_to_providers.provider_to_use('sms', '1234').name == first.identifier

    first.priority, second.priority = second.priority, first.priority

    provider_details_dao.dao_update_provider_details(first)
    provider_details_dao.dao_update_provider_details(second)

    assert send_to_providers.provider_to_use('sms', '1234').name == second.identifier

    first.priority, second.priority = second.priority, first.priority
    first.active = False

    provider_details_dao.dao_update_provider_details(first)
    provider_details_dao.dao_update_provider_details(second)

    assert send_to_providers.provider_to_use('sms', '1234').name == second.identifier

    first.active = True
    provider_details_dao.dao_update_provider_details(first)

    assert send_to_providers.provider_to_use('sms', '1234').name == first.identifier
예제 #5
0
def provider_to_use(notification_type,
                    notification_id,
                    international=False,
                    sender=None):
    active_providers_in_order = [
        p for p in get_provider_details_by_notification_type(
            notification_type, international) if p.active
    ]

    if not active_providers_in_order:
        current_app.logger.error("{} {} failed as no active providers".format(
            notification_type, notification_id))
        raise Exception("No active {} providers".format(notification_type))

    # Pour forcer l'utilisation de sinch avec un numéro abrege on utilise cette methode qui n est pas totalement sure
    # Un numéro de 5 ou 6 chiffres forcera l'utilisation de sinch
    if sender is not None and notification_type == SMS_TYPE and (
            len(sender) <= 6 and len(sender) >= 5) and sender.isdecimal():
        return clients.get_client_by_name_and_type("sinch", notification_type)

    # Pour forcer l'utilisation de pinpoint avec un numéro de téléphone à 10 chiffres comme sender
    # if sender is not None and notification_type == SMS_TYPE and sender[0] == "+":
    #     return clients.get_client_by_name_and_type("pinpoint", notification_type)

    return clients.get_client_by_name_and_type(
        active_providers_in_order[0].identifier, notification_type)
def test_should_return_highest_priority_active_provider(restore_provider_details):
    providers = provider_details_dao.get_provider_details_by_notification_type("sms")
    providers = [provider for provider in providers if provider.active]

    first = providers[0]
    second = providers[1]

    assert send_to_providers.provider_to_use("sms", "1234").name == first.identifier

    first.priority = 12
    second.priority = 10

    provider_details_dao.dao_update_provider_details(first)
    provider_details_dao.dao_update_provider_details(second)

    assert send_to_providers.provider_to_use("sms", "1234").name == second.identifier

    first.priority = 10
    first.active = False
    second.priority = 12

    provider_details_dao.dao_update_provider_details(first)
    provider_details_dao.dao_update_provider_details(second)

    assert send_to_providers.provider_to_use("sms", "1234").name == second.identifier

    first.active = True
    provider_details_dao.dao_update_provider_details(first)

    assert send_to_providers.provider_to_use("sms", "1234").name == first.identifier
def test_should_return_highest_priority_active_provider(notify_db, notify_db_session):
    providers = provider_details_dao.get_provider_details_by_notification_type('sms')

    first = providers[0]
    second = providers[1]

    assert send_to_providers.provider_to_use('sms', '1234').name == first.identifier

    first.priority = 20
    second.priority = 10

    provider_details_dao.dao_update_provider_details(first)
    provider_details_dao.dao_update_provider_details(second)

    assert send_to_providers.provider_to_use('sms', '1234').name == second.identifier

    first.priority = 10
    first.active = False
    second.priority = 20

    provider_details_dao.dao_update_provider_details(first)
    provider_details_dao.dao_update_provider_details(second)

    assert send_to_providers.provider_to_use('sms', '1234').name == second.identifier

    first.active = True
    provider_details_dao.dao_update_provider_details(first)

    assert send_to_providers.provider_to_use('sms', '1234').name == first.identifier
def provider_to_use(notification: Notification):

    if is_feature_enabled(FeatureFlag.PROVIDER_STRATEGIES_ENABLED):
        provider = provider_service.get_provider(notification)
        return clients.get_client_by_name_and_type(
            provider.identifier, notification.notification_type)

    if is_feature_enabled(FeatureFlag.TEMPLATE_SERVICE_PROVIDERS_ENABLED):
        provider_id = get_provider_id(notification)

        if provider_id:
            return clients.get_client_by_name_and_type(
                load_provider(provider_id).identifier,
                notification.notification_type)

    active_providers_in_order = [
        p for p in get_provider_details_by_notification_type(
            notification.notification_type, notification.international)
        if should_use_provider(p)
    ]

    if not active_providers_in_order:
        current_app.logger.error("{} {} failed as no active providers".format(
            notification.notification_type, notification.id))
        raise Exception("No active {} providers".format(
            notification.notification_type))

    return clients.get_client_by_name_and_type(
        active_providers_in_order[0].identifier,
        notification.notification_type)
def provider_to_use(notification_type, notification_id):
    active_providers_in_order = [
        provider for provider in get_provider_details_by_notification_type(notification_type) if provider.active
    ]

    if not active_providers_in_order:
        current_app.logger.error(
            "{} {} failed as no active providers".format(notification_type, notification_id)
        )
        raise Exception("No active {} providers".format(notification_type))

    return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)
예제 #10
0
def provider_to_use(notification_type, notification_id, international=False):
    active_providers_in_order = [
        p for p in get_provider_details_by_notification_type(notification_type, international) if p.active
    ]

    if not active_providers_in_order:
        current_app.logger.error(
            "{} {} failed as no active providers".format(notification_type, notification_id)
        )
        raise Exception("No active {} providers".format(notification_type))

    return clients.get_client_by_name_and_type(active_providers_in_order[0].identifier, notification_type)
def test_provider_to_use(restore_provider_details):
    providers = provider_details_dao.get_provider_details_by_notification_type("sms")
    first = providers[0]

    assert first.identifier == "sns"

    # provider is still SNS if SMS and sender is set
    provider = send_to_providers.provider_to_use("sms", "1234", False, "+12345678901")
    assert first.identifier == provider.name

    # provider is highest priority sms provider if sender is not set
    provider = send_to_providers.provider_to_use("sms", "1234", False)
    assert first.identifier == provider.name
예제 #12
0
def test_provider_to_use(restore_provider_details):
    providers = provider_details_dao.get_provider_details_by_notification_type(
        'sms')
    first = providers[0]

    # provider is pinpoint if sms and sender is set
    provider = send_to_providers.provider_to_use('sms', '1234', False,
                                                 '+12345678901')
    assert "pinpoint" == provider.name

    # provider is highest priority sms provider if sender is not set
    provider = send_to_providers.provider_to_use('sms', '1234', False)
    assert first.identifier == provider.name
예제 #13
0
def update_letter_notifications_to_sent_to_dvla(self, notification_references):
    # This task will be called by the FTP app to update notifications as sent to DVLA
    provider = get_provider_details_by_notification_type(LETTER_TYPE)[0]

    updated_count, _ = dao_update_notifications_by_reference(
        notification_references, {
            'status': NOTIFICATION_SENDING,
            'sent_by': provider.identifier,
            'sent_at': datetime.utcnow(),
            'updated_at': datetime.utcnow()
        })

    current_app.logger.info(
        "Updated {} letter notifications to sending".format(updated_count))
예제 #14
0
def provider_to_use(notification_type, international=False):
    active_providers = [
        p for p in get_provider_details_by_notification_type(notification_type, international) if p.active
    ]

    if not active_providers:
        current_app.logger.error(
            "{} failed as no active providers".format(notification_type)
        )
        raise Exception("No active {} providers".format(notification_type))

    chosen_provider = random.choices(active_providers, weights=[p.priority for p in active_providers])[0]

    return clients.get_client_by_name_and_type(chosen_provider.identifier, notification_type)
def test_can_get_email_providers_in_order_of_priority(setup_provider_details):
    providers = get_provider_details_by_notification_type('email')
    [prioritised_email_provider, deprioritised_email_provider, _, _,
     _] = setup_provider_details
    assert providers[0].identifier == prioritised_email_provider.identifier
    assert providers[1].identifier == deprioritised_email_provider.identifier
def test_can_get_sms_providers_in_order(restore_provider_details):
    providers = get_provider_details_by_notification_type('sms')

    assert providers[0].identifier == "mmg"
    assert providers[1].identifier == "firetext"
    assert providers[2].identifier == "loadtesting"
def test_can_get_email_providers_in_order(restore_provider_details):
    providers = get_provider_details_by_notification_type('email')

    assert providers[0].identifier == "ses"
def test_can_get_email_providers(restore_provider_details):
    assert len(get_provider_details_by_notification_type('email')) == 1
    types = [provider.notification_type for provider in get_provider_details_by_notification_type('email')]
    assert all('email' == notification_type for notification_type in types)
예제 #19
0
def test_can_get_email_providers_in_order_of_priority(
        restore_provider_details):
    providers = get_provider_details_by_notification_type('email')

    assert providers[0].identifier == "ses"
예제 #20
0
def test_can_get_sms_providers_in_order_of_priority(restore_provider_details):
    providers = get_provider_details_by_notification_type('sms', False)

    assert providers[0].priority < providers[1].priority
예제 #21
0
def test_can_get_sms_international_providers(restore_provider_details):
    sms_providers = get_provider_details_by_notification_type('sms', True)
    assert len(sms_providers) == 1
    assert all('sms' == prov.notification_type for prov in sms_providers)
    assert all(prov.supports_international for prov in sms_providers)
예제 #22
0
def test_can_get_sms_non_international_providers(restore_provider_details):
    sms_providers = get_provider_details_by_notification_type('sms')
    assert len(sms_providers) == 5
    assert all('sms' == prov.notification_type for prov in sms_providers)
def test_can_get_sms_providers(restore_provider_details):
    sms_providers = get_provider_details_by_notification_type('sms')
    assert len(sms_providers) == 3
    assert all('sms' == prov.notification_type for prov in sms_providers)
def test_can_get_sms_non_international_providers(notify_db_session):
    sms_providers = get_provider_details_by_notification_type('sms')
    assert len(sms_providers) == 2
    assert all('sms' == prov.notification_type for prov in sms_providers)