Skip to content

Commit

Permalink
chore:add new search query test cases for complex AND/OR operators
Browse files Browse the repository at this point in the history
Introduce tests to validate multiple OR queries and mixed AND/OR operators. This ensures correct handling of compound search expressions and improves coverage for different search scenarios.
  • Loading branch information
hareshkainthdbt committed Nov 26, 2024
1 parent 27b9ac9 commit 53cc42e
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions orp/orp_search/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ def test_or_search_operator_query(self, mock_search_query):
# Assert the AND operation was applied
mock_query1.__or__.assert_called_once_with(mock_query2)

@patch("orp_search.utils.search.SearchQuery", autospec=True)
def test_multple_or_search_operator_query(self, mock_search_query):
# Mock SearchQuery instances
mock_query1 = MagicMock(name="MockQuery1")
mock_query2 = MagicMock(name="MockQuery2")
mock_query3 = MagicMock(name="MockQuery3")

# Configure the mock to return mock objects
mock_search_query.side_effect = [mock_query1, mock_query2, mock_query3]

# Call the function
_ = create_search_query("test OR trial OR error")

# Assert that SearchQuery was called with expected arguments
calls = [
call("test", search_type="plain"),
call("trial", search_type="plain"),
call("error", search_type="plain"),
]
mock_search_query.assert_has_calls(calls, any_order=False)

# Assert the AND operation was applied
mock_query1.__or__.assert_called_with(mock_query3)

@patch("orp_search.utils.search.SearchQuery", autospec=True)
def test_multiple_or_search_operator_query(self, mock_search_query):
# Mock SearchQuery instances
Expand Down Expand Up @@ -161,6 +185,42 @@ def test_phrase_search_query(self, mock_search_query):
)
self.assertEqual(result, mock_search_query.return_value)

@patch("orp_search.utils.search.SearchQuery", autospec=True)
def test_and_multiple_single_single_phrase_search_query(
self, mock_search_query
):
mock_query1 = MagicMock(name="MockQuery1") # word1
mock_query2 = MagicMock(name="MockQuery2") # word2
mock_query3 = MagicMock(name="MockQuery3") # "word3 word4"
mock_query4 = MagicMock(name="MockQuery4") # word5
mock_query5 = MagicMock(name="MockQuery5") # word6

# Configure the mock to return mock objects
mock_search_query.side_effect = [
mock_query1,
mock_query2,
mock_query3,
mock_query4,
mock_query5,
]

_ = create_search_query(
'word1 AND word2 AND "word3 word4" AND word5 word6'
)

# Assert that SearchQuery was called with expected arguments
calls = [
call("word1", search_type="plain"),
call("word2", search_type="plain"),
call("word3 word4", search_type="phrase"),
call("word5", search_type="plain"),
call("word6", search_type="plain"),
]
mock_search_query.assert_has_calls(calls, any_order=False)

# Assert the AND operation was applied
mock_query1.__and__.assert_called_with(mock_query5)


if __name__ == "__main__":
unittest.main()

0 comments on commit 53cc42e

Please sign in to comment.