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 | from unittest import TestCase |
| 8 | |
| 9 | from data_models.transform_for_magma import bandwidth, gps_tr181 |
| 10 | from exceptions import ConfigurationError |
| 11 | |
| 12 | |
| 13 | class TransformForMagmaTests(TestCase): |
| 14 | def test_gps_tr181(self) -> None: |
| 15 | # Negative longitude |
| 16 | inp = '-122150583' |
| 17 | out = gps_tr181(inp) |
| 18 | expected = '-122.150583' |
| 19 | self.assertEqual(out, expected, 'Should convert negative longitude') |
| 20 | |
| 21 | inp = '122150583' |
| 22 | out = gps_tr181(inp) |
| 23 | expected = '122.150583' |
| 24 | self.assertEqual(out, expected, 'Should convert positive longitude') |
| 25 | |
| 26 | inp = '0' |
| 27 | out = gps_tr181(inp) |
| 28 | expected = '0.0' |
| 29 | self.assertEqual(out, expected, 'Should leave zero as zero') |
| 30 | |
| 31 | def test_bandwidth(self) -> None: |
| 32 | inp = 'n6' |
| 33 | out = bandwidth(inp) |
| 34 | expected = 1.4 |
| 35 | self.assertEqual(out, expected, 'Should convert RBs') |
| 36 | |
| 37 | inp = 1.4 |
| 38 | out = bandwidth(inp) |
| 39 | expected = 1.4 |
| 40 | self.assertEqual(out, expected, 'Should accept MHz') |
| 41 | |
| 42 | with self.assertRaises(ConfigurationError): |
| 43 | inp = 'asdf' |
| 44 | bandwidth(inp) |
| 45 | |
| 46 | with self.assertRaises(ConfigurationError): |
| 47 | inp = 1234 |
| 48 | bandwidth(inp) |