1 # Copyright 2015 The Chromium OS 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 unittest 6 7 import common 8 from autotest_lib.frontend import setup_django_lite_environment 9 from autotest_lib.frontend.afe import rpc_interface 10 from autotest_lib.server import site_utils 11 from autotest_lib.server.cros.dynamic_suite import tools 12 13 14 class SiteUtilsUnittests(unittest.TestCase): 15 """Test functions in site_utils.py 16 """ 17 18 def testParseJobName(self): 19 """Test method parse_job_name. 20 """ 21 trybot_paladin_build = 'trybot-lumpy-paladin/R27-3837.0.0-b123' 22 trybot_release_build = 'trybot-lumpy-release/R27-3837.0.0-b456' 23 release_build = 'lumpy-release/R27-3837.0.0' 24 paladin_build = 'lumpy-paladin/R27-3878.0.0-rc7' 25 brillo_build = 'git_mnc-brillo-dev/lumpy-eng/1234' 26 chrome_pfq_build = 'lumpy-chrome-pfq/R27-3837.0.0' 27 chromium_pfq_build = 'lumpy-chromium-pfq/R27-3837.0.0' 28 29 builds = [trybot_paladin_build, trybot_release_build, release_build, 30 paladin_build, brillo_build, chrome_pfq_build, 31 chromium_pfq_build] 32 test_name = 'login_LoginSuccess' 33 board = 'lumpy' 34 suite = 'bvt' 35 for build in builds: 36 expected_info = {'board': board, 37 'suite': suite, 38 'build': build} 39 build_parts = build.split('/') 40 if len(build_parts) == 2: 41 expected_info['build_version'] = build_parts[1] 42 else: 43 expected_info['build_version'] = build_parts[2] 44 suite_job_name = ('%s-%s' % 45 (build, rpc_interface.canonicalize_suite_name(suite))) 46 info = site_utils.parse_job_name(suite_job_name) 47 self.assertEqual(info, expected_info, '%s failed to be parsed to ' 48 '%s' % (suite_job_name, expected_info)) 49 test_job_name = tools.create_job_name(build, suite, test_name) 50 info = site_utils.parse_job_name(test_job_name) 51 self.assertEqual(info, expected_info, '%s failed to be parsed to ' 52 '%s' % (test_job_name, expected_info)) 53 54 55 def test_board_labels_allowed(self): 56 """Test method board_labels_allowed.""" 57 boards = ['board:name'] 58 self.assertEquals(True, site_utils.board_labels_allowed(boards)) 59 boards = ['board:name', 'board:another'] 60 self.assertEquals(False, site_utils.board_labels_allowed(boards)) 61 boards = ['board:name-1', 'board:name-2'] 62 self.assertEquals(True, site_utils.board_labels_allowed(boards)) 63 boards = ['board:name-1', 'board:another-2'] 64 self.assertEquals(True, site_utils.board_labels_allowed(boards)) 65 boards = ['board:name', 'board:another-1'] 66 self.assertEquals(False, site_utils.board_labels_allowed(boards)) 67 68 69 if __name__ == '__main__': 70 unittest.main() 71