def test_random_run(self):
     print("Boost model folder: ", self.boost_model_folder)
     decision_maker = BoostingDecisionMaker(self.boost_model_folder)
     test_data_size = 5
     random_data = np.random.rand(test_data_size,
                                  len(decision_maker.get_feature_ids()))
     result, result_probability = decision_maker.predict(random_data)
     result.should.have.length_of(test_data_size)
     result_probability.should.have.length_of(test_data_size)
 def test_full_data_check(self):
     print("Boost model folder: ", self.boost_model_folder)
     decision_maker = BoostingDecisionMaker(self.boost_model_folder)
     boost_model_results = self.get_fixture(self.boost_model_results)
     tests = [
         {
             "elastic_results":
             [(self.get_fixture(self.log_message),
               self.get_fixture(self.one_hit_search_rs_explained))],
             "config":
             TestBoostingModel.get_default_config(),
         },
         {
             "elastic_results":
             [(self.get_fixture(self.log_message),
               self.get_fixture(self.two_hits_search_rs_explained))],
             "config":
             TestBoostingModel.get_default_config(),
         },
         {
             "elastic_results":
             [(self.get_fixture(self.log_message),
               self.get_fixture(self.two_hits_search_rs_explained)),
              (self.get_fixture(self.log_message),
               self.get_fixture(self.one_hit_search_rs_explained))],
             "config":
             TestBoostingModel.get_default_config(),
         },
         {
             "elastic_results":
             [(self.get_fixture(self.log_message_only_small_logs),
               self.get_fixture(self.two_hits_search_rs_small_logs))],
             "config":
             TestBoostingModel.get_default_config(),
         },
     ]
     for idx, test in enumerate(tests):
         _boosting_featurizer = BoostingFeaturizer(
             test["elastic_results"], test["config"],
             decision_maker.get_feature_ids())
         with sure.ensure('Error in the test case number: {0}', idx):
             gathered_data, issue_type_names = _boosting_featurizer.gather_features_info(
             )
             gathered_data.should.equal(boost_model_results[str(idx)][0],
                                        epsilon=self.epsilon)
             predict_label, predict_probability = decision_maker.predict(
                 gathered_data)
             predict_label.tolist().should.equal(
                 boost_model_results[str(idx)][1], epsilon=self.epsilon)
             predict_probability.tolist().should.equal(
                 boost_model_results[str(idx)][2], epsilon=self.epsilon)
    def test_suggest_items(self):
        """Test suggesting test items"""
        tests = [
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/1",
                        "status": HTTPStatus.OK,
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(testItemId=1,
                                            uniqueId="341",
                                            testCaseHash=123,
                                            launchId=1,
                                            launchName="Launch",
                                            project=1,
                                            logs=[]),
                "expected_result": [],
                "boost_predict": ([], [])
            },
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/2",
                        "status": HTTPStatus.NOT_FOUND,
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(testItemId=1,
                                            uniqueId="341",
                                            testCaseHash=123,
                                            launchId=1,
                                            launchName="Launch",
                                            project=2,
                                            logs=[
                                                launch_objects.Log(
                                                    logId=1,
                                                    message="error found",
                                                    logLevel=40000)
                                            ]),
                "expected_result": [],
                "boost_predict": ([], [])
            },
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/1",
                        "status": HTTPStatus.OK,
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(testItemId=1,
                                            uniqueId="341",
                                            testCaseHash=123,
                                            launchId=1,
                                            launchName="Launch",
                                            project=1,
                                            logs=[
                                                launch_objects.Log(
                                                    logId=1,
                                                    message=" ",
                                                    logLevel=40000)
                                            ]),
                "expected_result": [],
                "boost_predict": ([], [])
            },
            {
                "test_calls": [{
                    "method": httpretty.GET,
                    "uri": "/1",
                    "status": HTTPStatus.OK,
                }, {
                    "method": httpretty.GET,
                    "uri": "/1/_search",
                    "status": HTTPStatus.OK,
                    "content_type": "application/json",
                    "rq": utils.get_fixture(self.search_rq_first),
                    "rs": utils.get_fixture(self.no_hits_search_rs),
                }, {
                    "method": httpretty.GET,
                    "uri": "/1/_search",
                    "status": HTTPStatus.OK,
                    "content_type": "application/json",
                    "rq": utils.get_fixture(self.search_rq_second),
                    "rs": utils.get_fixture(self.no_hits_search_rs),
                }, {
                    "method": httpretty.GET,
                    "uri": "/1/_search",
                    "status": HTTPStatus.OK,
                    "content_type": "application/json",
                    "rq": utils.get_fixture(self.search_rq_third),
                    "rs": utils.get_fixture(self.no_hits_search_rs),
                }],
                "test_item_info":
                launch_objects.TestItemInfo(**utils.get_fixture(
                    self.suggest_test_item_info_w_logs, to_json=True)),
                "expected_result": [],
                "boost_predict": ([], [])
            },
            {
                "test_calls": [{
                    "method": httpretty.GET,
                    "uri": "/1",
                    "status": HTTPStatus.OK,
                }, {
                    "method": httpretty.GET,
                    "uri": "/1/_search",
                    "status": HTTPStatus.OK,
                    "content_type": "application/json",
                    "rq": utils.get_fixture(self.search_rq_first),
                    "rs": utils.get_fixture(self.no_hits_search_rs),
                }, {
                    "method": httpretty.GET,
                    "uri": "/1/_search",
                    "status": HTTPStatus.OK,
                    "content_type": "application/json",
                    "rq": utils.get_fixture(self.search_rq_second),
                    "rs": utils.get_fixture(self.no_hits_search_rs),
                }, {
                    "method": httpretty.GET,
                    "uri": "/1/_search",
                    "status": HTTPStatus.OK,
                    "content_type": "application/json",
                    "rq": utils.get_fixture(self.search_rq_third),
                    "rs": utils.get_fixture(self.no_hits_search_rs),
                }],
                "test_item_info":
                launch_objects.TestItemInfo(**utils.get_fixture(
                    self.suggest_test_item_info_w_logs, to_json=True)),
                "expected_result": [],
                "boost_predict": ([], [])
            },
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/1",
                        "status": HTTPStatus.OK,
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_first),
                        "rs": utils.get_fixture(self.no_hits_search_rs),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_second),
                        "rs": utils.get_fixture(self.one_hit_search_rs),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_third),
                        "rs": utils.get_fixture(self.one_hit_search_rs),
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(**utils.get_fixture(
                    self.suggest_test_item_info_w_logs, to_json=True)),
                "expected_result": [
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='AB001',
                        relevantItem=1,
                        relevantLogId=1,
                        matchScore=80.0,
                        esScore=10.0,
                        esPosition=0,
                        modelFeatureNames='0',
                        modelFeatureValues='1.0',
                        modelInfo='',
                        resultPosition=0,
                        usedLogLines=-1,
                        minShouldMatch=80)
                ],
                "boost_predict": ([1], [[0.2, 0.8]])
            },
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/1",
                        "status": HTTPStatus.OK,
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_first),
                        "rs": utils.get_fixture(self.one_hit_search_rs),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_second),
                        "rs": utils.get_fixture(self.one_hit_search_rs),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_third),
                        "rs": utils.get_fixture(self.one_hit_search_rs),
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(**utils.get_fixture(
                    self.suggest_test_item_info_w_logs, to_json=True)),
                "expected_result": [
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='AB001',
                        relevantItem=1,
                        relevantLogId=1,
                        matchScore=70.0,
                        esScore=10.0,
                        esPosition=0,
                        modelFeatureNames='0',
                        modelFeatureValues='1.0',
                        modelInfo='',
                        resultPosition=0,
                        usedLogLines=-1,
                        minShouldMatch=80)
                ],
                "boost_predict": ([1], [[0.3, 0.7]])
            },
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/1",
                        "status": HTTPStatus.OK,
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_first),
                        "rs": utils.get_fixture(self.one_hit_search_rs),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_second),
                        "rs": utils.get_fixture(self.two_hits_search_rs),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_third),
                        "rs": utils.get_fixture(self.two_hits_search_rs),
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(**utils.get_fixture(
                    self.suggest_test_item_info_w_logs, to_json=True)),
                "expected_result": [
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='AB001',
                        relevantItem=1,
                        relevantLogId=1,
                        matchScore=70.0,
                        esScore=15.0,
                        esPosition=0,
                        modelFeatureNames='0',
                        modelFeatureValues='1.0',
                        modelInfo='',
                        resultPosition=0,
                        usedLogLines=-1,
                        minShouldMatch=80)
                ],
                "boost_predict": ([1, 0], [[0.3, 0.7], [0.9, 0.1]])
            },
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/1",
                        "status": HTTPStatus.OK,
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_first),
                        "rs": utils.get_fixture(self.one_hit_search_rs),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_second),
                        "rs": utils.get_fixture(self.two_hits_search_rs),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_third),
                        "rs": utils.get_fixture(self.no_hits_search_rs),
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(**utils.get_fixture(
                    self.suggest_test_item_info_w_logs, to_json=True)),
                "expected_result": [
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='AB001',
                        relevantItem=1,
                        relevantLogId=1,
                        matchScore=70.0,
                        esScore=15.0,
                        esPosition=0,
                        modelFeatureNames='0',
                        modelFeatureValues='1.0',
                        modelInfo='',
                        resultPosition=0,
                        usedLogLines=-1,
                        minShouldMatch=80),
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='PB001',
                        relevantItem=2,
                        relevantLogId=2,
                        matchScore=45.0,
                        esScore=10.0,
                        esPosition=1,
                        modelFeatureNames='0',
                        modelFeatureValues='0.67',
                        modelInfo='',
                        resultPosition=1,
                        usedLogLines=-1,
                        minShouldMatch=80)
                ],
                "boost_predict": ([1, 0], [[0.3, 0.7], [0.55, 0.45]])
            },
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/1",
                        "status": HTTPStatus.OK,
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_first),
                        "rs": utils.get_fixture(self.two_hits_search_rs),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_second),
                        "rs": utils.get_fixture(self.three_hits_search_rs),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_third),
                        "rs": utils.get_fixture(self.no_hits_search_rs),
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(**utils.get_fixture(
                    self.suggest_test_item_info_w_logs, to_json=True)),
                "expected_result": [
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='PB001',
                        relevantItem=3,
                        relevantLogId=3,
                        matchScore=80.0,
                        esScore=10.0,
                        esPosition=2,
                        modelFeatureNames='0',
                        modelFeatureValues='0.67',
                        modelInfo='',
                        resultPosition=0,
                        usedLogLines=-1,
                        minShouldMatch=80),
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='AB001',
                        relevantItem=1,
                        relevantLogId=1,
                        matchScore=70.0,
                        esScore=15.0,
                        esPosition=0,
                        modelFeatureNames='0',
                        modelFeatureValues='1.0',
                        modelInfo='',
                        resultPosition=1,
                        usedLogLines=-1,
                        minShouldMatch=80),
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='PB001',
                        relevantItem=2,
                        relevantLogId=2,
                        matchScore=45.0,
                        esScore=10.0,
                        esPosition=1,
                        modelFeatureNames='0',
                        modelFeatureValues='0.67',
                        modelInfo='',
                        resultPosition=2,
                        usedLogLines=-1,
                        minShouldMatch=80)
                ],
                "boost_predict": ([1, 0, 1], [[0.3, 0.7], [0.55, 0.45],
                                              [0.2, 0.8]])
            },
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/1",
                        "status": HTTPStatus.OK,
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_first),
                        "rs": utils.get_fixture(self.two_hits_search_rs),
                    },
                    {
                        "method":
                        httpretty.GET,
                        "uri":
                        "/1/_search",
                        "status":
                        HTTPStatus.OK,
                        "content_type":
                        "application/json",
                        "rq":
                        utils.get_fixture(self.search_rq_second),
                        "rs":
                        utils.get_fixture(
                            self.three_hits_search_rs_with_duplicate),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_third),
                        "rs": utils.get_fixture(self.no_hits_search_rs),
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(**utils.get_fixture(
                    self.suggest_test_item_info_w_logs, to_json=True)),
                "expected_result": [
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='AB001',
                        relevantItem=3,
                        relevantLogId=3,
                        matchScore=70.0,
                        esScore=15.0,
                        esPosition=0,
                        modelFeatureNames='0',
                        modelFeatureValues='1.0',
                        modelInfo='',
                        resultPosition=0,
                        usedLogLines=-1,
                        minShouldMatch=80),
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='AB001',
                        relevantItem=1,
                        relevantLogId=1,
                        matchScore=70.0,
                        esScore=15.0,
                        esPosition=0,
                        modelFeatureNames='0',
                        modelFeatureValues='1.0',
                        modelInfo='',
                        resultPosition=1,
                        usedLogLines=-1,
                        minShouldMatch=80),
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=178,
                        issueType='PB001',
                        relevantItem=2,
                        relevantLogId=2,
                        matchScore=70.0,
                        esScore=10.0,
                        esPosition=1,
                        modelFeatureNames='0',
                        modelFeatureValues='0.67',
                        modelInfo='',
                        resultPosition=2,
                        usedLogLines=-1,
                        minShouldMatch=80)
                ],
                "boost_predict": ([1, 1, 1], [[0.3, 0.7], [0.3, 0.7],
                                              [0.3, 0.7]])
            },
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/1",
                        "status": HTTPStatus.OK,
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_merged_first),
                        "rs": utils.get_fixture(self.one_hit_search_rs_merged),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_merged_second),
                        "rs": utils.get_fixture(self.one_hit_search_rs_merged),
                    },
                    {
                        "method": httpretty.GET,
                        "uri": "/1/_search",
                        "status": HTTPStatus.OK,
                        "content_type": "application/json",
                        "rq": utils.get_fixture(self.search_rq_merged_third),
                        "rs": utils.get_fixture(self.one_hit_search_rs_merged),
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(**utils.get_fixture(
                    self.suggest_test_item_info_w_merged_logs, to_json=True)),
                "expected_result": [
                    launch_objects.SuggestAnalysisResult(
                        testItem=123,
                        testItemLogId=-1,
                        issueType='AB001',
                        relevantItem=1,
                        relevantLogId=1,
                        matchScore=90.0,
                        esScore=10.0,
                        esPosition=0,
                        modelFeatureNames='0',
                        modelFeatureValues='1.0',
                        modelInfo='',
                        resultPosition=0,
                        usedLogLines=-1,
                        minShouldMatch=80)
                ],
                "boost_predict": ([1], [[0.1, 0.9]])
            },
            {
                "test_calls": [
                    {
                        "method": httpretty.GET,
                        "uri": "/1",
                        "status": HTTPStatus.OK,
                    },
                    {
                        "method":
                        httpretty.GET,
                        "uri":
                        "/1/_search",
                        "status":
                        HTTPStatus.OK,
                        "content_type":
                        "application/json",
                        "rq":
                        utils.get_fixture(self.search_rq_merged_first),
                        "rs":
                        utils.get_fixture(self.one_hit_search_rs_merged_wrong),
                    },
                    {
                        "method":
                        httpretty.GET,
                        "uri":
                        "/1/_search",
                        "status":
                        HTTPStatus.OK,
                        "content_type":
                        "application/json",
                        "rq":
                        utils.get_fixture(self.search_rq_merged_second),
                        "rs":
                        utils.get_fixture(self.one_hit_search_rs_merged_wrong),
                    },
                    {
                        "method":
                        httpretty.GET,
                        "uri":
                        "/1/_search",
                        "status":
                        HTTPStatus.OK,
                        "content_type":
                        "application/json",
                        "rq":
                        utils.get_fixture(self.search_rq_merged_third),
                        "rs":
                        utils.get_fixture(self.one_hit_search_rs_merged_wrong),
                    },
                ],
                "test_item_info":
                launch_objects.TestItemInfo(**utils.get_fixture(
                    self.suggest_test_item_info_w_merged_logs, to_json=True)),
                "expected_result": [],
                "boost_predict": ([], [])
            },
        ]

        for idx, test in enumerate(tests):
            with sure.ensure('Error in the test case number: {0}', idx):
                self._start_server(test["test_calls"])
                config = self.get_default_search_config()
                suggest_service = SuggestService(app_config=self.app_config,
                                                 search_cfg=config)
                _boosting_decision_maker = BoostingDecisionMaker()
                _boosting_decision_maker.get_feature_ids = MagicMock(
                    return_value=[0])
                _boosting_decision_maker.predict = MagicMock(
                    return_value=test["boost_predict"])
                suggest_service.suggest_decision_maker = _boosting_decision_maker
                response = suggest_service.suggest_items(
                    test["test_item_info"])

                response.should.have.length_of(len(test["expected_result"]))
                for real_resp, expected_resp in zip(response,
                                                    test["expected_result"]):
                    real_resp.should.equal(expected_resp)

                TestSuggestService.shutdown_server(test["test_calls"])
