Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import unittest |
| 16 | from mock import patch, call, Mock, PropertyMock |
| 17 | from helpers import Helpers |
| 18 | |
| 19 | class TestHelpers(unittest.TestCase): |
| 20 | |
| 21 | def setUp(self): |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 22 | # Create a mock service instance |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 23 | o = Mock() |
| 24 | o.voltha_url = "voltha_url" |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 25 | o.voltha_port = 1234 |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 26 | o.voltha_user = "voltha_user" |
| 27 | o.voltha_pass = "voltha_pass" |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 28 | o.onos_voltha_url = "onos_voltha_url" |
| 29 | o.onos_voltha_port = 4321 |
| 30 | o.onos_voltha_user = "onos_voltha_user" |
| 31 | o.onos_voltha_pass = "onos_voltha_pass" |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 32 | |
| 33 | self.o = o |
| 34 | |
| 35 | def test_format_url(self): |
| 36 | url = Helpers.format_url("onf.com") |
| 37 | self.assertEqual(url, "http://onf.com") |
| 38 | url = Helpers.format_url("http://onf.com") |
| 39 | self.assertEqual(url, "http://onf.com") |
| 40 | |
| 41 | def test_get_voltha_info(self): |
| 42 | voltha_dict = Helpers.get_voltha_info(self.o) |
| 43 | |
| 44 | self.assertEqual(voltha_dict["url"], "http://voltha_url") |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 45 | self.assertEqual(voltha_dict["port"], 1234) |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 46 | self.assertEqual(voltha_dict["user"], "voltha_user") |
| 47 | self.assertEqual(voltha_dict["pass"], "voltha_pass") |
| 48 | |
| 49 | def test_get_onos_info(self): |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 50 | onos_voltha_dict = Helpers.get_onos_voltha_info(self.o) |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 51 | |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 52 | self.assertEqual(onos_voltha_dict["url"], "http://onos_voltha_url") |
| 53 | self.assertEqual(onos_voltha_dict["port"], 4321) |
| 54 | self.assertEqual(onos_voltha_dict["user"], "onos_voltha_user") |
| 55 | self.assertEqual(onos_voltha_dict["pass"], "onos_voltha_pass") |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 56 | |
| 57 | def test_datapath_id_to_hex(self): |
| 58 | hex = Helpers.datapath_id_to_hex(55334486016) |
| 59 | self.assertEqual(hex, "0000000ce2314000") |
| 60 | |
| 61 | hex = Helpers.datapath_id_to_hex("55334486016") |
| 62 | self.assertEqual(hex, "0000000ce2314000") |
| 63 | |
| 64 | if __name__ == "__main__": |
| 65 | unittest.main() |