def testAnalysisIsNeededForCrashedAnalysisWithForce(self):
        master_name = 'm'
        builder_name = 'b 1'
        build_number = 123
        step_name = 's'
        test_name = 't'
        self._CreateAndSaveMasterFlakeAnalysis(master_name,
                                               builder_name,
                                               build_number,
                                               step_name,
                                               test_name,
                                               status=analysis_status.ERROR)

        mocked_now = datetime(2017, 05, 01, 10, 10, 10)
        self.MockUTCNow(mocked_now)

        test = TestInfo(master_name, builder_name, build_number, step_name,
                        test_name)
        need_analysis, analysis = initialize_flake_pipeline._NeedANewAnalysis(
            test,
            test,
            None,
            user_email='*****@*****.**',
            allow_new_analysis=True,
            force=True)

        self.assertTrue(need_analysis)
        self.assertIsNotNone(analysis)
        self.assertFalse(analysis.triggering_user_email_obscured)
        self.assertEqual(mocked_now, analysis.request_time)
        self.assertTrue(analysis.version_number > 1)
  def testAnalysisIsNotNeededWhenNoneExistsAndNotAllowedToSchedule(self):
    test = TestInfo('m', 'b 1', 123, 's', 't')
    need_analysis, analysis = initialize_flake_pipeline._NeedANewAnalysis(
        test, test, None, allow_new_analysis=False)

    self.assertFalse(need_analysis)
    self.assertIsNone(analysis)
    def testAnalysisIsNotNeededWhenNoneExistsAndNotAllowedToSchedule(self):
        master_name = 'm'
        builder_name = 'b 1'
        build_number = 123
        step_name = 's'
        test_name = 't'

        test = TestInfo(master_name, builder_name, build_number, step_name,
                        test_name)
        need_analysis, analysis = initialize_flake_pipeline._NeedANewAnalysis(
            test, test, None, allow_new_analysis=False)

        self.assertFalse(need_analysis)
        self.assertIsNone(analysis)
  def testAnalysisIsNeededWhenNoneExistsAndAllowedToSchedule(self):
    mocked_now = datetime(2017, 05, 01, 10, 10, 10)
    self.MockUTCNow(mocked_now)

    test = TestInfo('m', 'b 1', 123, 's', 't')
    flake = Flake.Create('chromium', 's', 't', 'label')
    need_analysis, analysis = initialize_flake_pipeline._NeedANewAnalysis(
        test,
        test,
        flake.key,
        None,
        user_email='*****@*****.**',
        allow_new_analysis=True)

    self.assertTrue(need_analysis)
    self.assertIsNotNone(analysis)
    self.assertEqual(flake.key, analysis.flake_key)
    self.assertFalse(analysis.triggering_user_email_obscured)
    self.assertEqual(mocked_now, analysis.request_time)
  def testAnalysisIsNeededForCompletedAnalysisWithForce(self):
    master_name = 'm'
    builder_name = 'b 1'
    build_number = 123
    step_name = 's'
    test_name = 't'
    flake = Flake.Create('chromium', step_name, test_name, 'l')
    analysis = _CreateAndSaveMasterFlakeAnalysis(
        master_name,
        builder_name,
        build_number,
        step_name,
        test_name,
        status=analysis_status.COMPLETED)
    analysis.flake_key = flake.key
    data_point = DataPoint()
    data_point.pass_rate = .5
    data_point.build_number = 100
    analysis.data_points.append(data_point)
    analysis.put()

    mocked_now = datetime(2017, 05, 01, 10, 10, 10)
    self.MockUTCNow(mocked_now)

    test = TestInfo(master_name, builder_name, build_number, step_name,
                    test_name)
    need_analysis, analysis = initialize_flake_pipeline._NeedANewAnalysis(
        test,
        test,
        flake.key,
        None,
        user_email='*****@*****.**',
        allow_new_analysis=True,
        force=True)

    self.assertTrue(need_analysis)
    self.assertIsNotNone(analysis)
    self.assertFalse(analysis.triggering_user_email_obscured)
    self.assertEqual(mocked_now, analysis.request_time)
    self.assertEqual(analysis.version_number, 2)
    self.assertEqual([], analysis.data_points)
    def testAnalysisIsNotNeededForIncompletedAnalysis(self):
        master_name = 'm'
        builder_name = 'b 1'
        build_number = 123
        step_name = 's'
        test_name = 't'
        for status in [analysis_status.RUNNING, analysis_status.PENDING]:
            self._CreateAndSaveMasterFlakeAnalysis(master_name,
                                                   builder_name,
                                                   build_number,
                                                   step_name,
                                                   test_name,
                                                   status=status)

            test = TestInfo(master_name, builder_name, build_number, step_name,
                            test_name)
            need_analysis, analysis = initialize_flake_pipeline._NeedANewAnalysis(
                test, test, None, allow_new_analysis=True, force=True)

            self.assertFalse(need_analysis)
            self.assertIsNotNone(analysis)
    def testAnalysisIsNeededWhenNoneExistsAndAllowedToSchedule(self):
        master_name = 'm'
        builder_name = 'b 1'
        build_number = 123
        step_name = 's'
        test_name = 't'

        mocked_now = datetime(2017, 05, 01, 10, 10, 10)
        self.MockUTCNow(mocked_now)

        test = TestInfo(master_name, builder_name, build_number, step_name,
                        test_name)
        need_analysis, analysis = initialize_flake_pipeline._NeedANewAnalysis(
            test,
            test,
            None,
            user_email='*****@*****.**',
            allow_new_analysis=True)

        self.assertTrue(need_analysis)
        self.assertIsNotNone(analysis)
        self.assertFalse(analysis.triggering_user_email_obscured)
        self.assertEqual(mocked_now, analysis.request_time)