Beispiel #4
0
    def test_analyze_logs(self):
        """Test analyzing logs"""
        tests = [
            {
                "test_calls":          [{"method":         httpretty.GET,
                                         "uri":            "/1",
                                         "status":         HTTPStatus.OK,
                                         }, ],
                "index_rq":            utils.get_fixture(self.launch_wo_test_items),
                "expected_count":      0,
                "expected_issue_type": "",
                "boost_predict":       ([], [])
            },
            {
                "test_calls":          [{"method":         httpretty.GET,
                                         "uri":            "/1",
                                         "status":         HTTPStatus.OK,
                                         }, ],
                "index_rq":            utils.get_fixture(
                    self.launch_w_test_items_wo_logs),
                "expected_count":      0,
                "expected_issue_type": "",
                "boost_predict":       ([], [])
            },
            {
                "test_calls":          [{"method":         httpretty.GET,
                                         "uri":            "/2",
                                         "status":         HTTPStatus.OK,
                                         }, ],
                "index_rq":            utils.get_fixture(
                    self.launch_w_test_items_w_empty_logs),
                "expected_count":      0,
                "expected_issue_type": "",
                "boost_predict":       ([], [])
            },
            {
                "test_calls":     [{"method":         httpretty.GET,
                                    "uri":            "/2",
                                    "status":         HTTPStatus.OK,
                                    }, ],
                "msearch_results": [utils.get_fixture(self.no_hits_search_rs, to_json=True),
                                    utils.get_fixture(self.no_hits_search_rs, to_json=True)],
                "index_rq":       utils.get_fixture(self.launch_w_test_items_w_logs),
                "expected_count":      0,
                "expected_issue_type": "",
                "boost_predict":       ([], [])
            },
            {
                "test_calls":     [{"method":         httpretty.GET,
                                    "uri":            "/2",
                                    "status":         HTTPStatus.NOT_FOUND,
                                    }, ],
                "index_rq":       utils.get_fixture(self.launch_w_test_items_w_logs),
                "expected_count":      0,
                "expected_issue_type": "",
                "boost_predict":       ([], [])
            },
            {
                "test_calls":     [{"method":         httpretty.GET,
                                    "uri":            "/2",
                                    "status":         HTTPStatus.OK,
                                    }],
                "msearch_results": [utils.get_fixture(self.no_hits_search_rs, to_json=True),
                                    utils.get_fixture(self.one_hit_search_rs, to_json=True)],
                "index_rq":       utils.get_fixture(self.launch_w_test_items_w_logs),
                "expected_count": 1,
                "expected_issue_type": "AB001",
                "boost_predict":       ([1], [[0.2, 0.8]])
            },
            {
                "test_calls":     [{"method":         httpretty.GET,
                                    "uri":            "/2",
                                    "status":         HTTPStatus.OK,
                                    }],
                "msearch_results": [utils.get_fixture(self.one_hit_search_rs, to_json=True),
                                    utils.get_fixture(self.two_hits_search_rs, to_json=True)],
                "index_rq":       utils.get_fixture(self.launch_w_test_items_w_logs),
                "expected_count": 1,
                "expected_issue_type": "AB001",
                "boost_predict":       ([1, 0], [[0.2, 0.8], [0.7, 0.3]])
            },
            {
                "test_calls":     [{"method":         httpretty.GET,
                                    "uri":            "/2",
                                    "status":         HTTPStatus.OK,
                                    }],
                "msearch_results": [utils.get_fixture(self.two_hits_search_rs, to_json=True),
                                    utils.get_fixture(self.three_hits_search_rs, to_json=True)],
                "index_rq":       utils.get_fixture(self.launch_w_test_items_w_logs),
                "expected_count": 1,
                "expected_issue_type": "AB001",
                "boost_predict":       ([1, 1], [[0.2, 0.8], [0.3, 0.7]])
            },
            {
                "test_calls":     [{"method":         httpretty.GET,
                                    "uri":            "/2",
                                    "status":         HTTPStatus.OK,
                                    }],
                "msearch_results": [utils.get_fixture(self.no_hits_search_rs, to_json=True),
                                    utils.get_fixture(self.three_hits_search_rs, to_json=True)],
                "index_rq":       utils.get_fixture(self.launch_w_test_items_w_logs),
                "expected_count": 1,
                "expected_issue_type": "PB001",
                "boost_predict":       ([0, 1], [[0.8, 0.2], [0.3, 0.7]])
            },
            {
                "test_calls":     [{"method":         httpretty.GET,
                                    "uri":            "/2",
                                    "status":         HTTPStatus.OK,
                                    }],
                "msearch_results": [utils.get_fixture(self.no_hits_search_rs, to_json=True),
                                    utils.get_fixture(self.three_hits_search_rs, to_json=True)],
                "index_rq":       utils.get_fixture(self.launch_w_test_items_w_logs),
                "expected_count": 1,
                "expected_issue_type": "AB001",
                "boost_predict":       ([1, 0], [[0.2, 0.8], [0.7, 0.3]])
            },
            {
                "test_calls":     [{"method":         httpretty.GET,
                                    "uri":            "/2",
                                    "status":         HTTPStatus.OK,
                                    }],
                "msearch_results": [utils.get_fixture(self.two_hits_search_rs, to_json=True)],
                "index_rq":       utils.get_fixture(
                    self.launch_w_test_items_w_logs_to_be_merged),
                "expected_count": 0,
                "expected_issue_type": "",
                "boost_predict":       ([], [])
            },
            {
                "test_calls":     [{"method":         httpretty.GET,
                                    "uri":            "/2",
                                    "status":         HTTPStatus.OK,
                                    }],
                "msearch_results": [
                    utils.get_fixture(self.no_hits_search_rs, to_json=True),
                    utils.get_fixture(self.three_hits_search_rs_with_one_unique_id, to_json=True)],
                "index_rq":       utils.get_fixture(
                    self.launch_w_test_items_w_logs),
                "expected_count": 1,
                "expected_issue_type": "AB001",
                "boost_predict":       ([1], [[0.2, 0.8]])
            }
        ]

        for idx, test in enumerate(tests):
            with sure.ensure('Error in the test case number: {0}', idx):
                self._start_server(test["test_calls"])
                config = self.get_default_search_config()
                analyzer_service = AutoAnalyzerService(app_config=self.app_config,
                                                       search_cfg=config)
                _boosting_decision_maker = BoostingDecisionMaker()
                _boosting_decision_maker.get_feature_ids = MagicMock(return_value=[0])
                _boosting_decision_maker.predict = MagicMock(return_value=test["boost_predict"])
                if "msearch_results" in test:
                    analyzer_service.es_client.es_client.msearch = MagicMock(
                        return_value={"responses": test["msearch_results"]})
                analyzer_service.boosting_decision_maker = _boosting_decision_maker

                launches = [launch_objects.Launch(**launch)
                            for launch in json.loads(test["index_rq"])]
                response = analyzer_service.analyze_logs(launches)

                response.should.have.length_of(test["expected_count"])

                if test["expected_issue_type"] != "":
                    test["expected_issue_type"].should.equal(response[0].issueType)

                if "expected_id" in test:
                    test["expected_id"].should.equal(response[0].relevantItem)

                TestAutoAnalyzerService.shutdown_server(test["test_calls"])