| 12345678910111213141516171819202122232425262728293031323334353637 |
- from types import SimpleNamespace
- from unittest.mock import MagicMock, patch
- import pytest
- from app.api.pl.plan import cancel_plan, _filters_from_params
- from app.services.pl_plan_archive_export import ARCHIVE_STATUS_LABELS
- @pytest.mark.parametrize("archive_status", ["unarchived", "draft"])
- def test_cancel_plan_persists_cancelled_archive_status(archive_status):
- plan = SimpleNamespace(
- id="p1", follow_status="arranged", archive_status=archive_status,
- transport_status="arranged", transport_id=None,
- )
- db = MagicMock()
- user = MagicMock(id="u1")
- with patch("app.api.pl.plan.get_tenant_no", return_value="t1"), patch(
- "app.api.pl.plan._get_plan", return_value=plan
- ), patch(
- "app.api.pl.plan.plan_execution_lock_reason", return_value=None
- ), patch("app.api.pl.plan.void_io_orders_for_plan"):
- result = cancel_plan("p1", body=None, db=db, user=user)
- assert result.follow_status == "cancelled"
- assert result.archive_status == "cancelled"
- db.commit.assert_called_once()
- db.refresh.assert_called_once_with(plan)
- def test_cancelled_archive_status_export_label():
- assert ARCHIVE_STATUS_LABELS.get("cancelled") == "已取消"
- def test_archive_list_scope_passes_through_list_and_export_params():
- with patch("app.api.pl.plan.build_plan_column_filters", return_value=[]) as build:
- _filters_from_params({"archiveList": "1"}, db=None, tenant_no="t1")
- assert build.call_args.kwargs["archive_list"] is True
|