コード例 #1
0
ファイル: reset.py プロジェクト: tjucch/webFrame
def test_data():
    SQLModel.init_db()

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    # Session.add(u.id)

    # form = dict(
    #     content='test weibo',
    # )
    # w = Weibo.add(form, u.id)
    # form = dict(
    #     id=1,
    #     content='test comment',
    #     user_id=1,
    # )
    # id = Weibo.insert(form)
    # log('id', id)
    # # Weibo.comment_add(form, u.id)

    SQLModel.connection.close()
コード例 #2
0
def run(host, port):
    SQLModel.init_db()
    log('开始运行于', 'http://{}:{}'.format(host, port))
    with socket.socket() as s:
        s.bind((host, port))
        s.listen()
        while True:
            connection, address = s.accept()
            log('ip {}'.format(address))
            _thread.start_new_thread(process_request, (connection, ))
コード例 #3
0
def test_data():
    SQLModel.init_db()

    # Test.new({})

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)
コード例 #4
0
ファイル: server.py プロジェクト: sulinalinhang/ajax_weibo
def configured_app():
    SQLModel.init_connection()

    app = Flask(__name__)
    app.register_blueprint(public)
    app.register_blueprint(user)
    app.register_blueprint(weibo_route)
    app.register_blueprint(api_weibo_route)
    # app.register_blueprint(todo_view)
    # app.register_blueprint(todo_api)
    log('url_map', app.url_map)
    return app
コード例 #5
0
ファイル: app.py プロジェクト: Rolling-meatballs/web_sever
def configured_app():
    app = Flask(__name__)
    app.register_blueprint(public_bp)
    app.register_blueprint(user_bp)
    app.register_blueprint(weibo_bp)
    app.secret_key = secret_key
    SQLModel.init_db()

    app.errorhandler(404)(error_view)
    app.template_filter('formatted_time')(formatted_time)
    app.context_processor(current_time)

    return app
コード例 #6
0
ファイル: server.py プロジェクト: hanrina2/socket_weibo
def run(host, port):
    # 初始化数据库
    SQLModel.init_db()
    log('数据库链接初始化 <{}>'.format(SQLModel.connection.host_info))
    log('开始运行于 http://{}:{}'.format(host, port))
    # 初始化 socket
    with socket.socket() as s:
        s.bind((host, port))
        s.listen()
        while True:
            connection, address = s.accept()
            log('请求地址 {}'.format(address))
            _thread.start_new_thread(process_request, (connection, ))
コード例 #7
0
ファイル: reset.py プロジェクト: ronin-hang/weibo-test
def test_data():
    SQLModel.init_db()

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    form = dict(
        content='test weibo',
        comment='[]'
    )
    w = Weibo.add(form, u.id)
コード例 #8
0
ファイル: reset.py プロジェクト: Rolling-meatballs/web_sever
def fake_data():
    SQLModel.init_db()

    Test.new({})

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    Session.add(u.id)

    form = dict(title='test todo ajax', )
    t = TodoAjax.add(form, u.id)
コード例 #9
0
def run(host, port):
    """
    启动服务器
    """
    # 初始化 ORM
    SQLModel.init_db()
    log('开始运行于', 'http://{}:{}'.format(host, port))
    with socket.socket() as s:
        s.bind((host, port))
        # 监听 接受 读取请求数据 解码成字符串
        s.listen()
        # 无限循环来处理请求
        while True:
            connection, address = s.accept()
            # 第二个参数类型必须是 tuple
            # log('ip {}'.format(address))
            _thread.start_new_thread(process_request, (connection, ))
コード例 #10
0
def test_data():
    SQLModel.init_db()

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    form = dict(content='test weibo', )
    w = Weibo.add(form, u.id)
    form = dict(
        content='test comment',
        weibo_id=w.id,
    )
    Weibo.comment_add(form, u.id)
コード例 #11
0
ファイル: server.py プロジェクト: COPPERHAMMER/MVC-web
def run(host, port):
    """
    启动服务器
    """
    # 初始化数据库
    SQLModel.init_db()
    log('数据库链接初始化 <{}>'.format(SQLModel.connection.host_info))
    # 初始化 socket 套路
    log('开始运行于 http://{}:{}'.format(host, port))
    with socket.socket() as s:
        s.bind((host, port))
        # 监听 接受 读取请求数据 解码成字符串
        s.listen()
        # 无限循环来处理请求
        while True:
            connection, address = s.accept()
            # 第二个参数类型必须是 tuple
            log('请求地址 {}'.format(address))
            _thread.start_new_thread(process_request, (connection, ))
