parent
87d3034bc0
commit
a41d0b26fc
@ -0,0 +1,70 @@
|
||||
import { expect } from 'chai';
|
||||
import axios from 'axios';
|
||||
|
||||
// 定义测试块
|
||||
describe('Flask API calls', () => {
|
||||
const baseURL = 'http://localhost:3000'; // Flask 服务器的基本 URL
|
||||
|
||||
// 测试随机获取学生
|
||||
it('should get a random student from Python API', async () => {
|
||||
try {
|
||||
// 调用 Flask 服务器的 /get_random_student 端点
|
||||
const response = await axios.get(`${baseURL}/get_random_student`);
|
||||
|
||||
// 断言返回结果是否包含 student_id 和 name 字段
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.data).to.have.property('student_id');
|
||||
expect(response.data).to.have.property('name');
|
||||
console.log("Random student fetched successfully:", response.data);
|
||||
} catch (error) {
|
||||
console.error("Error fetching random student:", error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
// 测试更新出勤积分
|
||||
it('should update attendance score for a student', async () => {
|
||||
try {
|
||||
const studentId = '102201505'; // 假设学生
|
||||
|
||||
// 调用 Flask 服务器的 /update_attendance_score 端点
|
||||
const response = await axios.post(`${baseURL}/update_attendance_score`, {
|
||||
student_id: studentId
|
||||
});
|
||||
|
||||
// 断言返回结果是否包含成功信息
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.data).to.have.property('message').that.equals('Attendance score updated');
|
||||
expect(response.data).to.have.property('student_id').that.equals(studentId);
|
||||
console.log("Attendance score updated successfully:", response.data);
|
||||
} catch (error) {
|
||||
console.error("Error updating attendance score:", error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
// 测试更新回答积分
|
||||
it('should update answer score for a student', async () => {
|
||||
try {
|
||||
const studentId = '102201505'; // 假设学生
|
||||
const repeatedCorrectly = true; // 假设重复回答正确
|
||||
const answerScore = 2.0; // 假设回答得分
|
||||
|
||||
// 调用 Flask 服务器的 /update_answer_score 端点
|
||||
const response = await axios.post(`${baseURL}/update_answer_score`, {
|
||||
student_id: studentId,
|
||||
repeated_correctly: repeatedCorrectly,
|
||||
answer_score: answerScore
|
||||
});
|
||||
|
||||
// 断言返回结果是否包含成功信息
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.data).to.have.property('message').that.equals('Answer score updated');
|
||||
expect(response.data).to.have.property('student_id').that.equals(studentId);
|
||||
console.log("Answer score updated successfully:", response.data);
|
||||
} catch (error) {
|
||||
console.error("Error updating answer score:", error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in new issue