test_sample_cert_insurance_sample_level.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. """样本级储存证 / 保险:handled 判定与 quick-register items 去重。"""
  2. from types import SimpleNamespace
  3. from datetime import datetime
  4. from app.services.sample_info_progress import insurance_handled, storage_cert_handled
  5. from app.services.sample_info_quick_register import unique_sample_items
  6. def test_storage_cert_handled_true_when_handle_time_set():
  7. assert (
  8. storage_cert_handled(
  9. SimpleNamespace(handle_time=object(), make_status="0", make_date=None)
  10. )
  11. is True
  12. )
  13. assert storage_cert_handled(None) is False
  14. def test_storage_cert_handled_legacy_fields():
  15. assert (
  16. storage_cert_handled(
  17. SimpleNamespace(handle_time=None, make_status="1", make_date="")
  18. )
  19. is True
  20. )
  21. assert (
  22. storage_cert_handled(
  23. SimpleNamespace(handle_time=None, make_status="0", make_date="20260101")
  24. )
  25. is True
  26. )
  27. assert (
  28. storage_cert_handled(
  29. SimpleNamespace(handle_time=None, make_status="0", make_date="")
  30. )
  31. is False
  32. )
  33. def test_insurance_handled_true_when_handle_time_set():
  34. assert (
  35. insurance_handled(
  36. SimpleNamespace(
  37. handle_time=datetime(2026, 10, 1, 8, 0),
  38. todo_status="0",
  39. handle_date="",
  40. )
  41. )
  42. is True
  43. )
  44. assert insurance_handled(None) is False
  45. def test_insurance_handled_legacy_fields():
  46. assert (
  47. insurance_handled(
  48. SimpleNamespace(handle_time=None, todo_status="1", handle_date="")
  49. )
  50. is True
  51. )
  52. assert (
  53. insurance_handled(
  54. SimpleNamespace(handle_time=None, todo_status="0", handle_date="20260131")
  55. )
  56. is True
  57. )
  58. assert (
  59. insurance_handled(
  60. SimpleNamespace(handle_time=None, todo_status="0", handle_date="")
  61. )
  62. is False
  63. )
  64. def test_unique_sample_items_dedupes_by_sample_code():
  65. pairs = unique_sample_items(
  66. [
  67. {"sampleCode": "S1", "protocolId": "P1"},
  68. {"sampleCode": " S1 ", "protocolId": "P9"},
  69. {"sampleCode": "S2", "protocolId": "P2"},
  70. {"sampleCode": "", "protocolId": "P3"},
  71. {"sampleCode": "S2", "protocolId": "P2"},
  72. ]
  73. )
  74. assert pairs == [("S1", "P1"), ("S2", "P2")]
  75. def test_unique_sample_items_empty():
  76. assert unique_sample_items([]) == []
  77. assert unique_sample_items(None) == []