"""现货申请新增与审核流程。""" import unittest from pathlib import Path from app import app ROOT=Path(__file__).resolve().parents[1] ROUTE=(ROOT/'routes/spot.py').read_text(encoding='utf-8') APP=(ROOT/'static/js/app.js').read_text(encoding='utf-8') class SpotApplicationWorkflowTest(unittest.TestCase): def setUp(self): self.client=app.test_client() with self.client.session_transaction() as s: s['user_id']=1;s['username']='甘旭东';s['real_name']='甘旭东';s['role']='super_admin';s['user_level']='employee' def test_required_fields_are_enforced(self): r=self.client.post('/api/spot/application/create',data={'product_name':'测试品','sample_quantity':'1'}) self.assertEqual(r.status_code,200);self.assertIn('条形码',r.get_json()['msg']) def test_decision_endpoint_exists_and_requires_rejection_reason(self): self.assertIn("@spot_bp.route('/api/spot/application/decision'",ROUTE) r=self.client.post('/api/spot/application/decision',json={'id':1,'decision':'驳回','reason':''}) self.assertEqual(r.status_code,200);self.assertIn('驳回原因',r.get_json()['msg']) def test_modal_has_image_replace_and_decision_ui(self): for text in ('openSpotApplicationModal','spotApplicationImageRemove','decideSpotApplication','通过','驳回'): self.assertIn(text,APP) if __name__=='__main__':unittest.main()