mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-04 16:13:23 +00:00
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
148 lines
4.6 KiB
Python
148 lines
4.6 KiB
Python
"""Tests for docsgpt/agents/tools/ntfy.py"""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from docsgpt.agents.tools.ntfy import NtfyTool
|
|
|
|
|
|
@pytest.fixture
|
|
def tool():
|
|
return NtfyTool(config={"token": "test_token"})
|
|
|
|
|
|
@pytest.fixture
|
|
def tool_no_token():
|
|
return NtfyTool(config={})
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestNtfyExecuteAction:
|
|
def test_unknown_action_raises(self, tool):
|
|
with pytest.raises(ValueError, match="Unknown action"):
|
|
tool.execute_action("bad_action")
|
|
|
|
@patch("docsgpt.agents.tools.ntfy.pinned_request")
|
|
def test_send_message_basic(self, mock_pinned_request, tool):
|
|
mock_resp = MagicMock()
|
|
mock_resp.status_code = 200
|
|
mock_pinned_request.return_value = mock_resp
|
|
|
|
result = tool.execute_action(
|
|
"ntfy_send_message",
|
|
server_url="https://ntfy.sh",
|
|
message="Hello",
|
|
topic="test",
|
|
)
|
|
|
|
assert result["status_code"] == 200
|
|
assert result["message"] == "Message sent"
|
|
mock_pinned_request.assert_called_once()
|
|
args, kwargs = mock_pinned_request.call_args
|
|
assert args[0] == "POST"
|
|
assert args[1] == "https://ntfy.sh/test"
|
|
assert kwargs["data"] == b"Hello"
|
|
|
|
@patch("docsgpt.agents.tools.ntfy.pinned_request")
|
|
def test_send_with_title_and_priority(self, mock_pinned_request, tool):
|
|
mock_resp = MagicMock()
|
|
mock_resp.status_code = 200
|
|
mock_pinned_request.return_value = mock_resp
|
|
|
|
tool.execute_action(
|
|
"ntfy_send_message",
|
|
server_url="https://ntfy.sh",
|
|
message="Alert",
|
|
topic="urgent",
|
|
title="Warning",
|
|
priority=5,
|
|
)
|
|
|
|
headers = mock_pinned_request.call_args[1]["headers"]
|
|
assert headers["X-Title"] == "Warning"
|
|
assert headers["X-Priority"] == "5"
|
|
|
|
@patch("docsgpt.agents.tools.ntfy.pinned_request")
|
|
def test_auth_header_with_token(self, mock_pinned_request, tool):
|
|
mock_resp = MagicMock()
|
|
mock_resp.status_code = 200
|
|
mock_pinned_request.return_value = mock_resp
|
|
|
|
tool.execute_action(
|
|
"ntfy_send_message",
|
|
server_url="https://ntfy.sh",
|
|
message="Hi",
|
|
topic="t",
|
|
)
|
|
|
|
headers = mock_pinned_request.call_args[1]["headers"]
|
|
assert headers["Authorization"] == "Basic test_token"
|
|
|
|
@patch("docsgpt.agents.tools.ntfy.pinned_request")
|
|
def test_no_auth_without_token(self, mock_pinned_request, tool_no_token):
|
|
mock_resp = MagicMock()
|
|
mock_resp.status_code = 200
|
|
mock_pinned_request.return_value = mock_resp
|
|
|
|
tool_no_token.execute_action(
|
|
"ntfy_send_message",
|
|
server_url="https://ntfy.sh",
|
|
message="Hi",
|
|
topic="t",
|
|
)
|
|
|
|
headers = mock_pinned_request.call_args[1]["headers"]
|
|
assert "Authorization" not in headers
|
|
|
|
def test_invalid_priority_raises(self, tool):
|
|
with pytest.raises(ValueError, match="between 1 and 5"):
|
|
tool.execute_action(
|
|
"ntfy_send_message",
|
|
server_url="https://ntfy.sh",
|
|
message="Hi",
|
|
topic="t",
|
|
priority=10,
|
|
)
|
|
|
|
def test_non_numeric_priority_raises(self, tool):
|
|
with pytest.raises(ValueError, match="convertible to an integer"):
|
|
tool.execute_action(
|
|
"ntfy_send_message",
|
|
server_url="https://ntfy.sh",
|
|
message="Hi",
|
|
topic="t",
|
|
priority="abc",
|
|
)
|
|
|
|
@patch("docsgpt.agents.tools.ntfy.pinned_request")
|
|
def test_trailing_slash_stripped(self, mock_pinned_request, tool):
|
|
mock_resp = MagicMock()
|
|
mock_resp.status_code = 200
|
|
mock_pinned_request.return_value = mock_resp
|
|
|
|
tool.execute_action(
|
|
"ntfy_send_message",
|
|
server_url="https://ntfy.sh/",
|
|
message="Hi",
|
|
topic="test",
|
|
)
|
|
|
|
assert mock_pinned_request.call_args[0][1] == "https://ntfy.sh/test"
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestNtfyMetadata:
|
|
def test_actions_metadata(self, tool):
|
|
meta = tool.get_actions_metadata()
|
|
assert len(meta) == 1
|
|
assert meta[0]["name"] == "ntfy_send_message"
|
|
assert "server_url" in meta[0]["parameters"]["properties"]
|
|
assert "message" in meta[0]["parameters"]["properties"]
|
|
assert "topic" in meta[0]["parameters"]["properties"]
|
|
|
|
def test_config_requirements(self, tool):
|
|
reqs = tool.get_config_requirements()
|
|
assert "token" in reqs
|
|
assert reqs["token"]["secret"] is True
|