blob: 31f9c9e503e6c50c530db2d2d74f8674a95c38e6 [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# SPDX-FileCopyrightText: 2020 The Magma Authors.
2# SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org>
3#
4# SPDX-License-Identifier: BSD-3-Clause
Wei-Yu Chen49950b92021-11-08 19:19:18 +08005
6# pylint: disable=protected-access
7
8from unittest import TestCase
9
10from data_models.data_model_parameters import ParameterName
11from devices.baicells import BaicellsTrDataModel
12
13
14class BaicellsTrDataModelTest(TestCase):
15 """
16 Tests for BaicellsTrDataModel
17 """
18
19 def test_is_parameter_present(self):
20 data_model = BaicellsTrDataModel()
21 with self.assertRaises(KeyError):
22 data_model.is_parameter_present(ParameterName.GPS_LONG)
23
24 result = data_model.is_parameter_present(ParameterName.DEVICE)
25 self.assertTrue(result, "Should have the device parameter")
26
27 def test_get_parameter(self):
28 param_info =\
29 BaicellsTrDataModel.get_parameter(ParameterName.GPS_STATUS)
30 self.assertIsNotNone(
31 param_info,
32 'Cannot get parameter info on %s' % ParameterName.GPS_STATUS,
33 )
34 path = param_info.path
35 expected_path = 'Device.DeviceInfo.X_BAICELLS_COM_GPS_Status'
36 self.assertEqual(
37 path,
38 expected_path,
39 'Path for parameter %s has incorrect value' %
40 ParameterName.GPS_STATUS,
41 )
42
43 def test_get_num_plmns(self):
44 n_plmns = BaicellsTrDataModel.get_num_plmns()
45 expected_n_plmns = 6
46 self.assertEqual(n_plmns, expected_n_plmns, 'Incorrect # of PLMNs')
47
48 def test_get_parameter_names(self):
49 name_list = BaicellsTrDataModel.get_parameter_names()
50
51 # Check that some random parameter names we expect are there
52 self.assertIn(
53 ParameterName.MME_STATUS, name_list,
54 'Should have %s in parameter name list' %
55 ParameterName.MME_STATUS,
56 )
57 self.assertIn(
58 ParameterName.DUPLEX_MODE_CAPABILITY, name_list,
59 'Should have %s in parameter name list' %
60 ParameterName.DUPLEX_MODE_CAPABILITY,
61 )
62 self.assertIn(
63 ParameterName.EARFCNUL, name_list,
64 'Should have %s in parameter name list' %
65 ParameterName.EARFCNUL,
66 )
67
68 # Check that some other parameter names are missing
69 self.assertNotIn(
70 ParameterName.PLMN, name_list,
71 'Should not have %s in parameter name list' %
72 ParameterName.PLMN,
73 )
74 self.assertNotIn(
75 ParameterName.PLMN_N % 1, name_list,
76 'Should not have %s in parameter name list' %
77 ParameterName.PLMN_N % 1,
78 )
79
80 def test_get_numbered_param_names(self):
81 name_list = list(BaicellsTrDataModel.get_numbered_param_names().keys())
82
83 # Check that unnumbered parameters are missing
84 self.assertNotIn(
85 ParameterName.EARFCNDL, name_list,
86 'Should not have %s in parameter name list' %
87 ParameterName.EARFCNDL,
88 )
89 self.assertNotIn(
90 ParameterName.MME_PORT, name_list,
91 'Should not have %s in parameter name list' %
92 ParameterName.MME_PORT,
93 )
94 self.assertNotIn(
95 ParameterName.PERIODIC_INFORM_ENABLE, name_list,
96 'Should not have %s in parameter name list' %
97 ParameterName.PERIODIC_INFORM_ENABLE,
98 )
99
100 # Check that some numbered parameters are present
101 self.assertIn(
102 ParameterName.PLMN_N % 1, name_list,
103 'Should have %s in parameter name list' %
104 ParameterName.PLMN_N % 1,
105 )
106 self.assertIn(
107 ParameterName.PLMN_N % 6, name_list,
108 'Should have %s in parameter name list' %
109 ParameterName.PLMN_N % 6,
110 )
111
112 def test_transform_for_magma(self):
113 gps_lat = str(10 * 1000000)
114 gps_lat_magma = BaicellsTrDataModel.transform_for_magma(
115 ParameterName.GPS_LAT, gps_lat,
116 )
117 expected = str(10.0)
118 self.assertEqual(gps_lat_magma, expected)
119
120 def test_transform_for_enb(self):
121 dl_bandwidth = 15
122 dl_bandwidth_enb = BaicellsTrDataModel.transform_for_enb(
123 ParameterName.DL_BANDWIDTH, dl_bandwidth,
124 )
125 expected = 'n75'
126 self.assertEqual(
127 dl_bandwidth_enb, expected,
128 'Transform for enb returning incorrect value',
129 )