Beispiel #1
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())
Beispiel #2
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)
Beispiel #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)
Beispiel #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())
Beispiel #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)
Beispiel #6
0
# 版本号
__version__ = '0.0.3'

# flask
app = Flask(__name__)
app.config.from_object('app.config_default')

# 加载配置
if 'GIT_WEBHOOK_CONFIG' in os.environ:
    app.config.from_envvar('GIT_WEBHOOK_CONFIG')
else:
    app.config.from_object('app.config')

# validator
v = Validator()

# flask-sqlalchemy
app.config['SQLALCHEMY_DATABASE_URI'] = app.config['DATABASE_URI']
SQLAlchemyDB = SQLAlchemy(app)

# celery
platforms.C_FORCE_ROOT = True
celeryInstance = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celeryInstance.conf.update(app.config)

# github login
github = GitHub(app)

from app.database import model  # noqa
from app import views  # noqa
Beispiel #7
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import json
import pytest
from schema import Use
from flask import Flask
from app.utils.validator import Validator
from app.utils.ResponseUtil import standard_response
from . import success, load_data

v = Validator()


@v.register('even')
def even():
    return Use(int, lambda value: value % 2)


SCHEMA = {
    'name': v.str(),
    'age': v.int(min=18, max=99),
    'sex': v.enum('男', '女'),
    'number': v.even(),
    v.optional('email'): v.email()
}
EXPECT = {
    'user_id': 123,
    'name': 'kk',
    'age': 21,
    'sex': '男',
Beispiel #8
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
Beispiel #9
0
def test_validator_returns_invalid_if_redundant_fields_in_request_with_all_required_string_fields(redundant_request):
    validator = Validator(redundant_request)
    assert validator.request_invalid()
    assert validator.errors['school'] == '"school" not required!'
Beispiel #10
0
def test_validator_returns_invalid_if_request_not_json():
    validator = Validator(Request('non-JSON string'))
    assert validator.request_invalid()
    assert validator.errors['error'] == 'Request not specified in JSON format!'