diff --git a/tests/test_feedback.py b/tests/test_feedback.py index 53589ae..3fe732e 100644 --- a/tests/test_feedback.py +++ b/tests/test_feedback.py @@ -69,8 +69,9 @@ def test_json_string_input(self) -> None: {"feedback": "Great tools!", "account_id": "acc_123456", "tool_names": ["test_tool"]} ) result = tool.execute(json_string) - assert result["message"] == "Success" + assert result == {"message": "Success"} assert route.called + assert route.calls[0].response.status_code == 200 class TestFeedbackToolExecution: @@ -97,6 +98,7 @@ def test_single_account_execution(self) -> None: assert result == api_response assert route.called assert route.call_count == 1 + assert route.calls[0].response.status_code == 200 request = route.calls[0].request body = json.loads(request.content) assert body["feedback"] == "Great tools!" @@ -122,13 +124,14 @@ def test_call_method_interface(self) -> None: assert result == api_response assert route.called assert route.call_count == 1 + assert route.calls[0].response.status_code == 200 @respx.mock def test_api_error_handling(self) -> None: """Test that API errors are handled properly.""" tool = create_feedback_tool(api_key="test_key") - respx.post("https://api.stackone.com/ai/tool-feedback").mock( + route = respx.post("https://api.stackone.com/ai/tool-feedback").mock( return_value=httpx.Response(401, json={"error": "Unauthorized"}) ) @@ -141,6 +144,9 @@ def test_api_error_handling(self) -> None: } ) + assert route.called + assert route.calls[0].response.status_code == 401 + @respx.mock def test_multiple_account_ids_execution(self) -> None: """Test execution with multiple account IDs - both success and mixed scenarios.""" @@ -160,12 +166,33 @@ def test_multiple_account_ids_execution(self) -> None: } ) - assert result["message"] == "Feedback sent to 3 account(s)" - assert result["total_accounts"] == 3 - assert result["successful"] == 3 - assert result["failed"] == 0 - assert len(result["results"]) == 3 + assert result == { + "message": "Feedback sent to 3 account(s)", + "total_accounts": 3, + "successful": 3, + "failed": 0, + "results": [ + { + "account_id": "acc_123456", + "status": "success", + "result": {"message": "Feedback successfully stored", "trace_id": "test-trace-id"}, + }, + { + "account_id": "acc_789012", + "status": "success", + "result": {"message": "Feedback successfully stored", "trace_id": "test-trace-id"}, + }, + { + "account_id": "acc_345678", + "status": "success", + "result": {"message": "Feedback successfully stored", "trace_id": "test-trace-id"}, + }, + ], + } assert route.call_count == 3 + assert route.calls[0].response.status_code == 200 + assert route.calls[1].response.status_code == 200 + assert route.calls[2].response.status_code == 200 @respx.mock def test_multiple_account_ids_mixed_success(self) -> None: @@ -180,7 +207,7 @@ def custom_side_effect(request: httpx.Request) -> httpx.Response: else: return httpx.Response(401, json={"error": "Unauthorized"}) - respx.post("https://api.stackone.com/ai/tool-feedback").mock(side_effect=custom_side_effect) + route = respx.post("https://api.stackone.com/ai/tool-feedback").mock(side_effect=custom_side_effect) result = tool.execute( { @@ -190,18 +217,32 @@ def custom_side_effect(request: httpx.Request) -> httpx.Response: } ) - assert result["total_accounts"] == 2 - assert result["successful"] == 1 - assert result["failed"] == 1 - assert len(result["results"]) == 2 - - success_result = next(r for r in result["results"] if r["account_id"] == "acc_123456") - assert success_result["status"] == "success" - - error_result = next(r for r in result["results"] if r["account_id"] == "acc_unauthorized") - assert error_result["status"] == "error" - assert "error" in error_result - assert "401" in error_result["error"] + assert result == { + "message": "Feedback sent to 2 account(s)", + "total_accounts": 2, + "successful": 1, + "failed": 1, + "results": [ + { + "account_id": "acc_123456", + "status": "success", + "result": {"message": "Success"}, + }, + { + "account_id": "acc_unauthorized", + "status": "error", + "error": ( + "Client error '401 Unauthorized' for url " + "'https://api.stackone.com/ai/tool-feedback'\n" + "For more information check: " + "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401" + ), + }, + ], + } + assert route.call_count == 2 + assert route.calls[0].response.status_code == 200 + assert route.calls[1].response.status_code == 401 def test_tool_integration(self) -> None: """Test that feedback tool integrates properly with toolset.""" diff --git a/tests/test_meta_tools.py b/tests/test_meta_tools.py index 06b7dc0..0c8f1d0 100644 --- a/tests/test_meta_tools.py +++ b/tests/test_meta_tools.py @@ -223,9 +223,9 @@ def test_execute_tool_call(self, tools_collection): # Call the meta execute tool result = execute_tool.call(toolName="hibob_list_employee", params={"limit": 10}) - assert result is not None - assert "success" in result or "employees" in result + assert result == {"success": True, "employees": []} assert route.called + assert route.calls[0].response.status_code == 200 class TestToolsMetaTools: