示例#1
0
def test_user_update_schema_accepts_valid_attribute_pairs(
        user_attribute, user_value):
    update_dict = {user_attribute: user_value}
    from app.schemas import user_update_schema_load_json

    data, errors = user_update_schema_load_json.load(update_dict)
    assert not errors
示例#2
0
def test_user_update_schema_rejects_invalid_attribute_pairs(
        user_attribute, user_value):
    from app.schemas import user_update_schema_load_json
    update_dict = {user_attribute: user_value}

    with pytest.raises(ValidationError):
        data, errors = user_update_schema_load_json.load(update_dict)
示例#3
0
def update_user_attribute(user_id):
    user_to_update = get_user_by_id(user_id=user_id)
    req_json = request.get_json()
    update_dct, errors = user_update_schema_load_json.load(req_json)
    if errors:
        raise InvalidRequest(errors, status_code=400)
    save_user_attribute(user_to_update, update_dict=update_dct)
    return jsonify(data=user_schema.dump(user_to_update).data), 200
示例#4
0
文件: rest.py 项目: qld-gov-au/notify
def update_user_attribute(user_id):
    user_to_update = get_user_by_id(user_id=user_id)
    req_json = request.get_json()
    update_dct, errors = user_update_schema_load_json.load(req_json)
    if errors:
        raise InvalidRequest(errors, status_code=400)
    save_user_attribute(user_to_update, update_dict=update_dct)
    return jsonify(data=user_to_update.serialize()), 200
def test_user_update_schema_rejects_invalid_attribute_pairs(user_attribute, user_value):
    from app.schemas import user_update_schema_load_json
    update_dict = {
        user_attribute: user_value
    }

    with pytest.raises(ValidationError):
        data, errors = user_update_schema_load_json.load(update_dict)
def test_user_update_schema_accepts_valid_attribute_pairs(user_attribute, user_value):
    update_dict = {
        user_attribute: user_value
    }
    from app.schemas import user_update_schema_load_json

    data, errors = user_update_schema_load_json.load(update_dict)
    assert not errors
示例#7
0
def update_user_attribute(user_id):
    user_to_update = get_user_by_id(user_id=user_id)
    req_json = request.get_json()
    if 'updated_by' in req_json:
        updated_by = get_user_by_id(user_id=req_json.pop('updated_by'))
    else:
        updated_by = None

    update_dct, errors = user_update_schema_load_json.load(req_json)
    if errors:
        raise InvalidRequest(errors, status_code=400)

    save_user_attribute(user_to_update, update_dict=update_dct)

    service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])

    # Alert user that account change took place
    user_alert_dct = update_dct.copy()
    user_alert_dct.pop('blocked', None)
    user_alert_dct.pop('current_session_id', None)
    if not updated_by and user_alert_dct:
        _update_alert(user_to_update, user_alert_dct)

    # Alert that team member edit user
    if updated_by:
        if 'email_address' in update_dct:
            template = dao_get_template_by_id(
                current_app.config['TEAM_MEMBER_EDIT_EMAIL_TEMPLATE_ID'])
            recipient = user_to_update.email_address
            reply_to = template.service.get_default_reply_to_email_address()
        elif 'mobile_number' in update_dct:
            template = dao_get_template_by_id(
                current_app.config['TEAM_MEMBER_EDIT_MOBILE_TEMPLATE_ID'])
            recipient = user_to_update.mobile_number
            reply_to = template.service.get_default_sms_sender()
        else:
            return jsonify(data=user_to_update.serialize()), 200

        saved_notification = persist_notification(
            template_id=template.id,
            template_version=template.version,
            recipient=recipient,
            service=service,
            personalisation={
                'name': user_to_update.name,
                'servicemanagername': updated_by.name,
                'email address': user_to_update.email_address
            },
            notification_type=template.template_type,
            api_key_id=None,
            key_type=KEY_TYPE_NORMAL,
            reply_to_text=reply_to)

        send_notification_to_queue(saved_notification,
                                   False,
                                   queue=QueueNames.NOTIFY)

    return jsonify(data=user_to_update.serialize()), 200
示例#8
0
def test_user_update_schema_rejects_disallowed_attribute_keys(user_attribute):
    update_dict = {user_attribute: 'not important'}
    from app.schemas import user_update_schema_load_json

    with pytest.raises(ValidationError) as excinfo:
        data, errors = user_update_schema_load_json.load(update_dict)

    assert excinfo.value.messages['_schema'][
        0] == 'Unknown field name {}'.format(user_attribute)
def test_user_update_schema_rejects_disallowed_attribute_keys(user_attribute):
    update_dict = {
        user_attribute: 'not important'
    }
    from app.schemas import user_update_schema_load_json

    with pytest.raises(ValidationError) as excinfo:
        data, errors = user_update_schema_load_json.load(update_dict)

    assert excinfo.value.messages['_schema'][0] == 'Unknown field name {}'.format(user_attribute)