refactor(backend): 重构后端admin和schedule部分
This commit is contained in:
1 parent
9f5493185d
commit
4a14960e01
74 files changed
+5937
-3644
No files matched your search
@@ -0,0 +1,45 @@
|
||||
"""
|
||||
tests/services/admin/test_department_service.py
|
||||
|
||||
用途:department_service CRUD 单元测试。
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from app import db
|
||||
from app.core.errors import NotFoundError, ValidationError
|
||||
from app.models import Department
|
||||
from app.services.admin.department_service import (
|
||||
create_department,
|
||||
delete_department,
|
||||
list_departments,
|
||||
update_department,
|
||||
)
|
||||
|
||||
|
||||
def test_department_crud(app):
|
||||
with app.app_context():
|
||||
created = create_department({'name': 'R&D', 'code': 'RD', 'company': 'HX'})
|
||||
assert created['name'] == 'R&D'
|
||||
|
||||
items = list_departments()
|
||||
assert any(item['code'] == 'RD' for item in items)
|
||||
|
||||
update_department(created['id'], {'description': 'Research'})
|
||||
dept = db.session.get(Department, created['id'])
|
||||
assert dept.description == 'Research'
|
||||
|
||||
delete_department(created['id'])
|
||||
assert db.session.get(Department, created['id']) is None
|
||||
|
||||
|
||||
def test_create_department_rejects_duplicate_name(app):
|
||||
with app.app_context():
|
||||
create_department({'name': 'Sales'})
|
||||
with pytest.raises(ValidationError, match='Name exists'):
|
||||
create_department({'name': 'Sales'})
|
||||
|
||||
|
||||
def test_update_department_not_found(app):
|
||||
with app.app_context():
|
||||
with pytest.raises(NotFoundError):
|
||||
update_department(99999, {'name': 'X'})
|
||||
Reference in new issue
Block a user