Spaces:
Running
Running
File size: 12,627 Bytes
dc3879e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
"""Integration tests for task listing via natural language chat.
[Task]: T023
[From]: specs/004-ai-chatbot/tasks.md
These tests verify that users can list and view their tasks through natural language
conversations with the AI assistant.
"""
import pytest
from uuid import uuid4
from datetime import datetime, timedelta
from sqlalchemy.ext.asyncio import AsyncSession
from models.message import Message
from models.conversation import Conversation
from models.task import Task
from core.database import get_db
@pytest.mark.asyncio
class TestChatTaskListing:
"""Test suite for natural language task listing via chat."""
async def test_list_all_tasks(
self,
async_session: AsyncSession,
test_user_id: uuid4
):
"""Test listing all tasks.
[From]: specs/004-ai-chatbot/spec.md - US2-AC1
User message: "What are my tasks?" or "Show me my tasks"
Expected: AI returns list of all tasks with completion status
"""
# Create conversation
conversation = Conversation(
id=uuid4(),
user_id=test_user_id,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
)
async_session.add(conversation)
await async_session.commit()
# Create some test tasks
tasks = [
Task(
id=uuid4(),
user_id=test_user_id,
title="Buy groceries",
completed=False,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
Task(
id=uuid4(),
user_id=test_user_id,
title="Finish report",
completed=True,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
Task(
id=uuid4(),
user_id=test_user_id,
title="Call client",
completed=False,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
]
for task in tasks:
async_session.add(task)
await async_session.commit()
# User sends message
user_message = Message(
id=uuid4(),
conversation_id=conversation.id,
user_id=test_user_id,
role="user",
content="What are my tasks?",
created_at=datetime.utcnow()
)
async_session.add(user_message)
await async_session.commit()
# TODO: After implementing list_tasks tool, verify:
# - AI responds with list of all 3 tasks
# - Each task shows title and completion status
# - Response is formatted clearly
# Placeholder assertion
assert len(tasks) == 3
assert sum(1 for t in tasks if t.completed) == 1
assert sum(1 for t in tasks if not t.completed) == 2
async def test_list_pending_tasks_only(
self,
async_session: AsyncSession,
test_user_id: uuid4
):
"""Test filtering tasks by completion status.
[From]: specs/004-ai-chatbot/spec.md - US2-AC2
User message: "Show me my pending tasks" or "What tasks are left?"
Expected: AI returns only incomplete tasks
"""
conversation = Conversation(
id=uuid4(),
user_id=test_user_id,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
)
async_session.add(conversation)
await async_session.commit()
# Create mix of completed and pending tasks
tasks = [
Task(
id=uuid4(),
user_id=test_user_id,
title="Pending task 1",
completed=False,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
Task(
id=uuid4(),
user_id=test_user_id,
title="Completed task",
completed=True,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
Task(
id=uuid4(),
user_id=test_user_id,
title="Pending task 2",
completed=False,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
]
for task in tasks:
async_session.add(task)
await async_session.commit()
user_message = Message(
id=uuid4(),
conversation_id=conversation.id,
user_id=test_user_id,
role="user",
content="Show me my pending tasks",
created_at=datetime.utcnow()
)
async_session.add(user_message)
await async_session.commit()
# TODO: After implementing list_tasks with filtering, verify:
# - AI responds with only 2 pending tasks
# - Completed task is not shown
# Placeholder assertion
pending_tasks = [t for t in tasks if not t.completed]
assert len(pending_tasks) == 2
async def test_list_completed_tasks(
self,
async_session: AsyncSession,
test_user_id: uuid4
):
"""Test listing completed tasks.
[From]: specs/004-ai-chatbot/spec.md - US2-AC3
User message: "What have I completed?" or "Show finished tasks"
Expected: AI returns only completed tasks
"""
conversation = Conversation(
id=uuid4(),
user_id=test_user_id,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
)
async_session.add(conversation)
await async_session.commit()
tasks = [
Task(
id=uuid4(),
user_id=test_user_id,
title="Done task 1",
completed=True,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
Task(
id=uuid4(),
user_id=test_user_id,
title="Pending task",
completed=False,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
Task(
id=uuid4(),
user_id=test_user_id,
title="Done task 2",
completed=True,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
]
for task in tasks:
async_session.add(task)
await async_session.commit()
user_message = Message(
id=uuid4(),
conversation_id=conversation.id,
user_id=test_user_id,
role="user",
content="What have I completed?",
created_at=datetime.utcnow()
)
async_session.add(user_message)
await async_session.commit()
# TODO: After implementing list_tasks with filtering, verify:
# - AI responds with only 2 completed tasks
# - Pending task is not shown
# Placeholder assertion
completed_tasks = [t for t in tasks if t.completed]
assert len(completed_tasks) == 2
async def test_empty_task_list(
self,
async_session: AsyncSession,
test_user_id: uuid4
):
"""Test listing tasks when user has none.
[From]: specs/004-ai-chatbot/spec.md - US2-AC4
User message: "What are my tasks?"
Expected: AI responds that there are no tasks, offers to help create one
"""
conversation = Conversation(
id=uuid4(),
user_id=test_user_id,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
)
async_session.add(conversation)
await async_session.commit()
# No tasks created
user_message = Message(
id=uuid4(),
conversation_id=conversation.id,
user_id=test_user_id,
role="user",
content="What are my tasks?",
created_at=datetime.utcnow()
)
async_session.add(user_message)
await async_session.commit()
# TODO: After implementing empty list handling (T026), verify:
# - AI responds with friendly message
# - AI offers to help create a task
# - No error or confusion
async def test_task_count_in_response(
self,
async_session: AsyncSession,
test_user_id: uuid4
):
"""Test that AI provides accurate task count.
[From]: specs/004-ai-chatbot/spec.md - US2-AC5
Scenario: User has 7 tasks, asks "How many tasks do I have?"
Expected: AI responds with accurate count
"""
conversation = Conversation(
id=uuid4(),
user_id=test_user_id,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
)
async_session.add(conversation)
await async_session.commit()
# Create 7 tasks
for i in range(7):
task = Task(
id=uuid4(),
user_id=test_user_id,
title=f"Task {i+1}",
completed=i < 3, # First 3 are completed
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
)
async_session.add(task)
await async_session.commit()
user_message = Message(
id=uuid4(),
conversation_id=conversation.id,
user_id=test_user_id,
role="user",
content="How many tasks do I have?",
created_at=datetime.utcnow()
)
async_session.add(user_message)
await async_session.commit()
# TODO: After implementation, verify:
# - AI responds with "You have 7 tasks"
# - Optionally breaks down: "3 completed, 4 pending"
async def test_task_listing_with_due_dates(
self,
async_session: AsyncSession,
test_user_id: uuid4
):
"""Test listing tasks with due date information.
[From]: specs/004-ai-chatbot/spec.md - US2-AC6
User message: "What tasks are due this week?"
Expected: AI filters by due date and shows matching tasks
"""
conversation = Conversation(
id=uuid4(),
user_id=test_user_id,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
)
async_session.add(conversation)
await async_session.commit()
today = datetime.utcnow()
tasks = [
Task(
id=uuid4(),
user_id=test_user_id,
title="Due today",
completed=False,
due_date=today.date(),
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
Task(
id=uuid4(),
user_id=test_user_id,
title="Due tomorrow",
completed=False,
due_date=(today + timedelta(days=1)).date(),
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
Task(
id=uuid4(),
user_id=test_user_id,
title="Due next week",
completed=False,
due_date=(today + timedelta(days=7)).date(),
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
Task(
id=uuid4(),
user_id=test_user_id,
title="No due date",
completed=False,
created_at=datetime.utcnow(),
updated_at=datetime.utcnow()
),
]
for task in tasks:
async_session.add(task)
await async_session.commit()
user_message = Message(
id=uuid4(),
conversation_id=conversation.id,
user_id=test_user_id,
role="user",
content="What tasks are due this week?",
created_at=datetime.utcnow()
)
async_session.add(user_message)
await async_session.commit()
# TODO: After implementing due date filtering, verify:
# - AI shows tasks due within 7 days
# - Includes due dates in response
|