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
5import unittest
6
7import common
8from autotest_lib.frontend import setup_django_lite_environment
9from autotest_lib.server import site_utils
10from autotest_lib.server.cros.dynamic_suite import tools
11from autotest_lib.server.cros.dynamic_suite import suite_common
12
13
14class SiteUtilsUnittests(unittest.TestCase):
15    """Test functions in site_utils.py"""
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'
24        brillo_build = 'git_mnc-brillo-dev/lumpy-eng/1234'
25        chrome_pfq_build = 'lumpy-chrome-pfq/R27-3837.0.0'
26        chromium_pfq_build = 'lumpy-chromium-pfq/R27-3837.0.0'
27
28        builds = [trybot_paladin_build, trybot_release_build, release_build,
29                  paladin_build, brillo_build, chrome_pfq_build,
30                  chromium_pfq_build]
31        test_name = 'login_LoginSuccess'
32        board = 'lumpy'
33        suite = 'bvt'
34        for build in builds:
35            expected_info = {'board': board,
36                             'suite': suite,
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]
43            suite_job_name = ('%s-%s' %
44                    (build, suite_common.canonicalize_suite_name(suite)))
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
54if __name__ == '__main__':
55    unittest.main()
56