1# Lint as: python2, python3
2# Copyright 2019 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import six.moves.configparser
7import io
8import unittest
9
10import common
11from autotest_lib.server.cros import ap_config
12
13
14class APTestCase(unittest.TestCase):
15    def test_not_rpm_managed(self):
16        conf = _parse_config_from_string("""
17[test_bss]
18rpm_managed = False
19rpm_hostname = chromeos3-row2-rack3-rpm1
20rpm_outlet = .A15""")
21        ap = ap_config.AP('test_bss', conf)
22        self.assertIsNone(ap.get_rpm_unit())
23
24
25    def test_rpm_managed(self):
26        conf = _parse_config_from_string("""
27[test_bss]
28rpm_managed = True
29rpm_hostname = chromeos3-row2-rack3-rpm1
30rpm_outlet = .A15""")
31        ap = ap_config.AP('test_bss', conf)
32        rpm_unit = ap.get_rpm_unit()
33        self.assertIsNotNone(rpm_unit)
34        self.assertEqual('chromeos3-row2-rack3-rpm1', rpm_unit.hostname)
35        self.assertEqual('.A15', rpm_unit.outlet)
36
37    def test_get_ap_list_returns_non_empty(self):
38        self.assertGreater(len(ap_config.get_ap_list()), 0)
39
40
41def _parse_config_from_string(conf):
42    parser = six.moves.configparser.RawConfigParser()
43    parser.readfp(io.BytesIO(conf))
44    return parser
45
46
47if __name__ == '__main__':
48    unittest.main()