Home | History | Annotate | Download | only in dashboard
      1 # Copyright 2016 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import json
      6 
      7 import webapp2
      8 import webtest
      9 
     10 from dashboard import post_bisect_results
     11 from dashboard import rietveld_service
     12 from dashboard import testing_common
     13 from dashboard.models import try_job
     14 
     15 _SAMPLE_BISECT_RESULTS_JSON = {
     16     'try_job_id': 6789,
     17     'bug_id': 4567,
     18     'status': 'completed',
     19     'bisect_bot': 'linux',
     20     'buildbot_log_url': '',
     21     'command': ('tools/perf/run_benchmark -v '
     22                 '--browser=release page_cycler.intl_ar_fa_he'),
     23     'metric': 'warm_times/page_load_time',
     24     'change': '',
     25     'score': 99.9,
     26     'good_revision': '306475',
     27     'bad_revision': '306478',
     28     'warnings': None,
     29     'aborted_reason': None,
     30     'culprit_data': {
     31         'subject': 'subject',
     32         'author': 'author',
     33         'email': 'author (at] email.com',
     34         'cl_date': '1/2/2015',
     35         'commit_info': 'commit_info',
     36         'revisions_links': [],
     37         'cl': '1235'
     38     },
     39     'revision_data': [
     40         {
     41             'revision_string': 'chromium@1234',
     42             'commit_hash': '1234123412341234123412341234123412341234',
     43             'depot_name': 'chromium',
     44             'mean_value': 70,
     45             'std_dev': 0,
     46             'values': [70, 70, 70],
     47             'result': 'good'
     48         }, {
     49             'revision_string': 'chromium@1235',
     50             'depot_name': 'chromium',
     51             'commit_hash': '1235123512351235123512351235123512351235',
     52             'mean_value': 80,
     53             'std_dev': 0,
     54             'values': [80, 80, 80],
     55             'result': 'bad'
     56         }
     57     ]
     58 }
     59 
     60 # Sample IP addresses to use in the tests below.
     61 _WHITELISTED_IP = '123.45.67.89'
     62 
     63 
     64 class PostBisectResultsTest(testing_common.TestCase):
     65 
     66   def setUp(self):
     67     super(PostBisectResultsTest, self).setUp()
     68     app = webapp2.WSGIApplication([
     69         ('/post_bisect_results',
     70          post_bisect_results.PostBisectResultsHandler)])
     71     self.testapp = webtest.TestApp(app)
     72     testing_common.SetIpWhitelist([_WHITELISTED_IP])
     73     self._AddRietveldConfig()
     74 
     75   def _AddRietveldConfig(self):
     76     """Adds a RietveldConfig entity to the datastore.
     77 
     78     This is used in order to get the Rietveld URL when requests are made to the
     79     handler in te tests below. In the real datastore, the RietveldConfig entity
     80     would contain credentials.
     81     """
     82     rietveld_service.RietveldConfig(
     83         id='default_rietveld_config',
     84         client_email='sullivan (at] email.com',
     85         service_account_key='Fake Account Key',
     86         server_url='https://test-rietveld.appspot.com',
     87         internal_server_url='https://test-rietveld.appspot.com').put()
     88 
     89   def testPost(self):
     90     job_key = try_job.TryJob(id=6789, rietveld_issue_id=200034).put()
     91     data_param = json.dumps(_SAMPLE_BISECT_RESULTS_JSON)
     92     self.testapp.post(
     93         '/post_bisect_results', {'data': data_param},
     94         extra_environ={'REMOTE_ADDR': _WHITELISTED_IP})
     95 
     96     job = job_key.get()
     97     self.assertEqual(6789, job.results_data['try_job_id'])
     98     self.assertEqual('completed', job.results_data['status'])
     99