Files
zkxw/backend/tests/test_oa_datetime_normalize.py
T
zlwuandCursor ac8e471aca fix: align sample registration, freight scope, and OA datetime display
Let customer-service quick register write storage, certificate, and insurance separately without extra menu or data-scope checks. List freight by document data scope like the web admin, allow protocol staff outside the collection region, and pad OA datetimes to seconds so PC date pickers can show historical minute values.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-20 17:30:30 +08:00

112 lines
3.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""oa_datetime_normalize:PC/小程序 datetime 到秒对齐与历史到分兼容"""
from app.services.oa_datetime_normalize import normalize_datetime_form_values
def test_pad_minute_only_when_datetime_default_expects_seconds():
schema = {
"rule": [
{
"type": "datePicker",
"field": "useTime",
"title": "用车时间",
"props": {"type": "datetime"},
}
]
}
data = {"useTime": "2026-10-20 09:00", "other": "x"}
out = normalize_datetime_form_values(schema, data)
assert out["useTime"] == "2026-10-20 09:00:00"
assert out["other"] == "x"
assert data["useTime"] == "2026-10-20 09:00" # 不改入参
def test_leave_as_is_when_already_has_seconds():
schema = {
"rule": [
{
"type": "datePicker",
"field": "t",
"props": {"type": "datetime", "valueFormat": "YYYY-MM-DD HH:mm:ss"},
}
]
}
out = normalize_datetime_form_values(schema, {"t": "2026-10-14 08:20:00"})
assert out["t"] == "2026-10-14 08:20:00"
def test_skip_when_schema_explicitly_minute_only():
"""请假/加班套件显式到分,不得补秒。"""
schema = {
"rule": [
{
"type": "datePicker",
"field": "start",
"props": {
"type": "datetime",
"format": "YYYY-MM-DD HH:mm",
"valueFormat": "YYYY-MM-DD HH:mm",
},
}
]
}
out = normalize_datetime_form_values(schema, {"start": "2026-10-20 09:00"})
assert out["start"] == "2026-10-20 09:00"
def test_skip_plain_date_fields():
schema = {
"rule": [
{"type": "datePicker", "field": "d", "title": "日期"},
]
}
out = normalize_datetime_form_values(schema, {"d": "2026-10-20"})
assert out["d"] == "2026-10-20"
def test_pad_nested_kit_children_only_when_seconds():
schema = {
"rule": [
{
"type": "leaveKit",
"field": "kit",
"children": [
{
"type": "datePicker",
"field": "leaveStart",
"props": {
"type": "datetime",
"valueFormat": "YYYY-MM-DD HH:mm",
},
},
{
"type": "datePicker",
"field": "carTime",
"props": {"type": "datetime"},
},
],
}
]
}
out = normalize_datetime_form_values(
schema,
{"leaveStart": "2026-10-20 09:00", "carTime": "2026-10-20 09:00"},
)
assert out["leaveStart"] == "2026-10-20 09:00"
assert out["carTime"] == "2026-10-20 09:00:00"
def test_pad_datetimerange_list():
schema = {
"rule": [
{
"type": "datePicker",
"field": "rng",
"props": {"type": "datetimerange"},
}
]
}
out = normalize_datetime_form_values(
schema, {"rng": ["2026-10-20 09:00", "2026-10-20 18:30"]}
)
assert out["rng"] == ["2026-10-20 09:00:00", "2026-10-20 18:30:00"]