コード例 #12
0
def fake_data():
    SQLModel.init_db()

    Test.new({})

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    Session.add(u.id)

    form = dict(title='test todo ajax', )
    todo = Todo.add(form, u.id)
    t = TodoAjax.add(form, u.id)

    form = dict(content='test weibo', )
    weibo = Weibo.add(form, u.id)
    comment = Comment.add(form, u.id)
コード例 #13
0
ファイル: reset.py プロジェクト: xiecang/PyWebFramework
def test_data():
    SQLModel.init_db()

    Test.new({})

    # guest user
    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    Session.add(u.id)

    # test todo insert
    form = dict(
        title='test todo',
        user_id=u.id,
    )
    Todo.insert(form)

    # test weibo insert
    form = dict(
        content='test weibo',
        user_id=u.id,
    )
    weibo_id = Weibo.insert(form)

    # test comment insert
    form = dict(
        content='test comment',
        weibo_id=weibo_id,
        user_id=u.id,
    )
    Comment.insert(form)

    SQLModel.connection.close()
コード例 #14
0
def test_data():
    SQLModel.init_db()
コード例 #15
0
def fake_data():
    log('fake data')
    SQLModel.init_db()

    Test.new({})

    form1 = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    form2 = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u2, result = User.register(form1)
    u1, result = User.register(form2)

    Session.add(u1.id)
    Session.add(u2.id)

    form = dict(title='test todo ajax', )
    t = TodoAjax.add(form, u1.id)

    # weibo
    form1 = dict(
        content="weibo test user zjt",
        user_id=u1.id,
    )
    form2 = dict(
        content="weibo test user abc",
        user_id=u2.id,
    )
    w1 = Weibo.add(form1, u1.id).id
    w2 = Weibo.add(form2, u2.id).id
    w1 = Weibo.add(form1, u2.id).id
    w2 = Weibo.add(form2, u1.id).id

    # comment
    form1 = dict(
        content="weibo test user zjt",
        user_id=u1.id,
        weibo_id=w1,
    )
    form2 = dict(
        content="weibo test user abc",
        user_id=u2.id,
        weibo_id=w1,
    )
    # comment
    form3 = dict(
        content="weibo test user zjt",
        user_id=u1.id,
        weibo_id=w2,
    )
    form4 = dict(
        content="weibo test user abc",
        user_id=u2.id,
        weibo_id=w2,
    )
    Comment.new(form1)
    Comment.new(form2)
    Comment.new(form3)
    Comment.new(form4)

    SQLModel.connection.close()
コード例 #16
0
def test_data():
    SQLModel.init_db()

    Test.new({})
コード例 #17
0
ファイル: app.py プロジェクト: Rolling-meatballs/web_sever
def configured_app():
    app = Flask(__name__)
    app.register_blueprint(public_bp)
    app.register_blueprint(user_bp)
    app.register_blueprint(weibo_bp)
    app.secret_key = secret_key
    SQLModel.init_db()

    app.errorhandler(404)(error_view)
    app.template_filter('formatted_time')(formatted_time)
    app.context_processor(current_time)

    return app

if __name__ == '__main__':
    SQLModel.init_db()
    config = dict(
        debug=True,
        host='localhost',
        port=80,
    )
    app = configured_app()
    log('url_map', app.url_map)
    app.run(**config)

# def response_for_path(request):
#     """
#     根据 path 调用相应的处理函数
#     没有处理的 path 会返回 404
#     """
#     r = {}
コード例 #18
0
def t_one():
    SQLModel.init_db()
    one = User.all(role=UserRole.normal)
    log('user one', one)
コード例 #19
0
ファイル: reset.py プロジェクト: sulinalinhang/ajax_weibo
def test_session_data():
    form = dict(
        session_id='dsacbhdjshabzmsd',
        user_id=2,
        expired_time=time.time(),
    )
    Session.new(form)


def test_weibo_date():
    form = dict(
        content='第一条微博',
        user_id=1,
    )
    Weibo.new(form)


def test_comment_date():
    form = dict(content='第一条评论', user_id=1, weibo_id=1)
    Comment.new(form)


if __name__ == '__main__':
    recreate_database()
    SQLModel.init_connection()
    test_user_data()
    test_session_data()
    test_weibo_date()
    test_comment_date()