blob: e813354acb463671eb9bba143560c117bfc2ce48 [file] [log] [blame]
Wei-Yu Chen49950b92021-11-08 19:19:18 +08001"""
2Copyright 2020 The Magma Authors.
3
4This source code is licensed under the BSD-style license found in the
5LICENSE file in the root directory of this source tree.
6
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12"""
13
14# pylint: disable=protected-access
15
16from unittest import TestCase
17
18from data_models.data_model_parameters import ParameterName
19from devices.baicells import BaicellsTrDataModel
20
21
22class BaicellsTrDataModelTest(TestCase):
23 """
24 Tests for BaicellsTrDataModel
25 """
26
27 def test_is_parameter_present(self):
28 data_model = BaicellsTrDataModel()
29 with self.assertRaises(KeyError):
30 data_model.is_parameter_present(ParameterName.GPS_LONG)
31
32 result = data_model.is_parameter_present(ParameterName.DEVICE)
33 self.assertTrue(result, "Should have the device parameter")
34
35 def test_get_parameter(self):
36 param_info =\
37 BaicellsTrDataModel.get_parameter(ParameterName.GPS_STATUS)
38 self.assertIsNotNone(
39 param_info,
40 'Cannot get parameter info on %s' % ParameterName.GPS_STATUS,
41 )
42 path = param_info.path
43 expected_path = 'Device.DeviceInfo.X_BAICELLS_COM_GPS_Status'
44 self.assertEqual(
45 path,
46 expected_path,
47 'Path for parameter %s has incorrect value' %
48 ParameterName.GPS_STATUS,
49 )
50
51 def test_get_num_plmns(self):
52 n_plmns = BaicellsTrDataModel.get_num_plmns()
53 expected_n_plmns = 6
54 self.assertEqual(n_plmns, expected_n_plmns, 'Incorrect # of PLMNs')
55
56 def test_get_parameter_names(self):
57 name_list = BaicellsTrDataModel.get_parameter_names()
58
59 # Check that some random parameter names we expect are there
60 self.assertIn(
61 ParameterName.MME_STATUS, name_list,
62 'Should have %s in parameter name list' %
63 ParameterName.MME_STATUS,
64 )
65 self.assertIn(
66 ParameterName.DUPLEX_MODE_CAPABILITY, name_list,
67 'Should have %s in parameter name list' %
68 ParameterName.DUPLEX_MODE_CAPABILITY,
69 )
70 self.assertIn(
71 ParameterName.EARFCNUL, name_list,
72 'Should have %s in parameter name list' %
73 ParameterName.EARFCNUL,
74 )
75
76 # Check that some other parameter names are missing
77 self.assertNotIn(
78 ParameterName.PLMN, name_list,
79 'Should not have %s in parameter name list' %
80 ParameterName.PLMN,
81 )
82 self.assertNotIn(
83 ParameterName.PLMN_N % 1, name_list,
84 'Should not have %s in parameter name list' %
85 ParameterName.PLMN_N % 1,
86 )
87
88 def test_get_numbered_param_names(self):
89 name_list = list(BaicellsTrDataModel.get_numbered_param_names().keys())
90
91 # Check that unnumbered parameters are missing
92 self.assertNotIn(
93 ParameterName.EARFCNDL, name_list,
94 'Should not have %s in parameter name list' %
95 ParameterName.EARFCNDL,
96 )
97 self.assertNotIn(
98 ParameterName.MME_PORT, name_list,
99 'Should not have %s in parameter name list' %
100 ParameterName.MME_PORT,
101 )
102 self.assertNotIn(
103 ParameterName.PERIODIC_INFORM_ENABLE, name_list,
104 'Should not have %s in parameter name list' %
105 ParameterName.PERIODIC_INFORM_ENABLE,
106 )
107
108 # Check that some numbered parameters are present
109 self.assertIn(
110 ParameterName.PLMN_N % 1, name_list,
111 'Should have %s in parameter name list' %
112 ParameterName.PLMN_N % 1,
113 )
114 self.assertIn(
115 ParameterName.PLMN_N % 6, name_list,
116 'Should have %s in parameter name list' %
117 ParameterName.PLMN_N % 6,
118 )
119
120 def test_transform_for_magma(self):
121 gps_lat = str(10 * 1000000)
122 gps_lat_magma = BaicellsTrDataModel.transform_for_magma(
123 ParameterName.GPS_LAT, gps_lat,
124 )
125 expected = str(10.0)
126 self.assertEqual(gps_lat_magma, expected)
127
128 def test_transform_for_enb(self):
129 dl_bandwidth = 15
130 dl_bandwidth_enb = BaicellsTrDataModel.transform_for_enb(
131 ParameterName.DL_BANDWIDTH, dl_bandwidth,
132 )
133 expected = 'n75'
134 self.assertEqual(
135 dl_bandwidth_enb, expected,
136 'Transform for enb returning incorrect value',
137 )