@@ -62,10 +62,10 @@ def test_list_view_action_buttons_only_for_created(self, client):
6262
6363 # Count actual button elements - should only be for the CREATED expense
6464 approve_count = html .count (
65- '<button style="background-color:#4CAF50;">APPROVE</button>'
65+ '<button type="submit" style="background-color:#4CAF50;">APPROVE</button>'
6666 )
6767 reject_count = html .count (
68- '<button style="background-color:#f44336;">REJECT</button>'
68+ '<button type="submit" style="background-color:#f44336;">REJECT</button>'
6969 )
7070 assert approve_count == 1
7171 assert reject_count == 1
@@ -119,19 +119,23 @@ def test_action_approve_ui(self, client):
119119 all_expenses ["test-expense" ] = ExpenseState .CREATED
120120
121121 with patch ("expense.ui.notify_expense_state_change" ) as mock_notify :
122- response = client .get ("/action?type=approve&id=test-expense" )
122+ response = client .post (
123+ "/action" , data = {"type" : "approve" , "id" : "test-expense" }
124+ )
123125 assert response .status_code == 200
124126 assert all_expenses ["test-expense" ] == ExpenseState .APPROVED
125- assert "SAMPLE EXPENSE SYSTEM" in response .text # Should show list view
127+ # Should redirect to list view
128+ assert response .url .path == "/list"
126129 mock_notify .assert_called_once_with ("test-expense" , ExpenseState .APPROVED )
127130
128131 def test_action_approve_api (self , client ):
129132 """Test approve action via API"""
130133 all_expenses ["test-expense" ] = ExpenseState .CREATED
131134
132135 with patch ("expense.ui.notify_expense_state_change" ) as mock_notify :
133- response = client .get (
134- "/action?type=approve&id=test-expense&is_api_call=true"
136+ response = client .post (
137+ "/action" ,
138+ data = {"type" : "approve" , "id" : "test-expense" , "is_api_call" : "true" },
135139 )
136140 assert response .status_code == 200
137141 assert response .text == "SUCCEED"
@@ -143,45 +147,60 @@ def test_action_reject_ui(self, client):
143147 all_expenses ["test-expense" ] = ExpenseState .CREATED
144148
145149 with patch ("expense.ui.notify_expense_state_change" ) as mock_notify :
146- response = client .get ("/action?type=reject&id=test-expense" )
150+ response = client .post (
151+ "/action" , data = {"type" : "reject" , "id" : "test-expense" }
152+ )
147153 assert response .status_code == 200
148154 assert all_expenses ["test-expense" ] == ExpenseState .REJECTED
155+ # Should redirect to list view
156+ assert response .url .path == "/list"
149157 mock_notify .assert_called_once_with ("test-expense" , ExpenseState .REJECTED )
150158
151159 def test_action_payment (self , client ):
152160 """Test payment action"""
153161 all_expenses ["test-expense" ] = ExpenseState .APPROVED
154162
155- response = client .get ("/action?type=payment&id=test-expense&is_api_call=true" )
163+ response = client .post (
164+ "/action" ,
165+ data = {"type" : "payment" , "id" : "test-expense" , "is_api_call" : "true" },
166+ )
156167 assert response .status_code == 200
157168 assert response .text == "SUCCEED"
158169 assert all_expenses ["test-expense" ] == ExpenseState .COMPLETED
159170
160171 def test_action_invalid_id_ui (self , client ):
161172 """Test action with invalid ID via UI"""
162- response = client .get ("/action?type= approve&id= nonexistent" )
173+ response = client .post ("/action" , data = { "type" : " approve" , "id" : " nonexistent"} )
163174 assert response .status_code == 200
164175 assert response .text == "Invalid ID"
165176
166177 def test_action_invalid_id_api (self , client ):
167178 """Test action with invalid ID via API"""
168- response = client .get ("/action?type=approve&id=nonexistent&is_api_call=true" )
179+ response = client .post (
180+ "/action" ,
181+ data = {"type" : "approve" , "id" : "nonexistent" , "is_api_call" : "true" },
182+ )
169183 assert response .status_code == 200
170184 assert response .text == "ERROR:INVALID_ID"
171185
172186 def test_action_invalid_type_ui (self , client ):
173187 """Test action with invalid type via UI"""
174188 all_expenses ["test-expense" ] = ExpenseState .CREATED
175189
176- response = client .get ("/action?type=invalid&id=test-expense" )
190+ response = client .post (
191+ "/action" , data = {"type" : "invalid" , "id" : "test-expense" }
192+ )
177193 assert response .status_code == 200
178194 assert response .text == "Invalid action type"
179195
180196 def test_action_invalid_type_api (self , client ):
181197 """Test action with invalid type via API"""
182198 all_expenses ["test-expense" ] = ExpenseState .CREATED
183199
184- response = client .get ("/action?type=invalid&id=test-expense&is_api_call=true" )
200+ response = client .post (
201+ "/action" ,
202+ data = {"type" : "invalid" , "id" : "test-expense" , "is_api_call" : "true" },
203+ )
185204 assert response .status_code == 200
186205 assert response .text == "ERROR:INVALID_TYPE"
187206
@@ -280,15 +299,18 @@ def test_state_transitions_complete_workflow(self, client):
280299
281300 # 3. Approve expense
282301 with patch ("expense.ui.notify_expense_state_change" ) as mock_notify :
283- response = client .get (
284- f"/action?type=approve&id={ expense_id } &is_api_call=true"
302+ response = client .post (
303+ "/action" ,
304+ data = {"type" : "approve" , "id" : expense_id , "is_api_call" : "true" },
285305 )
286306 assert response .text == "SUCCEED"
287307 assert all_expenses [expense_id ] == ExpenseState .APPROVED
288308 mock_notify .assert_called_once_with (expense_id , ExpenseState .APPROVED )
289309
290310 # 4. Process payment
291- response = client .get (f"/action?type=payment&id={ expense_id } &is_api_call=true" )
311+ response = client .post (
312+ "/action" , data = {"type" : "payment" , "id" : expense_id , "is_api_call" : "true" }
313+ )
292314 assert response .text == "SUCCEED"
293315 assert all_expenses [expense_id ] == ExpenseState .COMPLETED
294316
@@ -345,7 +367,7 @@ def test_parameter_validation(self, client):
345367 response = client .get ("/create" ) # Missing id
346368 assert response .status_code == 422 # FastAPI validation error
347369
348- response = client .get ("/action" ) # Missing type and id
370+ response = client .post ("/action" ) # Missing type and id
349371 assert response .status_code == 422
350372
351373 response = client .get ("/status" ) # Missing id
0 commit comments