You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
4.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import requests
import time
import json
import random
import cProfile
def test_all_c():
# 一、创建班级导入2个班级
url = 'http://127.0.0.1:8000/get/information/'
class_name1 = '嵌入式系统'
file_path1 = 'C:/Users/Lenovo/Desktop/嵌入式系统.xlsx'
with open(file_path1, 'rb') as f:
file1 = {'file': f}
data1 = {'class_name': class_name1}
response1 = requests.post(url, files=file1, data=data1)
print(response1.text)
#time.sleep(6)
class_name2 = '软件工程'
file_path2 = 'C:/Users/Lenovo/Desktop/软工学生名单.xlsx'
with open(file_path2, 'rb') as f:
file2 = {'file': f}
data2 = {'class_name': class_name2}
response2 = requests.post(url, files=file2, data=data2)
print(response2.text)
#time.sleep(6)
# 二、选择软件工程班级进行课前点名此处点3个人
url_call = 'http://127.0.0.1:8000/call/students/' # 确保 URL 正确
data_call = {
'class_name': '软件工程',
'num': 3,
'mode': 0 # 点名使用正常模式
}
response_call = requests.post(url_call, data=data_call)
print(response_call.text)
#time.sleep(3)
res = response_call.json()
result = res.get('result', {})
url_update = 'http://127.0.0.1:8000/update/table/'
# 有到加1分没到扣一分
for name, student_id in result.items():
print(student_id)
point = random.choice([1, -1])
data_update = {
'point': point,
'class_name': '软件工程',
'sid': student_id,
'style': 1
}
response0 = requests.post(url_update, data=data_update)
print(response0.text)
# time.sleep(2)
# 三、上课提问,一个一个提问,问了之后直接加分,选择三五成群的模式提问完直接加分提问3次
data_call = {
'class_name': '软件工程',
'num': 1,
'mode': 3
}
response_call1 = requests.post(url_call, data=data_call)
print(response_call1.text)
res = response_call1.json()
result = res.get('result', {})
student_ids = list(result.values())
student_id = student_ids[0]
data_update = {
'point': 3,
'class_name': '软件工程',
'sid': student_id,
'style': 1
}
response0 = requests.post(url_update, data=data_update)
print(response0.text)
# time.sleep(5)
data_call = {
'class_name': '软件工程',
'num': 1,
'mode': 3
}
response_call1 = requests.post(url_call, data=data_call)
print(response_call1.text)
res = response_call1.json()
result = res.get('result', {})
student_ids = list(result.values())
student_id = student_ids[0]
data_update = {
'point': -5,
'class_name': '软件工程',
'sid': student_id,
'style': 1
}
response0 = requests.post(url_update, data=data_update)
print(response0.text)
#time.sleep(5)
data_call = {
'class_name': '软件工程',
'num': 1,
'mode': 3
}
response_call1 = requests.post(url_call, data=data_call)
print(response_call1.text)
res = response_call1.json()
result = res.get('result', {})
student_ids = list(result.values())
student_id = student_ids[0]
data_update = {
'point': 2,
'class_name': '软件工程',
'sid': student_id,
'style': 1
}
response0 = requests.post(url_update, data=data_update)
print(response0.text)
#time.sleep(5)
# 课堂主动回答问题2人自己加分
data_update = {
'point': 2,
'class_name': '软件工程',
'sid': 102201216,
'style': 1
}
response0 = requests.post(url_update, data=data_update)
print(response0.text)
#time.sleep(5)
data_update = {
'point': 6,
'class_name': '软件工程',
'sid': 102201203,
'style': 1
}
response0 = requests.post(url_update, data=data_update)
print(response0.text)
#time.sleep(2)
# 查看排名 2人
url_show = 'http://127.0.0.1:8000/show/information/' # 确保 URL 正确
data = {
'order': 1,
'class_name': '软件工程',
'sid': 102201539,
}
response = requests.post(url_show, data=data)
data1 = response.json()
print(response.text)
#time.sleep(2)
data = {
'order': 1,
'class_name': '软件工程',
'sid': 102201529,
}
response = requests.post(url_show, data=data)
data1 = response.json()
print(response.text)
if __name__ == '__main__':
cProfile.run('test_all_c()','test_all_c.txt')