Skip to content

Add unit tests for POST /index/message (Close #148)#203

Open
ciscokwiz wants to merge 2 commits into
codebestia:devfrom
ciscokwiz:unit-test
Open

Add unit tests for POST /index/message (Close #148)#203
ciscokwiz wants to merge 2 commits into
codebestia:devfrom
ciscokwiz:unit-test

Conversation

@ciscokwiz

Copy link
Copy Markdown

Summary

Adds 7 pytest unit tests for the POST /index/message endpoint in apps/ai_agent/main.py, covering all code paths including error handling and resource cleanup.

Closes #148

Tests

# Test What it covers
1 test_weaviate_connection_failure_returns_503 Connection exception → 503 response
2 test_creates_collection_if_missing Message collection auto-created when absent
3 test_inserts_new_message collection.data.insert called, replace not called
4 test_replaces_existing_message collection.data.replace called, insert not called
5 test_closes_weaviate_on_success client.close() called after successful request
6 test_closes_weaviate_on_error client.close() called in finally block on exception
7 test_missing_fields_returns_422 Pydantic validation returns 422 for empty body

Verification

All 7 tests pass:

tests/test_index.py::TestIndexMessage::test_weaviate_connection_failure_returns_503 PASSED
tests/test_index.py::TestIndexMessage::test_creates_collection_if_missing PASSED
tests/test_index.py::TestIndexMessage::test_inserts_new_message PASSED
tests/test_index.py::TestIndexMessage::test_replaces_existing_message PASSED
tests/test_index.py::TestIndexMessage::test_closes_weaviate_on_success PASSED
tests/test_index.py::TestIndexMessage::test_closes_weaviate_on_error PASSED
tests/test_index.py::TestIndexMessage::test_missing_fields_returns_422 PASSED

Notes

  • No new runtime dependencies added; pytest and httpx are required only as dev dependencies.
  • All Weaviate and OpenAI calls are mocked — no external services needed.
  • Each write branch (insert vs replace) tested independently with assert_called_once / assert_not_called.

codebestia and others added 2 commits June 24, 2026 15:54
Centralize admin check and update backend configuration
- 7 tests covering all paths: connection failure, collection creation, insert vs replace branching, close on success/error, and missing fields validation
- Closes codebestia#148
@drips-wave

drips-wave Bot commented Jun 25, 2026

Copy link
Copy Markdown

@ciscokwiz Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants