dy-dashboard/tests/test_contract_ledger.py
2026-10-28 11:14:17 +08:00

39 lines
1.7 KiB
Python

"""Contract ledger model and navigation regression checks."""
from pathlib import Path
import unittest
from services.contract_ledger import new_contract_no
class ContractLedgerTest(unittest.TestCase):
def test_contract_numbers_are_unique_and_typed(self):
a = new_contract_no('domestic')
b = new_contract_no('domestic')
self.assertTrue(a.startswith('CGHTDY-GN-'))
self.assertNotEqual(a, b)
self.assertTrue(new_contract_no('overseas').startswith('CGHTDY-HW-'))
self.assertTrue(new_contract_no('packaging').startswith('CGHTDY-BC-'))
self.assertTrue(new_contract_no('domestic', 'YY').startswith('CGHTDY-YY-'))
def test_page_has_ledger_and_combined_template_tabs(self):
root = Path(__file__).resolve().parents[1]
app_js = (root / 'static/js/app.js').read_text(encoding='utf-8')
base = (root / 'templates/base.html').read_text(encoding='utf-8')
self.assertIn('合同台账管理', app_js)
self.assertIn('合同台账管理', base)
self.assertIn("switchCtTab('ledger')", app_js)
self.assertIn("switchCtTab('templates')", app_js)
self.assertIn('id="ctFinishedList"', app_js)
self.assertIn('id="ctPackagingList"', app_js)
self.assertIn('/api/contract/ledger/list', app_js)
def test_generation_creates_ledger_record_and_version(self):
source = (Path(__file__).resolve().parents[1] / 'routes/contract.py').read_text(encoding='utf-8')
for token in ('create_record(', 'add_file(contract_id, 1,', "add_event(contract_id, '生成合同'",
"new_contract_no(order_type, sup_name_to_contract_short.get(supplier))"):
self.assertIn(token, source)
if __name__ == '__main__':
unittest.main()