Compare commits
3 Commits
1a08ba460c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| dbeeb4d25a | |||
| 58c4b85e6a | |||
| b6fc41994e |
43
app/tests/ReceiveExcelTest.py
Normal file
43
app/tests/ReceiveExcelTest.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
|
from app.views import *
|
||||||
|
from werkzeug.datastructures import FileStorage # 用于创建测试文件
|
||||||
|
|
||||||
|
class ReceiveExcelTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
app.testing = True # 设置 Flask 应用为测试模式
|
||||||
|
self.client = app.test_client()
|
||||||
|
# 创建一个测试用的Excel文件或使用一个真实的Excel文件路径
|
||||||
|
self.test_file_path = 'template.xlsx'
|
||||||
|
|
||||||
|
def test_receive_excel_no_file(self):
|
||||||
|
# 测试没有文件时的情况
|
||||||
|
response = self.client.post('/api/receive-excel')
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
self.assertEqual(response.get_json(), {"error": "No file part"})
|
||||||
|
|
||||||
|
def test_receive_excel_with_file(self):
|
||||||
|
# 模拟已登录用户
|
||||||
|
with self.client.session_transaction() as sess:
|
||||||
|
sess['number'] = 'X202301000001'
|
||||||
|
|
||||||
|
# 使用 FileStorage 创建测试文件对象
|
||||||
|
data = {
|
||||||
|
'file': (open(self.test_file_path, 'rb'), self.test_file_path)
|
||||||
|
}
|
||||||
|
# 发送 POST 请求到 /api/receive-excel
|
||||||
|
response = self.client.post('/api/receive-excel', data=data, content_type='multipart/form-data')
|
||||||
|
|
||||||
|
# 验证返回的状态码和响应
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual(response.get_json(), {"message": "File successfully processed"})
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
# 清理测试用的文件或数据
|
||||||
|
if os.path.exists(self.test_file_path):
|
||||||
|
os.remove(self.test_file_path)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
bcrypt==4.1.2
|
|
||||||
blinker==1.7.0
|
|
||||||
click==8.1.7
|
|
||||||
colorama==0.4.6
|
|
||||||
DBUtils==3.0.3
|
|
||||||
et-xmlfile==1.1.0
|
|
||||||
Flask==3.0.0
|
|
||||||
itsdangerous==2.1.2
|
|
||||||
Jinja2==3.1.2
|
|
||||||
MarkupSafe==2.1.3
|
|
||||||
openpyxl==3.1.2
|
|
||||||
PyMySQL==1.1.0
|
|
||||||
Werkzeug==3.0.1
|
|
||||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Reference in New Issue
Block a user