Ejemplo n.º 1
0
def testdb(loop):
    'test class User - add a new user'
    print('Create db pool...')
    r = yield from orm.create_pool(loop=loop,
                                   host='127.0.0.1',
                                   port=3306,
                                   user='******',
                                   password='******',
                                   db='awesome')
    print('r : %s' % r)
    # 以下为测试:
    print('Create a new user...')

    "create a user with fixed <id> and <created_at>"
    #u = User(email='*****@*****.**', passwd='password', admin=True, name='testname2', image='blank', id='testid2',created_at='1.0')

    "create a user with fixed auto-generated <id> and <created_at>"
    u = User(email='*****@*****.**',
             passwd='password',
             admin=True,
             name='testname3',
             image='blank',
             id=None,
             created_at=None)  #
    print('Save the new user into database...')
    r = yield from u.save()
    print('r : %s' % r)
Ejemplo n.º 2
0
def test(loop):
    yield from create_pool(loop=loop, user='******', password='******', db='test')
    u = User(name='aaa', email='*****@*****.**', passwd='aaa', image='about:blank')
    yield from u.save()
    #    r = yield from u.findAll()
    #    print(r)
    yield from destory_pool()
Ejemplo n.º 3
0
def test(loop):
    #创建连接池
    yield from orm.create_pool(loop,user='******',password='******',database='awesome')
    #创建对象
    u=User(name='Test231',email='test123@wxample',passwd='123456',image='about:blank')
    #调用保存方法
    yield from u.save()
Ejemplo n.º 4
0
def init(loop):
    yield from orm.create_pool(loop=loop, **configs.db)
    app = web.Application(loop=loop, middlewares=[response_factory])
    # app.router.add_route()
    add_routes(app, 'handlers')

    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Ejemplo n.º 5
0
def test(loop):
    yield from orm.create_pool(loop=loop,
                               user='******',
                               password='******',
                               database='awesome')
    u = User(name='Yao',
             email='*****@*****.**',
             passwd="sas",
             image='about:blank')
    yield from u.save()
Ejemplo n.º 6
0
def test(loop):
    yield from orm.create_pool(loop=loop,
                               user='******',
                               password='******',
                               db='awesome')
    u = User(name='test77',
             email='*****@*****.**',
             passwd='test',
             image='about:blank')
    yield from u.save()
Ejemplo n.º 7
0
def find_test(loop):
    yield from orm.create_pool(loop=loop,
                               host='123.206.178.243',
                               user='******',
                               password='******',
                               db='awesome')

    u = yield from User().find(
        '001502421565775576b9c8a80e847e3b6ca4f45e5573712000')
    print(u)
Ejemplo n.º 8
0
def init(loop):
    yield from orm.create_pool(loop=loop, **configs.db)
    app = web.Application(loop=loop, middlewares=[
        logger_factory, auth_factory, response_factory
    ])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Ejemplo n.º 9
0
def test():
    yield from orm.create_pool(user='******',
                               password='******',
                               database='awesome')

    u = User(name='Test',
             email='[email protected]',
             passwd='123456',
             image='about-blank')

    yield from u.save()
Ejemplo n.º 10
0
def testSave():
    yield from orm.create_pool(loop,
                               user='******',
                               password='******',
                               db='awesome')
    u = User(name='awsome_admin',
             email='*****@*****.**',
             passwd='1234567890',
             image='about:blank',
             admin=True)
    yield from u.save()
Ejemplo n.º 11
0
def test():
    yield from orm.create_pool(user='******',
                               password='******',
                               database='awesome')

    u = User(name='Test',
             email='*****@*****.**',
             passwd='1234567890',
             image='about:blank')

    yield from u.save()
Ejemplo n.º 12
0
def init(loop):
    yield from orm.create_pool(loop=loop, **configs.db)
    app = web.Application(loop=loop, middlewares=[
        logger_factory, auth_factory, response_factory
    ])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 8050)
    logging.info('server started at http://127.0.0.1:8050...')
    return srv
