|
|
@@ -0,0 +1,58 @@
|
|
|
+import pytest
|
|
|
+from fastapi import HTTPException
|
|
|
+
|
|
|
+from app.services.pl_plan_service import (
|
|
|
+ DRAFTABLE_FOLLOW_STATUSES,
|
|
|
+ assert_can_save_as_draft,
|
|
|
+ resolve_follow_status_on_save,
|
|
|
+ validate_draft_min_fields,
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+def test_validate_draft_min_fields_requires_belongs_company():
|
|
|
+ with pytest.raises(HTTPException) as exc:
|
|
|
+ validate_draft_min_fields(belongs_company="", create_date=None)
|
|
|
+ assert exc.value.status_code == 422
|
|
|
+ assert "归属公司" in str(exc.value.detail)
|
|
|
+
|
|
|
+
|
|
|
+def test_validate_draft_min_fields_allows_missing_create_date():
|
|
|
+ validate_draft_min_fields(belongs_company="shanxia", create_date=None)
|
|
|
+
|
|
|
+
|
|
|
+def test_resolve_follow_status_draft_always_drafting():
|
|
|
+ assert (
|
|
|
+ resolve_follow_status_on_save(
|
|
|
+ save_mode="draft", current="pending_arrange", is_create=False
|
|
|
+ )
|
|
|
+ == "drafting"
|
|
|
+ )
|
|
|
+ assert resolve_follow_status_on_save(save_mode="draft", current=None, is_create=True) == "drafting"
|
|
|
+
|
|
|
+
|
|
|
+def test_resolve_follow_status_formal_promotes_drafting():
|
|
|
+ assert (
|
|
|
+ resolve_follow_status_on_save(save_mode="formal", current=None, is_create=True)
|
|
|
+ == "pending_arrange"
|
|
|
+ )
|
|
|
+ assert (
|
|
|
+ resolve_follow_status_on_save(save_mode="formal", current="drafting", is_create=False)
|
|
|
+ == "pending_arrange"
|
|
|
+ )
|
|
|
+ assert (
|
|
|
+ resolve_follow_status_on_save(save_mode="formal", current="arranged", is_create=False)
|
|
|
+ == "arranged"
|
|
|
+ )
|
|
|
+ assert (
|
|
|
+ resolve_follow_status_on_save(save_mode="formal", current="wait_notice", is_create=False)
|
|
|
+ == "wait_notice"
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def test_assert_can_save_as_draft_rejects_arranged():
|
|
|
+ assert "drafting" in DRAFTABLE_FOLLOW_STATUSES
|
|
|
+ assert "pending_arrange" in DRAFTABLE_FOLLOW_STATUSES
|
|
|
+ with pytest.raises(HTTPException) as exc:
|
|
|
+ assert_can_save_as_draft("arranged")
|
|
|
+ assert exc.value.status_code == 400
|
|
|
+ assert "不可暂存" in str(exc.value.detail)
|