Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame^] | 1 | # 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 Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 5 | |
| 6 | # pylint: disable=protected-access |
| 7 | |
| 8 | from unittest import TestCase |
| 9 | |
| 10 | from data_models.data_model_parameters import ParameterName |
| 11 | from devices.baicells import BaicellsTrDataModel |
| 12 | |
| 13 | |
| 14 | class 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 | ) |