From 0d822df89a214f2c43fb490ec5d00c5f26e573a8 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 27 Nov 2023 13:28:36 +0300 Subject: [PATCH] Add more tests --- .../service/test_unit_analyzer_service.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/test/unit/service/test_unit_analyzer_service.py b/test/unit/service/test_unit_analyzer_service.py index d42706d1..b667fce7 100644 --- a/test/unit/service/test_unit_analyzer_service.py +++ b/test/unit/service/test_unit_analyzer_service.py @@ -40,24 +40,28 @@ def get_empty_bool_query(): @pytest.mark.parametrize( - 'previous_launch_id, launch_mode, expected_query', + 'previous_launch_id, launch_mode, suggest, expected_query', [ - (2, 'LAUNCH_NAME', DEFAULT_LAUNCH_NAME_SEARCH), - (2, 'CURRENT_AND_THE_SAME_NAME', DEFAULT_LAUNCH_NAME_SEARCH), - (2, 'CURRENT_LAUNCH', {'must': [{'term': {'launch_id': {'value': DEFAULT_LAUNCH_ID}}}], 'should': []}), - (2, 'PREVIOUS_LAUNCH', {'must': [{'term': {'launch_id': {'value': 2}}}], 'should': []}), - (None, 'PREVIOUS_LAUNCH', {'must': [], 'should': []}), - ('3', 'PREVIOUS_LAUNCH', {'must': [{'term': {'launch_id': {'value': 3}}}], 'should': []}), - (2, None, {'must': [], 'should': [{'term': {'launch_name': {'value': DEFAULT_LAUNCH_NAME, - 'boost': DEFAULT_BOOST_LAUNCH}}}]}) + (2, 'LAUNCH_NAME', False, DEFAULT_LAUNCH_NAME_SEARCH), + (2, 'CURRENT_AND_THE_SAME_NAME', False, DEFAULT_LAUNCH_NAME_SEARCH), + (2, 'CURRENT_LAUNCH', False, {'must': [{'term': {'launch_id': {'value': DEFAULT_LAUNCH_ID}}}], 'should': []}), + (2, 'CURRENT_LAUNCH', True, {'must': [], 'should': [{'term': {'launch_id': { + 'value': DEFAULT_LAUNCH_ID, 'boost': DEFAULT_BOOST_LAUNCH}}}]}), + (2, 'PREVIOUS_LAUNCH', False, {'must': [{'term': {'launch_id': {'value': 2}}}], 'should': []}), + (None, 'PREVIOUS_LAUNCH', False, {'must': [], 'should': []}), + ('3', 'PREVIOUS_LAUNCH', False, {'must': [{'term': {'launch_id': {'value': 3}}}], 'should': []}), + ('3', 'PREVIOUS_LAUNCH', True, {'must': [], 'should': [{'term': {'launch_id': { + 'value': 3, 'boost': DEFAULT_BOOST_LAUNCH}}}]}), + (2, None, False, {'must': [], 'should': [{'term': {'launch_name': { + 'value': DEFAULT_LAUNCH_NAME, 'boost': DEFAULT_BOOST_LAUNCH}}}]}) ] ) -def test_add_constraints_for_launches_into_query(previous_launch_id, launch_mode, expected_query): +def test_add_constraints_for_launches_into_query(previous_launch_id, launch_mode, suggest, expected_query): launch = mock.Mock() launch.launchId = DEFAULT_LAUNCH_ID launch.previousLaunchId = previous_launch_id launch.launchName = DEFAULT_LAUNCH_NAME launch.analyzerConfig.analyzerMode = launch_mode analyzer = AnalyzerService(None, DEFAULT_SEARCH_CONFIG) - result = analyzer.add_constraints_for_launches_into_query(get_empty_bool_query(), launch) + result = analyzer.add_constraints_for_launches_into_query(get_empty_bool_query(), launch, suggest=suggest) assert result['query']['bool'] == expected_query