cortexflow-notion 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cortexflow_notion-0.1.0/LICENSE +21 -0
- cortexflow_notion-0.1.0/PKG-INFO +47 -0
- cortexflow_notion-0.1.0/README.md +31 -0
- cortexflow_notion-0.1.0/pyproject.toml +31 -0
- cortexflow_notion-0.1.0/setup.cfg +4 -0
- cortexflow_notion-0.1.0/src/cortexflow_notion/__init__.py +7 -0
- cortexflow_notion-0.1.0/src/cortexflow_notion/plugin.py +28 -0
- cortexflow_notion-0.1.0/src/cortexflow_notion/tool.py +77 -0
- cortexflow_notion-0.1.0/src/cortexflow_notion.egg-info/PKG-INFO +47 -0
- cortexflow_notion-0.1.0/src/cortexflow_notion.egg-info/SOURCES.txt +14 -0
- cortexflow_notion-0.1.0/src/cortexflow_notion.egg-info/dependency_links.txt +1 -0
- cortexflow_notion-0.1.0/src/cortexflow_notion.egg-info/entry_points.txt +2 -0
- cortexflow_notion-0.1.0/src/cortexflow_notion.egg-info/requires.txt +6 -0
- cortexflow_notion-0.1.0/src/cortexflow_notion.egg-info/top_level.txt +1 -0
- cortexflow_notion-0.1.0/tests/test_plugin.py +36 -0
- cortexflow_notion-0.1.0/tests/test_tool.py +103 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Amit Chandra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cortexflow-notion
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CortexFlow plugin — search Notion pages and databases.
|
|
5
|
+
Author-email: Amit Chandra <amit.vervebot@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: cortexflow-sdk>=0.1.0
|
|
11
|
+
Requires-Dist: httpx>=0.27.0
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest>=8.2.0; extra == "dev"
|
|
14
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# cortexflow-notion
|
|
18
|
+
|
|
19
|
+
Example CortexFlow plugin: a `notion_search` tool that searches Notion pages
|
|
20
|
+
and databases shared with your Notion integration.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e ./cortexflow-sdk # not yet on PyPI
|
|
26
|
+
pip install -e examples/plugins/cortexflow-notion
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Setup
|
|
30
|
+
|
|
31
|
+
1. Create a Notion integration at https://www.notion.so/my-integrations
|
|
32
|
+
2. Share the pages/databases you want searchable with that integration
|
|
33
|
+
3. Set `NOTION_TOKEN` in your environment to the integration's secret
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from cortexflow_notion import NotionSearchTool
|
|
39
|
+
|
|
40
|
+
tool = NotionSearchTool(token="secret_...")
|
|
41
|
+
result = await tool.execute(query="Q3 roadmap", limit=5)
|
|
42
|
+
print(result.output)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Once installed alongside the CortexFlow gateway, `PluginRegistry.discover()`
|
|
46
|
+
finds it via the `cortexflow.plugins` entry point declared in
|
|
47
|
+
`pyproject.toml`.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# cortexflow-notion
|
|
2
|
+
|
|
3
|
+
Example CortexFlow plugin: a `notion_search` tool that searches Notion pages
|
|
4
|
+
and databases shared with your Notion integration.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install -e ./cortexflow-sdk # not yet on PyPI
|
|
10
|
+
pip install -e examples/plugins/cortexflow-notion
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
1. Create a Notion integration at https://www.notion.so/my-integrations
|
|
16
|
+
2. Share the pages/databases you want searchable with that integration
|
|
17
|
+
3. Set `NOTION_TOKEN` in your environment to the integration's secret
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from cortexflow_notion import NotionSearchTool
|
|
23
|
+
|
|
24
|
+
tool = NotionSearchTool(token="secret_...")
|
|
25
|
+
result = await tool.execute(query="Q3 roadmap", limit=5)
|
|
26
|
+
print(result.output)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Once installed alongside the CortexFlow gateway, `PluginRegistry.discover()`
|
|
30
|
+
finds it via the `cortexflow.plugins` entry point declared in
|
|
31
|
+
`pyproject.toml`.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "cortexflow-notion"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "CortexFlow plugin — search Notion pages and databases."
|
|
9
|
+
authors = [{ name = "Amit Chandra", email = "amit.vervebot@gmail.com" }]
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
license = { text = "MIT" }
|
|
13
|
+
dependencies = [
|
|
14
|
+
"cortexflow-sdk>=0.1.0",
|
|
15
|
+
"httpx>=0.27.0",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.optional-dependencies]
|
|
19
|
+
dev = [
|
|
20
|
+
"pytest>=8.2.0",
|
|
21
|
+
"pytest-asyncio>=0.23.0",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.entry-points."cortexflow.plugins"]
|
|
25
|
+
cortexflow-notion = "cortexflow_notion.plugin:NotionPlugin"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
where = ["src"]
|
|
29
|
+
|
|
30
|
+
[tool.pytest.ini_options]
|
|
31
|
+
asyncio_mode = "auto"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""NotionPlugin — registers NotionSearchTool with the CortexFlow gateway."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from cortexflow_sdk import Plugin, PluginMetadata
|
|
8
|
+
|
|
9
|
+
from cortexflow_notion.tool import NotionSearchTool
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class NotionPlugin(Plugin):
|
|
13
|
+
"""Adds a notion_search tool. Reads NOTION_TOKEN from the environment."""
|
|
14
|
+
|
|
15
|
+
metadata = PluginMetadata(
|
|
16
|
+
name="cortexflow-notion",
|
|
17
|
+
version="0.1.0",
|
|
18
|
+
plugin_type="tool",
|
|
19
|
+
description="Search Notion pages and databases.",
|
|
20
|
+
permissions=["network"],
|
|
21
|
+
homepage="https://github.com/TheAmitChandra/CortexFlow",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def __init__(self) -> None:
|
|
25
|
+
self._token = os.getenv("NOTION_TOKEN")
|
|
26
|
+
|
|
27
|
+
def get_tools(self):
|
|
28
|
+
return [NotionSearchTool(token=self._token)]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""NotionSearchTool — searches Notion pages and databases by query."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from cortexflow_sdk import Tool, ToolResult
|
|
8
|
+
|
|
9
|
+
_SEARCH_URL = "https://api.notion.com/v1/search"
|
|
10
|
+
_NOTION_VERSION = "2022-06-28"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _extract_title(result: dict[str, Any]) -> str:
|
|
14
|
+
"""Pull the plain-text title out of a Notion page/database object."""
|
|
15
|
+
for prop in result.get("properties", {}).values():
|
|
16
|
+
if prop.get("type") == "title":
|
|
17
|
+
texts = prop.get("title", [])
|
|
18
|
+
return "".join(t.get("plain_text", "") for t in texts) or "(untitled)"
|
|
19
|
+
return "(untitled)"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class NotionSearchTool(Tool):
|
|
23
|
+
"""Searches Notion pages and databases shared with the integration."""
|
|
24
|
+
|
|
25
|
+
name = "notion_search"
|
|
26
|
+
description = "Search Notion pages and databases by query text."
|
|
27
|
+
parameters = {
|
|
28
|
+
"query": {"type": "str", "description": "Search text", "required": True},
|
|
29
|
+
"limit": {"type": "int", "description": "Max results to return (default 10)", "required": False},
|
|
30
|
+
}
|
|
31
|
+
permissions = ["network"]
|
|
32
|
+
|
|
33
|
+
def __init__(self, token: str | None = None) -> None:
|
|
34
|
+
self._token = token
|
|
35
|
+
|
|
36
|
+
async def execute(self, query: str, limit: int = 10, **_) -> ToolResult:
|
|
37
|
+
if not self._token:
|
|
38
|
+
return ToolResult(tool=self.name, output=None, error="NOTION_TOKEN not set")
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
import httpx
|
|
42
|
+
except ImportError:
|
|
43
|
+
return ToolResult(tool=self.name, output=None, error="pip install httpx")
|
|
44
|
+
|
|
45
|
+
headers = {
|
|
46
|
+
"Authorization": f"Bearer {self._token}",
|
|
47
|
+
"Notion-Version": _NOTION_VERSION,
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
async with httpx.AsyncClient() as client:
|
|
53
|
+
resp = await client.post(
|
|
54
|
+
_SEARCH_URL,
|
|
55
|
+
headers=headers,
|
|
56
|
+
json={"query": query, "page_size": min(limit, 100)},
|
|
57
|
+
timeout=10.0,
|
|
58
|
+
)
|
|
59
|
+
resp.raise_for_status()
|
|
60
|
+
data = resp.json()
|
|
61
|
+
except Exception as exc:
|
|
62
|
+
return ToolResult(tool=self.name, output=None, error=str(exc))
|
|
63
|
+
|
|
64
|
+
results = [
|
|
65
|
+
{
|
|
66
|
+
"id": r.get("id", ""),
|
|
67
|
+
"type": r.get("object", "unknown"),
|
|
68
|
+
"url": r.get("url", ""),
|
|
69
|
+
"title": _extract_title(r),
|
|
70
|
+
}
|
|
71
|
+
for r in data.get("results", [])[:limit]
|
|
72
|
+
]
|
|
73
|
+
return ToolResult(
|
|
74
|
+
tool=self.name,
|
|
75
|
+
output=results,
|
|
76
|
+
metadata={"query": query, "count": len(results)},
|
|
77
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cortexflow-notion
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CortexFlow plugin — search Notion pages and databases.
|
|
5
|
+
Author-email: Amit Chandra <amit.vervebot@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: cortexflow-sdk>=0.1.0
|
|
11
|
+
Requires-Dist: httpx>=0.27.0
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest>=8.2.0; extra == "dev"
|
|
14
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# cortexflow-notion
|
|
18
|
+
|
|
19
|
+
Example CortexFlow plugin: a `notion_search` tool that searches Notion pages
|
|
20
|
+
and databases shared with your Notion integration.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e ./cortexflow-sdk # not yet on PyPI
|
|
26
|
+
pip install -e examples/plugins/cortexflow-notion
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Setup
|
|
30
|
+
|
|
31
|
+
1. Create a Notion integration at https://www.notion.so/my-integrations
|
|
32
|
+
2. Share the pages/databases you want searchable with that integration
|
|
33
|
+
3. Set `NOTION_TOKEN` in your environment to the integration's secret
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from cortexflow_notion import NotionSearchTool
|
|
39
|
+
|
|
40
|
+
tool = NotionSearchTool(token="secret_...")
|
|
41
|
+
result = await tool.execute(query="Q3 roadmap", limit=5)
|
|
42
|
+
print(result.output)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Once installed alongside the CortexFlow gateway, `PluginRegistry.discover()`
|
|
46
|
+
finds it via the `cortexflow.plugins` entry point declared in
|
|
47
|
+
`pyproject.toml`.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/cortexflow_notion/__init__.py
|
|
5
|
+
src/cortexflow_notion/plugin.py
|
|
6
|
+
src/cortexflow_notion/tool.py
|
|
7
|
+
src/cortexflow_notion.egg-info/PKG-INFO
|
|
8
|
+
src/cortexflow_notion.egg-info/SOURCES.txt
|
|
9
|
+
src/cortexflow_notion.egg-info/dependency_links.txt
|
|
10
|
+
src/cortexflow_notion.egg-info/entry_points.txt
|
|
11
|
+
src/cortexflow_notion.egg-info/requires.txt
|
|
12
|
+
src/cortexflow_notion.egg-info/top_level.txt
|
|
13
|
+
tests/test_plugin.py
|
|
14
|
+
tests/test_tool.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cortexflow_notion
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Unit tests for cortexflow_notion.plugin — NotionPlugin."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from cortexflow_notion.plugin import NotionPlugin
|
|
6
|
+
from cortexflow_notion.tool import NotionSearchTool
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_plugin_metadata():
|
|
10
|
+
p = NotionPlugin()
|
|
11
|
+
assert p.metadata.name == "cortexflow-notion"
|
|
12
|
+
assert p.metadata.plugin_type == "tool"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_plugin_reads_token_from_env(monkeypatch):
|
|
16
|
+
monkeypatch.setenv("NOTION_TOKEN", "secret_fromenv")
|
|
17
|
+
p = NotionPlugin()
|
|
18
|
+
assert p._token == "secret_fromenv"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_plugin_no_token_in_env(monkeypatch):
|
|
22
|
+
monkeypatch.delenv("NOTION_TOKEN", raising=False)
|
|
23
|
+
p = NotionPlugin()
|
|
24
|
+
assert p._token is None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_get_tools_returns_notion_search_tool():
|
|
28
|
+
tools = NotionPlugin().get_tools()
|
|
29
|
+
assert len(tools) == 1
|
|
30
|
+
assert isinstance(tools[0], NotionSearchTool)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_get_tools_tool_carries_plugin_token(monkeypatch):
|
|
34
|
+
monkeypatch.setenv("NOTION_TOKEN", "secret_carried")
|
|
35
|
+
tool = NotionPlugin().get_tools()[0]
|
|
36
|
+
assert tool._token == "secret_carried"
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Unit tests for cortexflow_notion.tool — NotionSearchTool."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from unittest.mock import AsyncMock, MagicMock, patch
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
from cortexflow_notion.tool import NotionSearchTool, _extract_title
|
|
9
|
+
|
|
10
|
+
_SAMPLE_RESULT = {
|
|
11
|
+
"id": "page-1",
|
|
12
|
+
"object": "page",
|
|
13
|
+
"url": "https://notion.so/page-1",
|
|
14
|
+
"properties": {
|
|
15
|
+
"Name": {"type": "title", "title": [{"plain_text": "Q3 "}, {"plain_text": "Roadmap"}]},
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _make_mock_client(json_body, raise_on_status: Exception | None = None):
|
|
21
|
+
mock_resp = MagicMock()
|
|
22
|
+
mock_resp.raise_for_status = MagicMock(side_effect=raise_on_status)
|
|
23
|
+
mock_resp.json = MagicMock(return_value=json_body)
|
|
24
|
+
|
|
25
|
+
mock_client = MagicMock()
|
|
26
|
+
mock_client.__aenter__ = AsyncMock(return_value=mock_client)
|
|
27
|
+
mock_client.__aexit__ = AsyncMock(return_value=False)
|
|
28
|
+
mock_client.post = AsyncMock(return_value=mock_resp)
|
|
29
|
+
return mock_client
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_extract_title_joins_rich_text_segments():
|
|
33
|
+
assert _extract_title(_SAMPLE_RESULT) == "Q3 Roadmap"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_extract_title_untitled_when_no_title_property():
|
|
37
|
+
assert _extract_title({"properties": {}}) == "(untitled)"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@pytest.mark.asyncio
|
|
41
|
+
async def test_execute_no_token_returns_error():
|
|
42
|
+
tool = NotionSearchTool(token=None)
|
|
43
|
+
result = await tool.execute(query="x")
|
|
44
|
+
assert not result.success
|
|
45
|
+
assert "NOTION_TOKEN" in result.error
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.mark.asyncio
|
|
49
|
+
async def test_execute_returns_formatted_results():
|
|
50
|
+
tool = NotionSearchTool(token="secret_abc")
|
|
51
|
+
mock_client = _make_mock_client({"results": [_SAMPLE_RESULT]})
|
|
52
|
+
|
|
53
|
+
with patch("httpx.AsyncClient", return_value=mock_client):
|
|
54
|
+
result = await tool.execute(query="roadmap")
|
|
55
|
+
|
|
56
|
+
assert result.success
|
|
57
|
+
assert result.output[0]["title"] == "Q3 Roadmap"
|
|
58
|
+
assert result.output[0]["type"] == "page"
|
|
59
|
+
assert result.metadata["query"] == "roadmap"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@pytest.mark.asyncio
|
|
63
|
+
async def test_execute_sends_notion_version_header():
|
|
64
|
+
tool = NotionSearchTool(token="secret_abc")
|
|
65
|
+
mock_client = _make_mock_client({"results": []})
|
|
66
|
+
|
|
67
|
+
with patch("httpx.AsyncClient", return_value=mock_client):
|
|
68
|
+
await tool.execute(query="x")
|
|
69
|
+
|
|
70
|
+
headers = mock_client.post.call_args[1]["headers"]
|
|
71
|
+
assert headers["Authorization"] == "Bearer secret_abc"
|
|
72
|
+
assert headers["Notion-Version"] == "2022-06-28"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@pytest.mark.asyncio
|
|
76
|
+
async def test_execute_http_error_returns_error_result():
|
|
77
|
+
tool = NotionSearchTool(token="secret_abc")
|
|
78
|
+
mock_client = _make_mock_client({}, raise_on_status=RuntimeError("401 Unauthorized"))
|
|
79
|
+
|
|
80
|
+
with patch("httpx.AsyncClient", return_value=mock_client):
|
|
81
|
+
result = await tool.execute(query="x")
|
|
82
|
+
|
|
83
|
+
assert not result.success
|
|
84
|
+
assert "401" in result.error
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.mark.asyncio
|
|
88
|
+
async def test_execute_missing_httpx_returns_error():
|
|
89
|
+
import builtins
|
|
90
|
+
|
|
91
|
+
real_import = builtins.__import__
|
|
92
|
+
|
|
93
|
+
def fake_import(name, *args, **kwargs):
|
|
94
|
+
if name == "httpx":
|
|
95
|
+
raise ImportError("No module named 'httpx'")
|
|
96
|
+
return real_import(name, *args, **kwargs)
|
|
97
|
+
|
|
98
|
+
tool = NotionSearchTool(token="secret_abc")
|
|
99
|
+
with patch("builtins.__import__", side_effect=fake_import):
|
|
100
|
+
result = await tool.execute(query="x")
|
|
101
|
+
|
|
102
|
+
assert not result.success
|
|
103
|
+
assert "pip install httpx" in result.error
|