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 |
Matteo Scandolo | d44ca99 | 2018-05-17 15:02:10 -0700 | [diff] [blame] | 16 | |
| 17 | from mock import Mock |
| 18 | |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 19 | from helpers import Helpers |
| 20 | |
Matteo Scandolo | d44ca99 | 2018-05-17 15:02:10 -0700 | [diff] [blame] | 21 | |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 22 | class TestHelpers(unittest.TestCase): |
| 23 | |
| 24 | def setUp(self): |
Matteo Scandolo | 0d756f2 | 2019-06-10 14:55:55 -0700 | [diff] [blame] | 25 | |
| 26 | # create a mock ONOS Service |
| 27 | onos = Mock() |
| 28 | onos.name = "ONOS" |
Matteo Scandolo | 8202625 | 2019-06-20 12:11:45 -0700 | [diff] [blame] | 29 | onos.leaf_model.name = "ONOS" |
Matteo Scandolo | 0d756f2 | 2019-06-10 14:55:55 -0700 | [diff] [blame] | 30 | onos.leaf_model.rest_hostname = "onos_voltha_url" |
| 31 | onos.leaf_model.rest_port = 4321 |
| 32 | onos.leaf_model.rest_username = "onos_voltha_user" |
| 33 | onos.leaf_model.rest_password = "onos_voltha_pass" |
| 34 | |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 35 | # Create a mock service instance |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 36 | o = Mock() |
| 37 | o.voltha_url = "voltha_url" |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 38 | o.voltha_port = 1234 |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 39 | o.voltha_user = "voltha_user" |
| 40 | o.voltha_pass = "voltha_pass" |
Matteo Scandolo | 0d756f2 | 2019-06-10 14:55:55 -0700 | [diff] [blame] | 41 | |
| 42 | o.provider_services = [onos] |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 43 | |
| 44 | self.o = o |
| 45 | |
| 46 | def test_format_url(self): |
| 47 | url = Helpers.format_url("onf.com") |
| 48 | self.assertEqual(url, "http://onf.com") |
| 49 | url = Helpers.format_url("http://onf.com") |
| 50 | self.assertEqual(url, "http://onf.com") |
| 51 | |
Matteo Scandolo | 8202625 | 2019-06-20 12:11:45 -0700 | [diff] [blame] | 52 | def test_get_onos_service_name(self): |
| 53 | name = Helpers.get_onos_service_name(self.o) |
| 54 | self.assertEqual(name, "ONOS") |
| 55 | |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 56 | def test_get_voltha_info(self): |
| 57 | voltha_dict = Helpers.get_voltha_info(self.o) |
| 58 | |
| 59 | self.assertEqual(voltha_dict["url"], "http://voltha_url") |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 60 | self.assertEqual(voltha_dict["port"], 1234) |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 61 | self.assertEqual(voltha_dict["user"], "voltha_user") |
| 62 | self.assertEqual(voltha_dict["pass"], "voltha_pass") |
| 63 | |
| 64 | def test_get_onos_info(self): |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 65 | onos_voltha_dict = Helpers.get_onos_voltha_info(self.o) |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 66 | |
Luca Prete | ca974c8 | 2018-05-01 18:06:16 -0700 | [diff] [blame] | 67 | self.assertEqual(onos_voltha_dict["url"], "http://onos_voltha_url") |
| 68 | self.assertEqual(onos_voltha_dict["port"], 4321) |
| 69 | self.assertEqual(onos_voltha_dict["user"], "onos_voltha_user") |
| 70 | self.assertEqual(onos_voltha_dict["pass"], "onos_voltha_pass") |
Matteo Scandolo | f6337eb | 2018-04-05 15:58:37 -0700 | [diff] [blame] | 71 | |
| 72 | def test_datapath_id_to_hex(self): |
| 73 | hex = Helpers.datapath_id_to_hex(55334486016) |
| 74 | self.assertEqual(hex, "0000000ce2314000") |
| 75 | |
| 76 | hex = Helpers.datapath_id_to_hex("55334486016") |
| 77 | self.assertEqual(hex, "0000000ce2314000") |
| 78 | |
| 79 | if __name__ == "__main__": |
| 80 | unittest.main() |