Dan Shi | 70647ca | 2015-07-16 22:52:35 -0700 | [diff] [blame] | 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 |
Dan Shi | 70647ca | 2015-07-16 22:52:35 -0700 | [diff] [blame] | 9 | from autotest_lib.server import site_utils |
| 10 | from autotest_lib.server.cros.dynamic_suite import tools |
Xixuan Wu | e3e362f | 2018-04-26 16:34:28 -0700 | [diff] [blame] | 11 | from autotest_lib.server.cros.dynamic_suite import suite_common |
Dan Shi | 70647ca | 2015-07-16 22:52:35 -0700 | [diff] [blame] | 12 | |
| 13 | |
| 14 | class SiteUtilsUnittests(unittest.TestCase): |
Richard Barnette | 6e99120 | 2018-04-16 17:37:55 -0700 | [diff] [blame] | 15 | """Test functions in site_utils.py""" |
Dan Shi | 70647ca | 2015-07-16 22:52:35 -0700 | [diff] [blame] | 16 | |
| 17 | def testParseJobName(self): |
| 18 | """Test method parse_job_name. |
| 19 | """ |
| 20 | trybot_paladin_build = 'trybot-lumpy-paladin/R27-3837.0.0-b123' |
| 21 | trybot_release_build = 'trybot-lumpy-release/R27-3837.0.0-b456' |
| 22 | release_build = 'lumpy-release/R27-3837.0.0' |
| 23 | paladin_build = 'lumpy-paladin/R27-3878.0.0-rc7' |
Dan Shi | ef31f03 | 2016-05-13 15:51:39 -0700 | [diff] [blame] | 24 | brillo_build = 'git_mnc-brillo-dev/lumpy-eng/1234' |
Dan Shi | e02810d | 2016-08-25 09:44:57 -0700 | [diff] [blame] | 25 | chrome_pfq_build = 'lumpy-chrome-pfq/R27-3837.0.0' |
| 26 | chromium_pfq_build = 'lumpy-chromium-pfq/R27-3837.0.0' |
Dan Shi | 70647ca | 2015-07-16 22:52:35 -0700 | [diff] [blame] | 27 | |
| 28 | builds = [trybot_paladin_build, trybot_release_build, release_build, |
Dan Shi | e02810d | 2016-08-25 09:44:57 -0700 | [diff] [blame] | 29 | paladin_build, brillo_build, chrome_pfq_build, |
| 30 | chromium_pfq_build] |
Dan Shi | 70647ca | 2015-07-16 22:52:35 -0700 | [diff] [blame] | 31 | test_name = 'login_LoginSuccess' |
| 32 | board = 'lumpy' |
| 33 | suite = 'bvt' |
| 34 | for build in builds: |
| 35 | expected_info = {'board': board, |
| 36 | 'suite': suite, |
Dan Shi | ef31f03 | 2016-05-13 15:51:39 -0700 | [diff] [blame] | 37 | 'build': build} |
| 38 | build_parts = build.split('/') |
| 39 | if len(build_parts) == 2: |
| 40 | expected_info['build_version'] = build_parts[1] |
| 41 | else: |
| 42 | expected_info['build_version'] = build_parts[2] |
Dan Shi | 70647ca | 2015-07-16 22:52:35 -0700 | [diff] [blame] | 43 | suite_job_name = ('%s-%s' % |
Xixuan Wu | e3e362f | 2018-04-26 16:34:28 -0700 | [diff] [blame] | 44 | (build, suite_common.canonicalize_suite_name(suite))) |
Dan Shi | 70647ca | 2015-07-16 22:52:35 -0700 | [diff] [blame] | 45 | info = site_utils.parse_job_name(suite_job_name) |
| 46 | self.assertEqual(info, expected_info, '%s failed to be parsed to ' |
| 47 | '%s' % (suite_job_name, expected_info)) |
| 48 | test_job_name = tools.create_job_name(build, suite, test_name) |
| 49 | info = site_utils.parse_job_name(test_job_name) |
| 50 | self.assertEqual(info, expected_info, '%s failed to be parsed to ' |
| 51 | '%s' % (test_job_name, expected_info)) |
| 52 | |
| 53 | |
Dan Shi | 70647ca | 2015-07-16 22:52:35 -0700 | [diff] [blame] | 54 | if __name__ == '__main__': |
| 55 | unittest.main() |