def comment_add(request): u = current_user(request) form = request.form() weibo_id = int(form['weibo_id']) Comment.add(form, u.id, weibo_id) return redirect('/weibo/index')
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'