Files
arc53--docsgpt/tests/agents/tools/test_read_webpage_errors.py
wehub-resource-sync fed8b2eed7
Backend release / release (push) Waiting to run
Bandit Security Scan / bandit_scan (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / manifest (push) Blocked by required conditions
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / manifest (push) Blocked by required conditions
Python linting / ruff (push) Waiting to run
Run python tests with pytest / Run tests and count coverage (3.12) (push) Waiting to run
React Widget Build / build (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:28:29 +08:00

71 lines
2.4 KiB
Python

"""Tests for error paths in read_webpage tool."""
from unittest.mock import patch
import requests
class TestReadWebpageErrors:
def test_request_exception_returns_error_string(self):
from application.agents.tools.read_webpage import ReadWebpageTool
tool = ReadWebpageTool(config={})
with patch(
"application.agents.tools.read_webpage.pinned_request",
side_effect=requests.exceptions.RequestException("bad url"),
):
got = tool.execute_action(
"read_webpage", url="https://example.com/",
)
assert "Error fetching URL" in got
def test_generic_exception_returns_error_string(self):
from application.agents.tools.read_webpage import ReadWebpageTool
tool = ReadWebpageTool(config={})
with patch(
"application.agents.tools.read_webpage.markdownify",
side_effect=RuntimeError("boom"),
), patch(
"application.agents.tools.read_webpage.pinned_request",
) as mock_pinned_request:
mock_pinned_request.return_value.text = "<h1>hi</h1>"
mock_pinned_request.return_value.raise_for_status.return_value = None
got = tool.execute_action(
"read_webpage", url="https://example.com/",
)
assert "Error fetching URL" in got
class TestBaseAgentMinorBranches:
"""Cover 2 missing lines in agents/base.py (116, 160)."""
def test_base_agent_with_llm_provided(self):
from application.agents.classic_agent import ClassicAgent
from unittest.mock import MagicMock
mock_llm = MagicMock()
mock_handler = MagicMock()
# Instantiating with llm+llm_handler skips the creator call paths
agent = ClassicAgent(
endpoint="ep", llm_name="openai", model_id="gpt-4",
api_key="k", llm=mock_llm, llm_handler=mock_handler,
)
assert agent.llm is mock_llm
assert agent.llm_handler is mock_handler
class TestWorkflowNodesMinor:
"""Cover line 44 in workflow_nodes.py (likely default params branch)."""
def test_bulk_create_empty_list_returns_empty(self, pg_conn):
from application.storage.db.repositories.workflow_nodes import (
WorkflowNodesRepository,
)
got = WorkflowNodesRepository(pg_conn).bulk_create(
"00000000-0000-0000-0000-000000000001",
1,
[],
)
assert got == []