cortexflow-google-calendar 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_google_calendar-0.1.0/LICENSE +21 -0
- cortexflow_google_calendar-0.1.0/PKG-INFO +50 -0
- cortexflow_google_calendar-0.1.0/README.md +34 -0
- cortexflow_google_calendar-0.1.0/pyproject.toml +31 -0
- cortexflow_google_calendar-0.1.0/setup.cfg +4 -0
- cortexflow_google_calendar-0.1.0/src/cortexflow_google_calendar/__init__.py +7 -0
- cortexflow_google_calendar-0.1.0/src/cortexflow_google_calendar/plugin.py +34 -0
- cortexflow_google_calendar-0.1.0/src/cortexflow_google_calendar/tool.py +79 -0
- cortexflow_google_calendar-0.1.0/src/cortexflow_google_calendar.egg-info/PKG-INFO +50 -0
- cortexflow_google_calendar-0.1.0/src/cortexflow_google_calendar.egg-info/SOURCES.txt +14 -0
- cortexflow_google_calendar-0.1.0/src/cortexflow_google_calendar.egg-info/dependency_links.txt +1 -0
- cortexflow_google_calendar-0.1.0/src/cortexflow_google_calendar.egg-info/entry_points.txt +2 -0
- cortexflow_google_calendar-0.1.0/src/cortexflow_google_calendar.egg-info/requires.txt +6 -0
- cortexflow_google_calendar-0.1.0/src/cortexflow_google_calendar.egg-info/top_level.txt +1 -0
- cortexflow_google_calendar-0.1.0/tests/test_plugin.py +36 -0
- cortexflow_google_calendar-0.1.0/tests/test_tool.py +133 -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,50 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cortexflow-google-calendar
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CortexFlow plugin — list upcoming Google Calendar events.
|
|
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-google-calendar
|
|
18
|
+
|
|
19
|
+
Example CortexFlow plugin: a `calendar_list_events` tool that lists upcoming
|
|
20
|
+
events from a Google Calendar via Calendar API v3.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e ./cortexflow-sdk # not yet on PyPI
|
|
26
|
+
pip install -e examples/plugins/cortexflow-google-calendar
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Setup
|
|
30
|
+
|
|
31
|
+
This tool expects an OAuth2 **access token** with the
|
|
32
|
+
`https://www.googleapis.com/auth/calendar.readonly` scope, set as
|
|
33
|
+
`GOOGLE_CALENDAR_ACCESS_TOKEN`. Obtaining and refreshing that token (the
|
|
34
|
+
OAuth consent flow against Google's identity service) is outside this
|
|
35
|
+
plugin's scope — wire it up via your own token-refresh job or a library like
|
|
36
|
+
`google-auth-oauthlib`.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from cortexflow_google_calendar import GoogleCalendarEventsTool
|
|
42
|
+
|
|
43
|
+
tool = GoogleCalendarEventsTool(access_token="ya29....")
|
|
44
|
+
result = await tool.execute(calendar_id="primary", limit=5)
|
|
45
|
+
print(result.output)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Once installed alongside the CortexFlow gateway, `PluginRegistry.discover()`
|
|
49
|
+
finds it via the `cortexflow.plugins` entry point declared in
|
|
50
|
+
`pyproject.toml`.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# cortexflow-google-calendar
|
|
2
|
+
|
|
3
|
+
Example CortexFlow plugin: a `calendar_list_events` tool that lists upcoming
|
|
4
|
+
events from a Google Calendar via Calendar API v3.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install -e ./cortexflow-sdk # not yet on PyPI
|
|
10
|
+
pip install -e examples/plugins/cortexflow-google-calendar
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
This tool expects an OAuth2 **access token** with the
|
|
16
|
+
`https://www.googleapis.com/auth/calendar.readonly` scope, set as
|
|
17
|
+
`GOOGLE_CALENDAR_ACCESS_TOKEN`. Obtaining and refreshing that token (the
|
|
18
|
+
OAuth consent flow against Google's identity service) is outside this
|
|
19
|
+
plugin's scope — wire it up via your own token-refresh job or a library like
|
|
20
|
+
`google-auth-oauthlib`.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from cortexflow_google_calendar import GoogleCalendarEventsTool
|
|
26
|
+
|
|
27
|
+
tool = GoogleCalendarEventsTool(access_token="ya29....")
|
|
28
|
+
result = await tool.execute(calendar_id="primary", limit=5)
|
|
29
|
+
print(result.output)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Once installed alongside the CortexFlow gateway, `PluginRegistry.discover()`
|
|
33
|
+
finds it via the `cortexflow.plugins` entry point declared in
|
|
34
|
+
`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-google-calendar"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "CortexFlow plugin — list upcoming Google Calendar events."
|
|
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-google-calendar = "cortexflow_google_calendar.plugin:GoogleCalendarPlugin"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
where = ["src"]
|
|
29
|
+
|
|
30
|
+
[tool.pytest.ini_options]
|
|
31
|
+
asyncio_mode = "auto"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""cortexflow-google-calendar — example CortexFlow plugin: Calendar events."""
|
|
2
|
+
|
|
3
|
+
from cortexflow_google_calendar.plugin import GoogleCalendarPlugin
|
|
4
|
+
from cortexflow_google_calendar.tool import GoogleCalendarEventsTool
|
|
5
|
+
|
|
6
|
+
__all__ = ["GoogleCalendarEventsTool", "GoogleCalendarPlugin"]
|
|
7
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""GoogleCalendarPlugin — registers GoogleCalendarEventsTool with the gateway."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from cortexflow_sdk import Plugin, PluginMetadata
|
|
8
|
+
|
|
9
|
+
from cortexflow_google_calendar.tool import GoogleCalendarEventsTool
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class GoogleCalendarPlugin(Plugin):
|
|
13
|
+
"""Adds a calendar_list_events tool.
|
|
14
|
+
|
|
15
|
+
Reads GOOGLE_CALENDAR_ACCESS_TOKEN from the environment — a short-lived
|
|
16
|
+
OAuth2 access token, not a long-lived API key. Refreshing that token is
|
|
17
|
+
left to the operator (e.g. a cron job calling Google's OAuth2 token
|
|
18
|
+
endpoint with a stored refresh token).
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
metadata = PluginMetadata(
|
|
22
|
+
name="cortexflow-google-calendar",
|
|
23
|
+
version="0.1.0",
|
|
24
|
+
plugin_type="tool",
|
|
25
|
+
description="List upcoming Google Calendar events.",
|
|
26
|
+
permissions=["network"],
|
|
27
|
+
homepage="https://github.com/TheAmitChandra/CortexFlow",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
def __init__(self) -> None:
|
|
31
|
+
self._access_token = os.getenv("GOOGLE_CALENDAR_ACCESS_TOKEN")
|
|
32
|
+
|
|
33
|
+
def get_tools(self):
|
|
34
|
+
return [GoogleCalendarEventsTool(access_token=self._access_token)]
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""GoogleCalendarEventsTool — lists upcoming events from a Google Calendar."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import datetime
|
|
6
|
+
|
|
7
|
+
from cortexflow_sdk import Tool, ToolResult
|
|
8
|
+
|
|
9
|
+
_EVENTS_URL = "https://www.googleapis.com/calendar/v3/calendars/{calendar_id}/events"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _now_iso() -> str:
|
|
13
|
+
return datetime.datetime.now(datetime.timezone.utc).isoformat()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class GoogleCalendarEventsTool(Tool):
|
|
17
|
+
"""Lists upcoming events from a Google Calendar via the Calendar API v3.
|
|
18
|
+
|
|
19
|
+
Requires an OAuth2 access token with the
|
|
20
|
+
``https://www.googleapis.com/auth/calendar.readonly`` scope — obtaining
|
|
21
|
+
that token (the OAuth consent flow) is out of scope for this tool.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
name = "calendar_list_events"
|
|
25
|
+
description = "List upcoming events from a Google Calendar."
|
|
26
|
+
parameters = {
|
|
27
|
+
"calendar_id": {
|
|
28
|
+
"type": "str",
|
|
29
|
+
"description": "Calendar ID, or 'primary' for the user's main calendar",
|
|
30
|
+
"required": False,
|
|
31
|
+
},
|
|
32
|
+
"limit": {"type": "int", "description": "Max events to return (default 10)", "required": False},
|
|
33
|
+
}
|
|
34
|
+
permissions = ["network"]
|
|
35
|
+
|
|
36
|
+
def __init__(self, access_token: str | None = None) -> None:
|
|
37
|
+
self._access_token = access_token
|
|
38
|
+
|
|
39
|
+
async def execute(self, calendar_id: str = "primary", limit: int = 10, **_) -> ToolResult:
|
|
40
|
+
if not self._access_token:
|
|
41
|
+
return ToolResult(
|
|
42
|
+
tool=self.name, output=None, error="GOOGLE_CALENDAR_ACCESS_TOKEN not set",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
import httpx
|
|
47
|
+
except ImportError:
|
|
48
|
+
return ToolResult(tool=self.name, output=None, error="pip install httpx")
|
|
49
|
+
|
|
50
|
+
url = _EVENTS_URL.format(calendar_id=calendar_id)
|
|
51
|
+
headers = {"Authorization": f"Bearer {self._access_token}"}
|
|
52
|
+
params = {
|
|
53
|
+
"timeMin": _now_iso(),
|
|
54
|
+
"maxResults": min(limit, 100),
|
|
55
|
+
"singleEvents": "true",
|
|
56
|
+
"orderBy": "startTime",
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
async with httpx.AsyncClient() as client:
|
|
61
|
+
resp = await client.get(url, headers=headers, params=params, timeout=10.0)
|
|
62
|
+
resp.raise_for_status()
|
|
63
|
+
data = resp.json()
|
|
64
|
+
except Exception as exc:
|
|
65
|
+
return ToolResult(tool=self.name, output=None, error=str(exc))
|
|
66
|
+
|
|
67
|
+
events = [
|
|
68
|
+
{
|
|
69
|
+
"summary": e.get("summary", "(no title)"),
|
|
70
|
+
"start": (e.get("start") or {}).get("dateTime") or (e.get("start") or {}).get("date", ""),
|
|
71
|
+
"link": e.get("htmlLink", ""),
|
|
72
|
+
}
|
|
73
|
+
for e in data.get("items", [])[:limit]
|
|
74
|
+
]
|
|
75
|
+
return ToolResult(
|
|
76
|
+
tool=self.name,
|
|
77
|
+
output=events,
|
|
78
|
+
metadata={"calendar_id": calendar_id, "count": len(events)},
|
|
79
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cortexflow-google-calendar
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CortexFlow plugin — list upcoming Google Calendar events.
|
|
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-google-calendar
|
|
18
|
+
|
|
19
|
+
Example CortexFlow plugin: a `calendar_list_events` tool that lists upcoming
|
|
20
|
+
events from a Google Calendar via Calendar API v3.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e ./cortexflow-sdk # not yet on PyPI
|
|
26
|
+
pip install -e examples/plugins/cortexflow-google-calendar
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Setup
|
|
30
|
+
|
|
31
|
+
This tool expects an OAuth2 **access token** with the
|
|
32
|
+
`https://www.googleapis.com/auth/calendar.readonly` scope, set as
|
|
33
|
+
`GOOGLE_CALENDAR_ACCESS_TOKEN`. Obtaining and refreshing that token (the
|
|
34
|
+
OAuth consent flow against Google's identity service) is outside this
|
|
35
|
+
plugin's scope — wire it up via your own token-refresh job or a library like
|
|
36
|
+
`google-auth-oauthlib`.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from cortexflow_google_calendar import GoogleCalendarEventsTool
|
|
42
|
+
|
|
43
|
+
tool = GoogleCalendarEventsTool(access_token="ya29....")
|
|
44
|
+
result = await tool.execute(calendar_id="primary", limit=5)
|
|
45
|
+
print(result.output)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Once installed alongside the CortexFlow gateway, `PluginRegistry.discover()`
|
|
49
|
+
finds it via the `cortexflow.plugins` entry point declared in
|
|
50
|
+
`pyproject.toml`.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/cortexflow_google_calendar/__init__.py
|
|
5
|
+
src/cortexflow_google_calendar/plugin.py
|
|
6
|
+
src/cortexflow_google_calendar/tool.py
|
|
7
|
+
src/cortexflow_google_calendar.egg-info/PKG-INFO
|
|
8
|
+
src/cortexflow_google_calendar.egg-info/SOURCES.txt
|
|
9
|
+
src/cortexflow_google_calendar.egg-info/dependency_links.txt
|
|
10
|
+
src/cortexflow_google_calendar.egg-info/entry_points.txt
|
|
11
|
+
src/cortexflow_google_calendar.egg-info/requires.txt
|
|
12
|
+
src/cortexflow_google_calendar.egg-info/top_level.txt
|
|
13
|
+
tests/test_plugin.py
|
|
14
|
+
tests/test_tool.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cortexflow_google_calendar
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Unit tests for cortexflow_google_calendar.plugin — GoogleCalendarPlugin."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from cortexflow_google_calendar.plugin import GoogleCalendarPlugin
|
|
6
|
+
from cortexflow_google_calendar.tool import GoogleCalendarEventsTool
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_plugin_metadata():
|
|
10
|
+
p = GoogleCalendarPlugin()
|
|
11
|
+
assert p.metadata.name == "cortexflow-google-calendar"
|
|
12
|
+
assert p.metadata.plugin_type == "tool"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_plugin_reads_token_from_env(monkeypatch):
|
|
16
|
+
monkeypatch.setenv("GOOGLE_CALENDAR_ACCESS_TOKEN", "ya29.fromenv")
|
|
17
|
+
p = GoogleCalendarPlugin()
|
|
18
|
+
assert p._access_token == "ya29.fromenv"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_plugin_no_token_in_env(monkeypatch):
|
|
22
|
+
monkeypatch.delenv("GOOGLE_CALENDAR_ACCESS_TOKEN", raising=False)
|
|
23
|
+
p = GoogleCalendarPlugin()
|
|
24
|
+
assert p._access_token is None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_get_tools_returns_calendar_events_tool():
|
|
28
|
+
tools = GoogleCalendarPlugin().get_tools()
|
|
29
|
+
assert len(tools) == 1
|
|
30
|
+
assert isinstance(tools[0], GoogleCalendarEventsTool)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_get_tools_tool_carries_plugin_token(monkeypatch):
|
|
34
|
+
monkeypatch.setenv("GOOGLE_CALENDAR_ACCESS_TOKEN", "ya29.carried")
|
|
35
|
+
tool = GoogleCalendarPlugin().get_tools()[0]
|
|
36
|
+
assert tool._access_token == "ya29.carried"
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Unit tests for cortexflow_google_calendar.tool — GoogleCalendarEventsTool."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from unittest.mock import AsyncMock, MagicMock, patch
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
from cortexflow_google_calendar.tool import GoogleCalendarEventsTool
|
|
9
|
+
|
|
10
|
+
_SAMPLE_ITEMS = [
|
|
11
|
+
{
|
|
12
|
+
"summary": "Team standup",
|
|
13
|
+
"start": {"dateTime": "2026-06-27T10:00:00Z"},
|
|
14
|
+
"htmlLink": "https://calendar.google.com/event1",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"summary": "All-day offsite",
|
|
18
|
+
"start": {"date": "2026-06-28"},
|
|
19
|
+
"htmlLink": "https://calendar.google.com/event2",
|
|
20
|
+
},
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _make_mock_client(json_body, raise_on_status: Exception | None = None):
|
|
25
|
+
mock_resp = MagicMock()
|
|
26
|
+
mock_resp.raise_for_status = MagicMock(side_effect=raise_on_status)
|
|
27
|
+
mock_resp.json = MagicMock(return_value=json_body)
|
|
28
|
+
|
|
29
|
+
mock_client = MagicMock()
|
|
30
|
+
mock_client.__aenter__ = AsyncMock(return_value=mock_client)
|
|
31
|
+
mock_client.__aexit__ = AsyncMock(return_value=False)
|
|
32
|
+
mock_client.get = AsyncMock(return_value=mock_resp)
|
|
33
|
+
return mock_client
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.mark.asyncio
|
|
37
|
+
async def test_execute_no_token_returns_error():
|
|
38
|
+
tool = GoogleCalendarEventsTool(access_token=None)
|
|
39
|
+
result = await tool.execute()
|
|
40
|
+
assert not result.success
|
|
41
|
+
assert "GOOGLE_CALENDAR_ACCESS_TOKEN" in result.error
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@pytest.mark.asyncio
|
|
45
|
+
async def test_execute_returns_formatted_events():
|
|
46
|
+
tool = GoogleCalendarEventsTool(access_token="ya29.token")
|
|
47
|
+
mock_client = _make_mock_client({"items": _SAMPLE_ITEMS})
|
|
48
|
+
|
|
49
|
+
with patch("httpx.AsyncClient", return_value=mock_client):
|
|
50
|
+
result = await tool.execute(calendar_id="primary", limit=10)
|
|
51
|
+
|
|
52
|
+
assert result.success
|
|
53
|
+
assert result.output[0]["summary"] == "Team standup"
|
|
54
|
+
assert result.output[0]["start"] == "2026-06-27T10:00:00Z"
|
|
55
|
+
assert result.metadata["calendar_id"] == "primary"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@pytest.mark.asyncio
|
|
59
|
+
async def test_execute_falls_back_to_all_day_date():
|
|
60
|
+
tool = GoogleCalendarEventsTool(access_token="ya29.token")
|
|
61
|
+
mock_client = _make_mock_client({"items": [_SAMPLE_ITEMS[1]]})
|
|
62
|
+
|
|
63
|
+
with patch("httpx.AsyncClient", return_value=mock_client):
|
|
64
|
+
result = await tool.execute()
|
|
65
|
+
|
|
66
|
+
assert result.output[0]["start"] == "2026-06-28"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@pytest.mark.asyncio
|
|
70
|
+
async def test_execute_missing_summary_uses_placeholder():
|
|
71
|
+
tool = GoogleCalendarEventsTool(access_token="ya29.token")
|
|
72
|
+
mock_client = _make_mock_client({"items": [{"start": {"date": "2026-06-29"}}]})
|
|
73
|
+
|
|
74
|
+
with patch("httpx.AsyncClient", return_value=mock_client):
|
|
75
|
+
result = await tool.execute()
|
|
76
|
+
|
|
77
|
+
assert result.output[0]["summary"] == "(no title)"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@pytest.mark.asyncio
|
|
81
|
+
async def test_execute_sends_bearer_token_and_ordering_params():
|
|
82
|
+
tool = GoogleCalendarEventsTool(access_token="ya29.token")
|
|
83
|
+
mock_client = _make_mock_client({"items": []})
|
|
84
|
+
|
|
85
|
+
with patch("httpx.AsyncClient", return_value=mock_client):
|
|
86
|
+
await tool.execute()
|
|
87
|
+
|
|
88
|
+
call_kwargs = mock_client.get.call_args[1]
|
|
89
|
+
assert call_kwargs["headers"]["Authorization"] == "Bearer ya29.token"
|
|
90
|
+
assert call_kwargs["params"]["orderBy"] == "startTime"
|
|
91
|
+
assert "timeMin" in call_kwargs["params"]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@pytest.mark.asyncio
|
|
95
|
+
async def test_execute_respects_limit():
|
|
96
|
+
tool = GoogleCalendarEventsTool(access_token="ya29.token")
|
|
97
|
+
mock_client = _make_mock_client({"items": _SAMPLE_ITEMS})
|
|
98
|
+
|
|
99
|
+
with patch("httpx.AsyncClient", return_value=mock_client):
|
|
100
|
+
result = await tool.execute(limit=1)
|
|
101
|
+
|
|
102
|
+
assert len(result.output) == 1
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@pytest.mark.asyncio
|
|
106
|
+
async def test_execute_http_error_returns_error_result():
|
|
107
|
+
tool = GoogleCalendarEventsTool(access_token="ya29.token")
|
|
108
|
+
mock_client = _make_mock_client({}, raise_on_status=RuntimeError("403 Forbidden"))
|
|
109
|
+
|
|
110
|
+
with patch("httpx.AsyncClient", return_value=mock_client):
|
|
111
|
+
result = await tool.execute()
|
|
112
|
+
|
|
113
|
+
assert not result.success
|
|
114
|
+
assert "403" in result.error
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@pytest.mark.asyncio
|
|
118
|
+
async def test_execute_missing_httpx_returns_error():
|
|
119
|
+
import builtins
|
|
120
|
+
|
|
121
|
+
real_import = builtins.__import__
|
|
122
|
+
|
|
123
|
+
def fake_import(name, *args, **kwargs):
|
|
124
|
+
if name == "httpx":
|
|
125
|
+
raise ImportError("No module named 'httpx'")
|
|
126
|
+
return real_import(name, *args, **kwargs)
|
|
127
|
+
|
|
128
|
+
tool = GoogleCalendarEventsTool(access_token="ya29.token")
|
|
129
|
+
with patch("builtins.__import__", side_effect=fake_import):
|
|
130
|
+
result = await tool.execute()
|
|
131
|
+
|
|
132
|
+
assert not result.success
|
|
133
|
+
assert "pip install httpx" in result.error
|