Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comprehensive unit tests for search command #73 #145

Merged

Conversation

sambhavnoobcoder
Copy link
Contributor

This pull request introduces a new suite of unit tests for the search command functionality in the file search_command_test.py. These tests are designed to ensure the reliability and correctness of our search feature across various scenarios and search types.

Key additions and features:

  1. New test file: search_command_test.py
  2. Five comprehensive test cases covering different aspects of the search functionality
  3. Proper mocking of AssetsApi, SearchApi, and AssetsCommandsApi
  4. Verification of correct API calls, parameters, and output formatting
  5. Robust error handling checks

Detailed description of test cases:

  1. test_search_assets:
    This test case verifies the basic asset search functionality. It mocks the AssetsApi to return a predefined set of results (one exact match and one suggested match). The test ensures that the correct API is called with the right parameters, the results are properly processed, and the asset details are correctly printed.

  2. test_search_no_results:
    This test simulates a scenario where the search query returns no results. It verifies that the function handles this case gracefully, printing an appropriate "No matches found" message without raising any errors.

  3. test_invalid_search_type:
    This test checks the error handling for an invalid search type. It ensures that when an unsupported search type is provided, the function calls the show_error method with the correct error message.

  4. test_search_ncs:
    This test case focuses on the Neural Code Search (NCS) functionality. It mocks the SearchApi to return a sample result and verifies that the neural_code_search method is called with the correct query. It also checks that the results are properly processed and displayed.

  5. test_search_fts:
    Similar to the NCS test, this case tests the Full Text Search (FTS) functionality. It ensures that the full_text_search method of the SearchApi is called correctly and that the results are appropriately handled and displayed.

All tests are currently passing, providing confidence in the correct implementation of the search functionality across different search types and scenarios.

Testing:

  • Ran all tests using python -m unittest search_command_test.py
  • All 5 tests passed successfully

Results :
Screenshot 2024-07-18 at 6 21 37 PM

Conclusion :
This addition significantly improves our test coverage and will help maintain the integrity of the search functionality as we continue to develop and refine our application.

This commit introduces a new suite of unit tests for the search command functionality. We've created thorough test cases covering various aspects of the search feature, including tests for 'assets', 'ncs' (neural code search), and 'fts' (full text search) types. The test suite also includes scenarios for handling no results and invalid search types. 

Key features of these tests include:
- Proper mocking of AssetsApi, SearchApi, and AssetsCommandsApi
- Verification of correct API calls and parameters
- Validation of output formatting and error handling
- Coverage of different search types and edge cases

These tests ensure the robustness of the search command, providing a solid foundation for future development and maintenance. All tests are passing successfully, confirming the correct implementation of the search functionality across various use cases.
@Bishoy-at-pieces Bishoy-at-pieces linked an issue Jul 18, 2024 that may be closed by this pull request
@Bishoy-at-pieces
Copy link
Collaborator

It looks great well done!!

@Bishoy-at-pieces Bishoy-at-pieces merged commit cf4e6e6 into pieces-app:main Jul 22, 2024
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.

Add search test
2 participants