test: implement unit tests for knowledge-space api logic #63#65
test: implement unit tests for knowledge-space api logic #63#65ulekarsiddhant0-boop wants to merge 1 commit intoINCF:mainfrom
Conversation
|
Nice work on the KS API tests @ulekarsiddhant0-boop! These complement my PR #64 well — my tests cover the API endpoints (health, chat, session reset) while yours cover the internal KS API logic. One suggestion: it might be cleaner to place the tests inside |
|
Tests are real and correctly mock external APIs. Two issues: the tests are placed in the wrong location (should be under backend/tests/ not root tests/), and the PR adds a backend/init.py which changes the module structure and can break existing imports. Only 3 tests covering 2 functions is also quite minimal for a test suite PR. Please fix the directory structure, remove the init.py unless necessary, add more coverage, and reopen. |

This PR addresses Issue #63 by implementing a comprehensive testing suite for the KnowledgeSpace API backend. It ensures that the data retrieval and formatting logic are reliable and handles edge cases appropriately.
Key Changes was :
1]Testing Infrastructure: Added init.py files to the backend/ and tests/ directories to enable standard Python module discovery.
2]API Mocking: Utilized pytest-mock to simulate external API responses from api.knowledge-space.org. This allows tests to run without an internet connection and prevents hitting rate limits.
3]Data Validation: Added unit tests for format_datasets_list and list_datasources to verify that JSON responses are correctly parsed into human-readable strings.
4]Edge Case Handling: Added a specific test case for empty search results to ensure the system returns a graceful "No datasets found" message rather than crashing.
Verification Results:
I have verified the changes locally using the following command:
python -m pytest tests/Result: 3 passed in 0.14s