github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/gubernator/pull_request_test.py (about)

     1  #!/usr/bin/env python
     2  
     3  # Copyright 2016 The Kubernetes Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  import unittest
    18  
    19  import pull_request
    20  
    21  
    22  def make(number, version, result, start_time=1000):
    23      started = None if version is None else {
    24          'timestamp': start_time, 'version': version}
    25      finished = result and {'result': result}
    26      return (number, started, finished)
    27  
    28  
    29  class TableTest(unittest.TestCase):
    30  
    31      def test_builds_to_table(self):
    32          jobs = {'J1': [make(4, 'v2', 'A', 9), make(3, 'v2', 'B', 10)],
    33                  'J2': [make(5, 'v1', 'C', 7), make(4, 'v1', 'D', 6)]}
    34          max_builds, headings, rows = pull_request.builds_to_table(jobs)
    35  
    36          self.assertEqual(max_builds, 4)
    37          self.assertEqual(headings, [('v2', 2, 9), ('v1', 2, 6)])
    38          self.assertEqual(rows, [('J1', [(4, 'A'), (3, 'B')]),
    39                                  ('J2', [None, None, (5, 'C'), (4, 'D')])])
    40  
    41      def test_builds_to_table_no_header(self):
    42          jobs = {'J': [make(5, None, 'A', 3), make(4, '', 'B', 2)]}
    43          self.assertEqual(pull_request.builds_to_table(jobs),
    44                           (0, [], [('J', [(5, 'A'), (4, 'B')])]))
    45  
    46      def test_pull_ref_commit(self):
    47          jobs = {'J1': [make(4, 'v2', 'A', 9)]}
    48          jobs['J1'][0][1]['pull'] = 'master:1234,35:abcd'
    49          _, headings, _ = pull_request.builds_to_table(jobs)
    50          self.assertEqual(headings, [('abcd', 1, 9)])