Ejemplo n.º 13
0
def test(loop):
    db_dict = {'user': '******', 'password': '******', 'db': 'awesome'}
    yield from orm.create_pool(loop=loop, **db_dict)
    # yield from orm.create_pool(user='******', password='******', database='awesome')

    u = User(name='Test',
             email='*****@*****.**',
             passwd='1234567890',
             image='about:blank')

    yield from u.save()
    yield from orm.destory_pool()
Ejemplo n.º 14
0
 def test(loop):
     yield from create_pool(loop=loop,
                            host='localhost',
                            port=3306,
                            user='******',
                            password='******',
                            db='awesome')
     # user = User(id=1, name='ding')
     # yield from user.save()
     r = yield from User.find('1')
     print(r)
     yield from destory_pool()
Ejemplo n.º 15
0
def save_test(loop):
    yield from orm.create_pool(loop=loop,
                               host='123.206.178.243',
                               user='******',
                               password='******',
                               db='awesome')

    u = User(name='sanji',
             email='*****@*****.**',
             passwd='123123',
             image='about:blank')
    yield from u.save()
Ejemplo n.º 16
0
def test(loop):
    yield from orm.create_pool(loop=loop,
                               user='******',
                               password='******',
                               database='awesome')
    u = User(admin=True,
             name='kHRYSTAL',
             email='*****@*****.**',
             passwd=hashlib.sha1(
                 ('%s:%s' %
                  (next_id(), 'yyg1990918')).encode('utf-8')).hexdigest(),
             image='about:blank')
    yield from u.save()
Ejemplo n.º 17
0
def test(loop):
    yield from orm.create_pool(loop=loop,
                               host='127.0.0.1',
                               port=3306,
                               user='******',
                               password='******',
                               db='awesome')
    user = User(name='Test',
                email='*****@*****.**',
                passwd='123456',
                image='ablout:blank')
    print('-------create finish-----------')
    user.show()
    yield from user.save()
    yield from orm.destory_pool()
Ejemplo n.º 18
0
def init(loop):
    # 创建数据库连接池,db参数传配置文件里边的db
    yield from orm.create_pool(loop=loop, **configs.db)
    # middlewares 设置两个中间处理函数
    # middlewares 中的每个factory接收两个参数,app和handler,即middlewares中下一个handler
    # middlewares 的最后一个元素的 handler会通过routes查找到相应的 routes注册的handler
    app = web.Application(loop=loop, middlewares=[logger_factory, auth_factory, response_factory])
    # 初始化 jinja2模板
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    # 添加请求的 handlers,即各个请求相对应的处理函数
    add_routes(app, 'handlers')
    # 添加静态文件所在地址
    add_static(app)
    # 启动服务器
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Ejemplo n.º 19
0
def test(loop, **kw):
    yield from orm.create_pool(loop=loop,
                               user='******',
                               password='******',
                               db='awesome')
    u = User(name=kw.get('name'),
             email=kw.get('email'),
             passwd=kw.get('passwd'),
             image=kw.get('image'))
    yield from u.save()
    yield from orm.destory_pool()


# data=dict(name='gaf', email='*****@*****.**', passwd='1312345', image='about:blank')
# loop=asyncio.get_event_loop()
# loop.run_until_complete(test(loop,**data))
# loop.close()
Ejemplo n.º 20
0
def create_server(loop, config_mod_name):
    config = __import__(config_mod_name, fromlist=["config", "config_default"])
    #print(config.config_default.configs["db"])
    yield from orm.create_pool(loop=loop,
                               **config.config_default.configs["db"])
    app = web.Application(loop=loop,
                          middlewares=[
                              logger_factory, auth_factory, data_factory,
                              response_factory
                          ])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routs(app, "handlers")
    add_routs(app, "apis")
    add_static(app)
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Ejemplo n.º 21
0
def init(loop):
    yield from orm.create_pool(loop=loop,
                               host='127.0.0.1',
                               port=3306,
                               user='******',
                               password='******',
                               db='awesome')
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory, response_factory])
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    add_routes(app, 'handlers')
    add_static(app)

    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    return srv
Ejemplo n.º 22
0
def testdb():
    'test orm and database connection'
    # 以下为测试:
    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        orm.create_pool(loop=loop,
                        host='127.0.0.1',
                        port=3306,
                        user='******',
                        password='******',
                        db='awesome'))
    #rs = loop.run_until_complete(orm.select('select `id` from users', None))
    args = [
        '*****@*****.**', 'password', True, 'testname', 'blank', '1.0', 'testid'
    ]
    rs = loop.run_until_complete(
        orm.execute(
            'insert into `users` (`email`,`passwd`,`admin`,`name`,`image`,`created_at`, `id`) values (?,?,?,?,?,?,?)',
            args))
    # 获取到了数据库返回的数据
    print("rs:%s" % rs)
    pass
Ejemplo n.º 23
0
def init(loop):
    # yield from www.orm.create_pool(loop=loop,host='127.0.0.1',port =3306,user='******',password='******',db='awesome')
    yield from orm.create_pool(loop=loop, **configs.db)

    #  handlers: url对应的内容 middlewares:根据内容的类型决定具体返回的形式
    app = web.Application(
        loop=loop,
        middlewares=[
            # logger_factory, response_factory
            logger_factory,
            auth_factory,
            response_factory
        ])

    # jinja2的filter(过滤器)
    init_jinja2(app, filters=dict(datetime=datetime_filter))

    add_routes(app, 'handlers')  # 与handlers.py 文件名一致
    add_static(app)

    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9090)

    logging.info('server started at http://127.0.0.1:9090...')
    return srv
Ejemplo n.º 24
0
def test(loop, x):
    yield from orm.create_pool(user='******', password='', database='awesome', loop=loop)

    u = User(name='Test%d' % x, email='*****@*****.**' % x, passwd='123456', image='about:blank')

    yield from u.save()
Ejemplo n.º 25
0
def test():
    yield from orm.create_pool(host=DB_HOST, user=DB_USER, password=DB_PASSWORD, port=DB_PORT, db=DB_NAME)
    for x in range(10):
        u = model.User(name='Test%s' % x, email='*****@*****.**' % x, passwd='1234567890', image='about:blank')
        yield from u.save()
Ejemplo n.º 26
0
def test():
    yield from orm.create_pool(user='******', password='******', database='awesome')
    u = user(name='test', email='*****@*****.**', passwd='test', image='about:blank')
    yield from u.save()
Ejemplo n.º 27
0
def create_pool(loop):
    yield from orm.create_pool(loop=loop,
                               host='123.206.178.243',
                               user='******',
                               password='******',
                               db='awesome')
Ejemplo n.º 28
0
async def testDelete(uid):
    u = await User.find(uid)
    await Blog.deleteAll(user_id=uid)
    blogs = await u.getBlogs()
    print(blogs)


async def creCom(uid):
    blogs = await Blog.findAll(user_id=uid)
    for b in blogs:
        await b.comments_random()
    co = await b.getCommentsWrapped()
    print(co)


async def initialize():
    await init()
    u = User.user_random()
    await u.save()
    print(u.id)
    await loadBlogs(u.id)


loop = asyncio.get_event_loop()
loop.run_until_complete(
    create_pool(user=config['user'],
                password=config['password'],
                db=config['db'],
                loop=loop))
loop.run_until_complete(initialize())
Ejemplo n.º 29
0
def test(loop):
    yield from orm.create_pool(loop=loop, user='******', password='******', database='awesome')
    u=User(name='Yao', email='*****@*****.**', passwd="sas", image='about:blank')
    yield from u.save()
Ejemplo n.º 30
0
def test(loop):
    yield from orm.create_pool(loop=loop, user='******', password='******', db='awesome')
    u = User(name='Won', email='*****@*****.**', passwd='1234567890', image='about:blank')
    yield from u.save()
Ejemplo n.º 31
0
def test(loop):
    yield from orm.create_pool(loop=loop, user='******', password='******', database='awesome')
    u=User(admin=True, name='kHRYSTAL', email='*****@*****.**', passwd=hashlib.sha1(('%s:%s' % (next_id(), 'yyg1990918')).encode('utf-8')).hexdigest(), image='about:blank')
    yield from u.save()
Ejemplo n.º 32
0
def test(loop):
    yield from orm.create_pool(loop, user='******', password='******', database='awesome_study')
    u = User(name='Test', email='*****@*****.**', passwd='1234567890', image='about:blank')
    yield from u.save()