Esempio n. 1
0
def get_id():
    data = request.get_json() or {}

    # Validation
    try:
        Validator.validate_required_fields({'username': str}, data)
    except ValueError as exception:
        return bad_request(exception.args[0])

    return jsonify(User.query.filter_by(username=data['username']).first_or_404().id)
Esempio n. 2
0
def get_user_information():
    data = request.get_json() or {}

    # Validation
    try:
        Validator.validate_required_fields({'id': int}, data)
    except ValueError as exception:
        return bad_request(exception.args[0])

    return jsonify(User.query.get_or_404(data['id']).to_dict())
Esempio n. 3
0
def find_room():
    data = request.get_json() or {}

    # Validation
    try:
        Validator.validate_required_fields({'request': str}, data)
    except ValueError as exception:
        return bad_request(exception.args[0])

    rooms_list = []
    for room in current_user.get_sorted_rooms_by_timestamp(current_user):
        if re.search(data['request'].lower(), room['title'].lower()):
            rooms_list.append(room)
    return jsonify(rooms_list)
Esempio n. 4
0
def get_dialog():
    data = request.get_json() or {}

    # Validation
    try:
        Validator.validate_required_fields({'profile_id': int}, data)
    except ValueError as exception:
        return bad_request(exception.args[0])

    dialog = Dialog.get_object(current_user, User.query.get_or_404(data['profile_id']))
    if dialog is None:
        return jsonify([])
    else:
        return jsonify(dialog.get_messages())
Esempio n. 5
0
def find_user():
    data = request.get_json() or {}

    # Validation
    try:
        Validator.validate_required_fields({'request': str}, data)
    except ValueError as exception:
        return bad_request(exception.args[0])

    user_list = []
    for user in User.query.all():
        search_line = (user.name + ' ' + user.surname + ' ' +
                       user.username).lower()
        if re.search(data['request'].lower(),
                     search_line) and user != current_user:
            user_list.append(user.to_dict())
    return jsonify(user_list)
Esempio n. 6
0
def test_abstract_method_in_base_validator_logs_no_errors(invalid_signup_data):
    validator = Validator(invalid_signup_data)
    validator.validate_required_fields()
    assert not validator.errors