Compare commits
No commits in common. "1a08ba460c6422dbc8780bc7c0c594dc9cbcfda4" and "ded28f6a1ef70488e24f0fc317b7ca5786b58879" have entirely different histories.
1a08ba460c
...
ded28f6a1e
|
|
@ -1,39 +0,0 @@
|
||||||
import unittest
|
|
||||||
|
|
||||||
from app.views import *
|
|
||||||
from unittest.mock import patch
|
|
||||||
from flask import session
|
|
||||||
|
|
||||||
|
|
||||||
class StudentSignInTestCase(unittest.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
# 设置 Flask 测试模式
|
|
||||||
app.testing = True
|
|
||||||
self.client = app.test_client()
|
|
||||||
|
|
||||||
@patch('db.database_manager.DatabaseManager.update_sign_in_info')
|
|
||||||
def test_student_sign_in(self, mock_update_sign_in_info):
|
|
||||||
# 模拟已登录用户
|
|
||||||
with self.client.session_transaction() as sess:
|
|
||||||
sess['number'] = 'X202301000001'
|
|
||||||
|
|
||||||
# 模拟数据库操作
|
|
||||||
mock_update_sign_in_info.return_value = 1 # 假设成功更新签到信息
|
|
||||||
|
|
||||||
# 发送 POST 请求到/api/student-sign-in
|
|
||||||
response = self.client.post('/api/student-sign-in', data={
|
|
||||||
'course_name': '计算机导论',
|
|
||||||
'course_id': '2',
|
|
||||||
'student_number': 'X202301000001',
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
# 验证返回的状态码和JSON数据
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
json_data = response.get_json()
|
|
||||||
self.assertEqual(json_data, {"msg": "ok", "data": "签到成功!"})
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
import unittest
|
|
||||||
|
|
||||||
from app.views import *
|
|
||||||
from unittest.mock import patch
|
|
||||||
from flask import session
|
|
||||||
|
|
||||||
class TeacherSignInTestCase(unittest.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
# 设置 Flask 测试模式
|
|
||||||
app.testing = True
|
|
||||||
self.client = app.test_client()
|
|
||||||
|
|
||||||
@patch('db.database_manager.DatabaseManager.update_sign_in_info')
|
|
||||||
def test_teacher_sign_in(self, mock_teacher_sign_in):
|
|
||||||
# 模拟已登录用户
|
|
||||||
with self.client.session_transaction() as sess:
|
|
||||||
sess['number'] = 'X202301000001'
|
|
||||||
|
|
||||||
# 模拟数据库操作的返回值
|
|
||||||
mock_teacher_sign_in.return_value = {"msg": "当前班级专业没有学生'"}
|
|
||||||
|
|
||||||
# 发送 POST 请求到/api/teacher-sign-in
|
|
||||||
response = self.client.post('/api/teacher-sign-in', data={
|
|
||||||
'course_id': '123',
|
|
||||||
'course_name': 'Test Course',
|
|
||||||
'class_name': 'TestClass',
|
|
||||||
'major_id': '456'
|
|
||||||
})
|
|
||||||
|
|
||||||
# 验证返回的状态码和数据
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
json_data = response.get_json()
|
|
||||||
self.assertEqual(json_data, {"msg": "当前班级专业没有学生"})
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
||||||
import unittest
|
|
||||||
|
|
||||||
from app.views import *
|
|
||||||
|
|
||||||
|
|
||||||
class HtmlTestCase(unittest.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
app.testing = True # 设置 Flask 应用为测试模式
|
|
||||||
self.client = app.test_client() # 创建一个测试客户端
|
|
||||||
|
|
||||||
def test_get_course_info(self):
|
|
||||||
# 测试 GET 请求
|
|
||||||
response = self.client.get('/course-info')
|
|
||||||
|
|
||||||
# 验证响应状态码
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
# 验证响应的Content-Type头部值
|
|
||||||
self.assertIn('text/html', response.content_type)
|
|
||||||
|
|
||||||
def test_get_attendance(self):
|
|
||||||
# 测试 GET 请求
|
|
||||||
response = self.client.get('/attendance')
|
|
||||||
|
|
||||||
# 验证响应状态码
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# 验证响应的Content-Type头部值
|
|
||||||
self.assertIn('text/html', response.content_type)
|
|
||||||
|
|
||||||
def test_get_announcement(self):
|
|
||||||
# 测试 GET 请求
|
|
||||||
response = self.client.get('/announcement')
|
|
||||||
|
|
||||||
# 验证响应状态码
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# 验证响应的Content-Type头部值
|
|
||||||
self.assertIn('text/html', response.content_type)
|
|
||||||
|
|
||||||
def test_get_attendance_reminder(self):
|
|
||||||
# 测试 GET 请求
|
|
||||||
response = self.client.get('/attendance-reminder')
|
|
||||||
|
|
||||||
# 验证响应状态码
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# 验证响应的Content-Type头部值
|
|
||||||
self.assertIn('text/html', response.content_type)
|
|
||||||
|
|
||||||
def test_get_course_category(self):
|
|
||||||
# 测试 GET 请求
|
|
||||||
response = self.client.get('/course-category')
|
|
||||||
|
|
||||||
# 验证响应状态码
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# 验证响应的Content-Type头部值
|
|
||||||
self.assertIn('text/html', response.content_type)
|
|
||||||
|
|
||||||
def test_get_attendance_teacher(self):
|
|
||||||
# 测试 GET 请求
|
|
||||||
response = self.client.get('/attendance-teacher')
|
|
||||||
|
|
||||||
# 验证响应状态码
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# 验证响应的Content-Type头部值
|
|
||||||
self.assertIn('text/html', response.content_type)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
Reference in New Issue