Skip to content

Comments

test: add unit test suite for backend API endpoints (#63)#64

Open
SandeepChauhan00 wants to merge 1 commit intoINCF:mainfrom
SandeepChauhan00:test/add-backend-unit-tests
Open

test: add unit test suite for backend API endpoints (#63)#64
SandeepChauhan00 wants to merge 1 commit intoINCF:mainfrom
SandeepChauhan00:test/add-backend-unit-tests

Conversation

@SandeepChauhan00
Copy link

Summary

Adds the first unit test suite for the backend API, covering all existing endpoints with 28 tests. This establishes the testing foundation for the project.

Closes #63

What's Added

  • backend/tests/__init__.py — test package marker
  • backend/tests/conftest.py — shared fixtures with mocked heavy dependencies (torch, vertexai, google-cloud, sentence-transformers) so tests run fast without GPU or cloud credentials
  • backend/tests/test_health.py — 15 tests covering /, /health, and /api/health
  • backend/tests/test_query.py — 13 tests covering /api/chat, /api/session/reset, and unknown routes
  • Updated pyproject.toml with [tool.pytest.ini_options] configuration

Test Results

All 28 tests pass on Python 3.14:

backend/tests/test_health.py::TestRootEndpoint::test_root_returns_200 PASSED
backend/tests/test_health.py::TestRootEndpoint::test_root_contains_message PASSED
backend/tests/test_health.py::TestRootEndpoint::test_root_contains_version PASSED
backend/tests/test_health.py::TestHealthEndpoint::test_health_returns_200 PASSED
backend/tests/test_health.py::TestHealthEndpoint::test_health_status_is_healthy PASSED
backend/tests/test_health.py::TestHealthEndpoint::test_health_contains_timestamp PASSED
backend/tests/test_health.py::TestHealthEndpoint::test_health_contains_service_name PASSED
backend/tests/test_health.py::TestHealthEndpoint::test_health_contains_version PASSED
backend/tests/test_health.py::TestApiHealthEndpoint::test_api_health_returns_200 PASSED
backend/tests/test_health.py::TestApiHealthEndpoint::test_api_health_status_is_healthy PASSED
backend/tests/test_health.py::TestApiHealthEndpoint::test_api_health_contains_components PASSED
backend/tests/test_health.py::TestApiHealthEndpoint::test_api_health_components_have_expected_keys PASSED
backend/tests/test_health.py::TestApiHealthEndpoint::test_api_health_keyword_search_always_enabled PASSED
backend/tests/test_health.py::TestApiHealthEndpoint::test_api_health_contains_timestamp PASSED
backend/tests/test_health.py::TestApiHealthEndpoint::test_api_health_contains_version PASSED
backend/tests/test_query.py::TestChatEndpoint::test_chat_endpoint_exists PASSED
backend/tests/test_query.py::TestChatEndpoint::test_chat_returns_response_field PASSED
backend/tests/test_query.py::TestChatEndpoint::test_chat_returns_metadata PASSED
backend/tests/test_query.py::TestChatEndpoint::test_chat_metadata_contains_process_time PASSED
backend/tests/test_query.py::TestChatEndpoint::test_chat_metadata_contains_session_id PASSED
backend/tests/test_query.py::TestChatEndpoint::test_chat_with_custom_session_id PASSED
backend/tests/test_query.py::TestChatEndpoint::test_chat_missing_query_returns_422 PASSED
backend/tests/test_query.py::TestChatEndpoint::test_chat_get_method_not_allowed PASSED
backend/tests/test_query.py::TestSessionResetEndpoint::test_reset_endpoint_exists PASSED
backend/tests/test_query.py::TestSessionResetEndpoint::test_reset_returns_ok_status PASSED
backend/tests/test_query.py::TestSessionResetEndpoint::test_reset_returns_session_id PASSED
backend/tests/test_query.py::TestUnknownRoutes::test_unknown_route_returns_404 PASSED
backend/tests/test_query.py::TestUnknownRoutes::test_unknown_api_route_returns_404 PASSED

28 passed, 18 warnings in 0.62s

Endpoint Coverage

Endpoint Tests Status
GET / 3 ✅ All pass
GET /health 5 ✅ All pass
GET /api/health 7 ✅ All pass
POST /api/chat 8 ✅ All pass
POST /api/session/reset 3 ✅ All pass
Unknown routes (404) 2 ✅ All pass

How to Run

pip install pytest httpx
python -m pytest backend/tests/ -v


##Design Decisions
Mocked dependencies: torch, vertexai, google-cloud, and sentence-transformers are mocked in conftest.py so tests run instantly without GPU, cloud credentials, or heavy installs
FakeAssistant: The NeuroscienceAssistant is replaced with a lightweight fake that returns predictable responses, isolating API layer tests from LLM behavior
Pytest configuration: Added [tool.pytest.ini_options] to pyproject.toml rather than a separate pytest.ini to keep config centralized

@SandeepChauhan00
Copy link
Author

PR submitted: #64

28 tests covering all backend endpoints — all passing on Python 3.14. Heavy dependencies are mocked so tests run instantly without GPU or cloud credentials.

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.

[Testing] Add unit test suite for backend API endpoints and core modules

1 participant