def test(): connection = pymysql.connect( host='localhost', user='******', password='******', # db='web8', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) with connection.cursor() as cursor: cursor.execute('DROP DATABASE IF EXISTS`web8`') cursor.execute('CREATE DATABASE `web8` CHARACTER SET utf8mb4') cursor.execute('USE `web8`') cursor.execute(User.sql_create) cursor.execute(Session.sql_create) cursor.execute(Weibo.sql_create) cursor.execute(Comment.sql_create) connection.commit() connection.close() form = dict( username='******', password='******', ) User.register_user(form) u, result = User.login_user(form) assert u is not None, result form = dict( username='******', password='******', ) User.register_user(form) session_id = random_string() form = dict( session_id=session_id, user_id=u.id, ) Session.new(form) s: Session = Session.one(session_id=session_id) assert s.session_id == session_id
def route_register(request): form = request.form() result = User.register_user(form) # 换行符需要编码,不然显示不全 result = urllib.parse.quote_plus(result) return redirect('/register/view', result=result)
def test(): connection = pymysql.connect( host='localhost', user='******', password='******'.format(secret.database_password), # db='web8', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) with connection.cursor() as cursor: cursor.execute('DROP DATABASE IF EXISTS`web`') cursor.execute('CREATE DATABASE `web` CHARACTER SET utf8mb4') cursor.execute('USE `web`') cursor.execute(User.sql_create) cursor.execute(Session.sql_create) cursor.execute(Todo.sql_create) cursor.execute(Weibo.sql_create) cursor.execute(Comment.sql_create) connection.commit() connection.close() form = dict( username='******', password='******', ) User.register_user(form) u, result = User.login_user(form) assert u is not None, result form = dict( username='******', password='******', ) User.register_user(form) session_id = random_string() form = dict( session_id=session_id, user_id=u.id, ) Session.new(form) s: Session = Session.one(session_id=session_id) assert s.session_id == session_id form = dict( title='test todo', user_id=u.id, ) t = Todo.add(form, u.id) assert t.title == 'test todo' form = dict( content='test weibo', user_id=u.id, ) w = Weibo.add(form, u.id) assert w.content == 'test weibo' form = dict( content='test comment', user_id=u.id, ) c = Comment.add(form, u.id, w.id) assert c.content == 'test comment'