def testGetFlakeAnalysesResultsNotShowErrorAnalysis(self):
        analysis_2 = MasterFlakeAnalysis.Create('m', 'b', 12345, 's', 't')
        analysis_2.bug_id = 123
        analysis_2.status = analysis_status.ERROR
        analysis_2.put()

        self.assertEqual(([], {}),
                         flake_detection_utils._GetFlakeAnalysesResults(123))
    def testGetFlakeAnalysesResultsShowPendingAnalysis(self):
        analysis_1 = MasterFlakeAnalysis.Create('m', 'b', 12345, 's', 't')
        analysis_1.bug_id = 123
        analysis_1.put()

        self.assertEqual(([], {
            'status': 'Pending',
            'analysis_key': analysis_1.key.urlsafe()
        }), flake_detection_utils._GetFlakeAnalysesResults(123))
    def testGetFlakeAnalysesResultsFailedToGetCulprit(self):
        analysis = MasterFlakeAnalysis.Create('m', 'b', 12345, 's', 't')
        analysis.bug_id = 123
        analysis.culprit_urlsafe_key = 'culprit.key'
        analysis.status = analysis_status.COMPLETED
        analysis.put()

        self.assertEqual(([], {
            'status': 'Completed, no culprit found',
            'analysis_key': analysis.key.urlsafe()
        }), flake_detection_utils._GetFlakeAnalysesResults(123))
    def testGetFlakeAnalysesResultsShowRunningAnalysis(self):
        analysis_1 = MasterFlakeAnalysis.Create('m', 'b', 12345, 's', 't')
        analysis_1.bug_id = 123
        analysis_1.status = analysis_status.RUNNING
        analysis_1.put()

        analysis_2 = MasterFlakeAnalysis.Create('m', 'b', 12345, 's', 't')
        analysis_2.bug_id = 123
        analysis_2.status = analysis_status.ERROR
        analysis_2.put()

        self.assertEqual(([], {
            'status': 'Running',
            'analysis_key': analysis_1.key.urlsafe()
        }), flake_detection_utils._GetFlakeAnalysesResults(123))
 def testGetFlakeAnalysesResultsNoAnalyses(self):
     self.assertEqual(([], None),
                      flake_detection_utils._GetFlakeAnalysesResults(123))