Beispiel #1
0
def test_add_and_commit_whitelisted_contacts_saves_data(sample_service):
    whitelist = ServiceWhitelist.from_string(sample_service.id, EMAIL_TYPE, '*****@*****.**')

    dao_add_and_commit_whitelisted_contacts([whitelist])

    db_contents = ServiceWhitelist.query.all()
    assert len(db_contents) == 1
    assert db_contents[0].id == whitelist.id
def test_add_and_commit_whitelisted_contacts_saves_data(sample_service):
    whitelist = ServiceWhitelist.from_string(sample_service.id, EMAIL_TYPE, '*****@*****.**')

    dao_add_and_commit_whitelisted_contacts([whitelist])

    db_contents = ServiceWhitelist.query.all()
    assert len(db_contents) == 1
    assert db_contents[0].id == whitelist.id
Beispiel #3
0
def test_remove_service_whitelist_only_removes_for_my_service(notify_db, notify_db_session):
    service_1 = create_service(notify_db, notify_db_session, service_name="service 1")
    service_2 = create_service(notify_db, notify_db_session, service_name="service 2")
    dao_add_and_commit_whitelisted_contacts([
        ServiceWhitelist.from_string(service_1.id, EMAIL_TYPE, '*****@*****.**'),
        ServiceWhitelist.from_string(service_2.id, EMAIL_TYPE, '*****@*****.**')
    ])

    dao_remove_service_whitelist(service_1.id)

    assert service_1.whitelist == []
    assert len(service_2.whitelist) == 1
def test_get_whitelist_separates_emails_and_phones(client, sample_service):
    dao_add_and_commit_whitelisted_contacts([
        ServiceWhitelist.from_string(sample_service.id, EMAIL_TYPE, '*****@*****.**'),
        ServiceWhitelist.from_string(sample_service.id, MOBILE_TYPE, '07123456789')
    ])

    response = client.get('service/{}/whitelist'.format(sample_service.id), headers=[create_authorization_header()])
    assert response.status_code == 200
    assert json.loads(response.get_data(as_text=True)) == {
        'email_addresses': ['*****@*****.**'],
        'phone_numbers': ['07123456789']
    }
def test_remove_service_whitelist_only_removes_for_my_service(notify_db, notify_db_session):
    service_1 = create_service(notify_db, notify_db_session, service_name="service 1")
    service_2 = create_service(notify_db, notify_db_session, service_name="service 2")
    dao_add_and_commit_whitelisted_contacts([
        ServiceWhitelist.from_string(service_1.id, EMAIL_TYPE, '*****@*****.**'),
        ServiceWhitelist.from_string(service_2.id, EMAIL_TYPE, '*****@*****.**')
    ])

    dao_remove_service_whitelist(service_1.id)

    assert service_1.whitelist == []
    assert len(service_2.whitelist) == 1
Beispiel #6
0
def update_whitelist(service_id):
    # doesn't commit so if there are any errors, we preserve old values in db
    dao_remove_service_whitelist(service_id)
    try:
        whitelist_objs = get_whitelist_objects(service_id, request.get_json())
    except ValueError as e:
        current_app.logger.exception(e)
        dao_rollback()
        msg = '{} is not a valid email address or phone number'.format(str(e))
        raise InvalidRequest(msg, 400)
    else:
        dao_add_and_commit_whitelisted_contacts(whitelist_objs)
        return '', 204
Beispiel #7
0
def test_get_whitelist_separates_emails_and_phones(client, sample_service):
    dao_add_and_commit_whitelisted_contacts([
        ServiceWhitelist.from_string(sample_service.id, EMAIL_TYPE,
                                     '*****@*****.**'),
        ServiceWhitelist.from_string(sample_service.id, MOBILE_TYPE,
                                     '0412345678'),
        ServiceWhitelist.from_string(sample_service.id, MOBILE_TYPE,
                                     '+1800-555-5555'),
    ])

    response = client.get('service/{}/whitelist'.format(sample_service.id),
                          headers=[create_authorization_header()])
    assert response.status_code == 200
    json_resp = json.loads(response.get_data(as_text=True))
    assert json_resp['email_addresses'] == ['*****@*****.**']
    assert sorted(json_resp['phone_numbers']) == sorted(
        ['+1800-555-5555', '0412345678'])
def test_send_one_off_notification_raises_if_cant_send_to_recipient(
    notify_db_session,
    recipient,
):
    service = create_service(restricted=True)
    template = create_template(service=service)
    dao_add_and_commit_whitelisted_contacts([
        ServiceWhitelist.from_string(service.id, MOBILE_TYPE, '07700900123'),
    ])

    post_data = {
        'template_id': str(template.id),
        'to': recipient,
        'created_by': str(service.created_by_id)
    }

    with pytest.raises(BadRequestError) as e:
        send_one_off_notification(service.id, post_data)

    assert 'service is in trial mode' in e.value.message