Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Nov 27, 2023
1 parent c224585 commit 0d822df
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/unit/service/test_unit_analyzer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0d822df

Please sign in to comment.