我不熟悉python编程,而是尝试使用Pytest为我的Flask应用程序编写测试用例。我无法理解如何处理代码请求。这是代码段。
@app.route("/", methods=["GET", "POST"])
def home():
if request.form:
ts = time.gmtime()
createdon = time.strftime("%x %X", ts)
classiddetail = request.form.get("selectedid")
detail = Class.query.filter_by(id=classiddetail).first()
classleader = request.form.get("classleader")
if classleader == "Yes":
student_det = Student(name=request.form.get("name"), class_id=classiddetail, createdon=createdon, classname=detail)
class_info = Class.query.filter_by(id=classiddetail).first()
class_info.class_leader = student_det.id
tsu = time.gmtime()
update_time = time.strftime("%x %X", tsu)
class_info.updatedon = update_time
db.session.add(student_det)
db.session.add(class_info)
db.session.commit()
else:
studentdet = Student(name=request.form.get("name"), class_id=classiddetail, createdon=createdon,
classname=detail)
db.session.add(studentdet)
db.session.commit()
students = Student.query.all()
return render_template("homepage.html", students=students)
我们将不胜感激。
感谢与问候, 吉塔什(Jitaksh)