|
1 | 1 | import json |
2 | 2 | from fastmcp.client import Client |
3 | | -from garth.users.profile import UserProfile |
| 3 | +import garth |
4 | 4 |
|
5 | 5 | async def test_list_tools(mcp_client: Client): |
6 | 6 | list_tools = await mcp_client.list_tools() |
7 | | - |
8 | 7 | assert len(list_tools) > 0 |
9 | 8 |
|
10 | | - |
11 | | - |
12 | | -async def test_get_profile(mcp_client: Client): |
| 9 | +# Garth data class tools |
| 10 | +async def test_user_profile(mcp_client: Client): |
13 | 11 | response = await mcp_client.call_tool("user_profile") |
14 | | - #breakpoint() |
| 12 | + assert response.is_error is False |
| 13 | + assert response.content[0].type == "text" |
15 | 14 | profile_data = json.loads(response.content[0].text) |
| 15 | + assert garth.UserProfile(**profile_data) |
| 16 | + |
| 17 | +async def test_user_settings(mcp_client: Client): |
| 18 | + response = await mcp_client.call_tool("user_settings") |
| 19 | + assert response.is_error is False |
| 20 | + assert response.content[0].type == "text" |
| 21 | + settings_data = json.loads(response.content[0].text) |
| 22 | + assert garth.UserSettings(**settings_data) |
| 23 | + |
| 24 | +async def test_weekly_intensity_minutes(mcp_client: Client): |
| 25 | + response = await mcp_client.call_tool("weekly_intensity_minutes") |
| 26 | + assert response.is_error is False |
| 27 | + assert response.content[0].type == "text" |
| 28 | + data = json.loads(response.content[0].text) |
| 29 | + assert isinstance(data, dict) |
| 30 | + assert garth.WeeklyIntensityMinutes(**data) |
| 31 | + |
| 32 | +async def test_daily_body_battery(mcp_client: Client): |
| 33 | + response = await mcp_client.call_tool("daily_body_battery") |
| 34 | + assert response.is_error is False |
| 35 | + assert response.content[0].type == "text" |
| 36 | + data = json.loads(response.content[0].text) |
| 37 | + assert isinstance(data, dict) |
| 38 | + assert garth.DailyBodyBatteryStress(**data) |
| 39 | + |
| 40 | +async def test_daily_hydration(mcp_client: Client): |
| 41 | + response = await mcp_client.call_tool("daily_hydration") |
| 42 | + assert response.is_error is False |
| 43 | + assert response.content[0].type == "text" |
| 44 | + data = json.loads(response.content[0].text) |
| 45 | + assert isinstance(data, dict) |
| 46 | + assert garth.DailyHydration(**data) |
| 47 | + |
| 48 | +async def test_daily_steps(mcp_client: Client): |
| 49 | + response = await mcp_client.call_tool("daily_steps") |
| 50 | + assert response.is_error is False |
| 51 | + assert response.content[0].type == "text" |
| 52 | + data = json.loads(response.content[0].text) |
| 53 | + assert isinstance(data, dict) |
| 54 | + assert garth.DailySteps(**data) |
| 55 | + |
| 56 | +async def test_weekly_steps(mcp_client: Client): |
| 57 | + response = await mcp_client.call_tool("weekly_steps") |
| 58 | + assert response.is_error is False |
| 59 | + assert response.content[0].type == "text" |
| 60 | + data = json.loads(response.content[0].text) |
| 61 | + assert isinstance(data, dict) |
| 62 | + assert garth.WeeklySteps(**data) |
| 63 | + |
| 64 | +async def test_daily_hrv(mcp_client: Client): |
| 65 | + response = await mcp_client.call_tool("daily_hrv") |
| 66 | + assert response.is_error is False |
| 67 | + assert response.content[0].type == "text" |
| 68 | + data = json.loads(response.content[0].text) |
| 69 | + assert isinstance(data, dict) |
| 70 | + assert garth.DailyHRV(**data) |
| 71 | + |
| 72 | +async def test_hrv_data(mcp_client: Client): |
| 73 | + response = await mcp_client.call_tool("hrv_data") |
| 74 | + assert response.is_error is False |
| 75 | + assert response.content[0].type == "text" |
| 76 | + data = json.loads(response.content[0].text) |
| 77 | + assert isinstance(data, dict) |
| 78 | + assert garth.HRVData(**data) |
| 79 | + |
| 80 | +async def test_daily_sleep(mcp_client: Client): |
| 81 | + response = await mcp_client.call_tool("daily_sleep") |
| 82 | + assert response.is_error is False |
| 83 | + assert response.content[0].type == "text" |
| 84 | + data = json.loads(response.content[0].text) |
| 85 | + assert isinstance(data, dict) |
| 86 | + assert garth.DailySleep(**data) |
| 87 | + |
| 88 | +async def test_nightly_sleep(mcp_client: Client): |
| 89 | + response = await mcp_client.call_tool("nightly_sleep") |
| 90 | + assert response.is_error is False |
| 91 | + assert response.content[0].type == "text" |
| 92 | + data = json.loads(response.content[0].text) |
| 93 | + assert isinstance(data, dict) |
| 94 | + assert garth.SleepData(**data) |
| 95 | + |
| 96 | +async def test_daily_stress(mcp_client: Client): |
| 97 | + response = await mcp_client.call_tool("daily_stress") |
| 98 | + assert response.is_error is False |
| 99 | + assert response.content[0].type == "text" |
| 100 | + data = json.loads(response.content[0].text) |
| 101 | + assert isinstance(data, dict) |
| 102 | + assert garth.DailyStress(**data) |
| 103 | + |
| 104 | +async def test_weekly_stress(mcp_client: Client): |
| 105 | + response = await mcp_client.call_tool("weekly_stress") |
| 106 | + assert response.is_error is False |
| 107 | + assert response.content[0].type == "text" |
| 108 | + data = json.loads(response.content[0].text) |
| 109 | + assert isinstance(data, dict) |
| 110 | + assert garth.WeeklyStress(**data) |
| 111 | + |
| 112 | +async def test_daily_intensity_minutes(mcp_client: Client): |
| 113 | + response = await mcp_client.call_tool("daily_intensity_minutes") |
| 114 | + assert response.is_error is False |
| 115 | + assert response.content[0].type == "text" |
| 116 | + data = json.loads(response.content[0].text) |
| 117 | + assert isinstance(data, dict) |
| 118 | + assert garth.DailyIntensityMinutes(**data) |
| 119 | + |
| 120 | +# ConnectAPI tools |
| 121 | +async def test_get_activities(mcp_client: Client): |
| 122 | + response = await mcp_client.call_tool("get_activities") |
| 123 | + assert response.is_error is False |
| 124 | + assert response.content[0].type == "text" |
| 125 | + data = json.loads(response.content[0].text) |
| 126 | + assert isinstance(data, dict) |
| 127 | + |
| 128 | +async def test_get_activities_by_date(mcp_client: Client): |
| 129 | + response = await mcp_client.call_tool("get_activities_by_date", {"date": "2024-01-15"}) |
| 130 | + assert response.is_error is False |
| 131 | + assert response.content[0].type == "text" |
| 132 | + data = json.loads(response.content[0].text) |
| 133 | + assert isinstance(data, (dict, list)) |
| 134 | + |
| 135 | +async def test_activity_related_tools(mcp_client: Client): |
| 136 | + # First get activities to find a real activity ID |
| 137 | + activities_response = await mcp_client.call_tool("get_activities") |
| 138 | + assert activities_response.is_error is False |
| 139 | + activities_data = json.loads(activities_response.content[0].text) |
| 140 | + |
| 141 | + # Get the first activity ID |
| 142 | + activity_id = str(activities_data.get("activityId")) |
| 143 | + assert activity_id != "None" |
| 144 | + |
| 145 | + # Test activity details with real ID |
| 146 | + details_response = await mcp_client.call_tool("get_activity_details", {"activity_id": activity_id}) |
| 147 | + assert details_response.is_error is False |
| 148 | + assert details_response.content[0].type == "text" |
| 149 | + details_data = json.loads(details_response.content[0].text) |
| 150 | + assert isinstance(details_data, dict) |
| 151 | + |
| 152 | + # Test activity splits with real ID |
| 153 | + splits_response = await mcp_client.call_tool("get_activity_splits", {"activity_id": activity_id}) |
| 154 | + assert splits_response.is_error is False |
| 155 | + assert splits_response.content[0].type == "text" |
| 156 | + splits_data = json.loads(splits_response.content[0].text) |
| 157 | + assert isinstance(splits_data, (dict, list)) |
| 158 | + |
| 159 | + # Test activity weather with real ID |
| 160 | + weather_response = await mcp_client.call_tool("get_activity_weather", {"activity_id": activity_id}) |
| 161 | + assert weather_response.is_error is False |
| 162 | + assert weather_response.content[0].type == "text" |
| 163 | + weather_data = json.loads(weather_response.content[0].text) |
| 164 | + assert isinstance(weather_data, dict) |
| 165 | + |
| 166 | +async def test_get_body_composition(mcp_client: Client): |
| 167 | + response = await mcp_client.call_tool("get_body_composition") |
| 168 | + assert response.is_error is False |
| 169 | + assert response.content[0].type == "text" |
| 170 | + data = json.loads(response.content[0].text) |
| 171 | + assert isinstance(data, dict) |
| 172 | + |
| 173 | +async def test_get_respiration_data(mcp_client: Client): |
| 174 | + response = await mcp_client.call_tool("get_respiration_data", {"date": "2024-01-15"}) |
| 175 | + assert response.is_error is False |
| 176 | + assert response.content[0].type == "text" |
| 177 | + data = json.loads(response.content[0].text) |
| 178 | + assert isinstance(data, (dict, list)) |
| 179 | + |
| 180 | +async def test_get_spo2_data(mcp_client: Client): |
| 181 | + response = await mcp_client.call_tool("get_spo2_data", {"date": "2024-01-15"}) |
| 182 | + assert response.is_error is False |
| 183 | + assert response.content[0].type == "text" |
| 184 | + data = json.loads(response.content[0].text) |
| 185 | + assert isinstance(data, (dict, list)) |
| 186 | + |
| 187 | +async def test_get_blood_pressure(mcp_client: Client): |
| 188 | + response = await mcp_client.call_tool("get_blood_pressure", {"date": "2024-01-15"}) |
| 189 | + assert response.is_error is False |
| 190 | + assert response.content[0].type == "text" |
| 191 | + data = json.loads(response.content[0].text) |
| 192 | + assert isinstance(data, (dict, list)) |
| 193 | + |
| 194 | +async def test_get_devices(mcp_client: Client): |
| 195 | + response = await mcp_client.call_tool("get_devices") |
| 196 | + assert response.is_error is False |
| 197 | + assert response.content[0].type == "text" |
| 198 | + data = json.loads(response.content[0].text) |
| 199 | + assert isinstance(data, (dict, list)) |
| 200 | + |
| 201 | +async def test_get_device_settings(mcp_client: Client): |
| 202 | + response = await mcp_client.call_tool("get_device_settings", {"device_id": "123456789"}) |
| 203 | + assert response.is_error is False |
| 204 | + assert response.content[0].type == "text" |
| 205 | + data = json.loads(response.content[0].text) |
| 206 | + assert isinstance(data, dict) |
| 207 | + |
| 208 | +async def test_get_gear(mcp_client: Client): |
| 209 | + response = await mcp_client.call_tool("get_gear") |
| 210 | + assert response.is_error is False |
| 211 | + assert response.content[0].type == "text" |
| 212 | + data = json.loads(response.content[0].text) |
| 213 | + assert isinstance(data, (dict, list)) |
| 214 | + |
| 215 | +async def test_get_gear_stats(mcp_client: Client): |
| 216 | + response = await mcp_client.call_tool("get_gear_stats", {"gear_uuid": "12345678-1234-1234-1234-123456789012"}) |
| 217 | + assert response.is_error is False |
| 218 | + assert response.content[0].type == "text" |
| 219 | + data = json.loads(response.content[0].text) |
| 220 | + assert isinstance(data, dict) |
| 221 | + |
| 222 | +async def test_get_connectapi_endpoint(mcp_client: Client): |
| 223 | + response = await mcp_client.call_tool("get_connectapi_endpoint", {"endpoint": "test/endpoint"}) |
| 224 | + assert response.is_error is False |
| 225 | + assert response.content[0].type == "text" |
| 226 | + data = json.loads(response.content[0].text) |
| 227 | + assert isinstance(data, (dict, list)) |
| 228 | + |
| 229 | +async def test_monthly_activity_summary(mcp_client: Client): |
| 230 | + response = await mcp_client.call_tool("monthly_activity_summary", {"month": 1, "year": 2024}) |
| 231 | + assert response.is_error is False |
| 232 | + assert response.content[0].type == "text" |
| 233 | + data = json.loads(response.content[0].text) |
| 234 | + assert isinstance(data, (dict, list)) |
16 | 235 |
|
| 236 | +async def test_snapshot(mcp_client: Client): |
| 237 | + response = await mcp_client.call_tool("snapshot", {"from_date": "2024-01-01", "to_date": "2024-01-31"}) |
17 | 238 | assert response.is_error is False |
18 | 239 | assert response.content[0].type == "text" |
19 | | - assert UserProfile(**profile_data) |
| 240 | + data = json.loads(response.content[0].text) |
| 241 | + assert isinstance(data, (dict, list)) |
0 commit comments