blob: a2b392dfedab70ee0b2a5eb559eac118e0c664d7 [file] [log] [blame]
Matteo Scandolof6337eb2018-04-05 15:58:37 -07001# 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
15import unittest
Matteo Scandolod44ca992018-05-17 15:02:10 -070016
17from mock import Mock
18
Matteo Scandolof6337eb2018-04-05 15:58:37 -070019from helpers import Helpers
20
Matteo Scandolod44ca992018-05-17 15:02:10 -070021
Matteo Scandolof6337eb2018-04-05 15:58:37 -070022class TestHelpers(unittest.TestCase):
23
24 def setUp(self):
Matteo Scandolo0d756f22019-06-10 14:55:55 -070025
26 # create a mock ONOS Service
27 onos = Mock()
28 onos.name = "ONOS"
29 onos.leaf_model.rest_hostname = "onos_voltha_url"
30 onos.leaf_model.rest_port = 4321
31 onos.leaf_model.rest_username = "onos_voltha_user"
32 onos.leaf_model.rest_password = "onos_voltha_pass"
33
Luca Preteca974c82018-05-01 18:06:16 -070034 # Create a mock service instance
Matteo Scandolof6337eb2018-04-05 15:58:37 -070035 o = Mock()
36 o.voltha_url = "voltha_url"
Luca Preteca974c82018-05-01 18:06:16 -070037 o.voltha_port = 1234
Matteo Scandolof6337eb2018-04-05 15:58:37 -070038 o.voltha_user = "voltha_user"
39 o.voltha_pass = "voltha_pass"
Matteo Scandolo0d756f22019-06-10 14:55:55 -070040
41 o.provider_services = [onos]
Matteo Scandolof6337eb2018-04-05 15:58:37 -070042
43 self.o = o
44
45 def test_format_url(self):
46 url = Helpers.format_url("onf.com")
47 self.assertEqual(url, "http://onf.com")
48 url = Helpers.format_url("http://onf.com")
49 self.assertEqual(url, "http://onf.com")
50
51 def test_get_voltha_info(self):
52 voltha_dict = Helpers.get_voltha_info(self.o)
53
54 self.assertEqual(voltha_dict["url"], "http://voltha_url")
Luca Preteca974c82018-05-01 18:06:16 -070055 self.assertEqual(voltha_dict["port"], 1234)
Matteo Scandolof6337eb2018-04-05 15:58:37 -070056 self.assertEqual(voltha_dict["user"], "voltha_user")
57 self.assertEqual(voltha_dict["pass"], "voltha_pass")
58
59 def test_get_onos_info(self):
Luca Preteca974c82018-05-01 18:06:16 -070060 onos_voltha_dict = Helpers.get_onos_voltha_info(self.o)
Matteo Scandolof6337eb2018-04-05 15:58:37 -070061
Luca Preteca974c82018-05-01 18:06:16 -070062 self.assertEqual(onos_voltha_dict["url"], "http://onos_voltha_url")
63 self.assertEqual(onos_voltha_dict["port"], 4321)
64 self.assertEqual(onos_voltha_dict["user"], "onos_voltha_user")
65 self.assertEqual(onos_voltha_dict["pass"], "onos_voltha_pass")
Matteo Scandolof6337eb2018-04-05 15:58:37 -070066
67 def test_datapath_id_to_hex(self):
68 hex = Helpers.datapath_id_to_hex(55334486016)
69 self.assertEqual(hex, "0000000ce2314000")
70
71 hex = Helpers.datapath_id_to_hex("55334486016")
72 self.assertEqual(hex, "0000000ce2314000")
73
74if __name__ == "__main__":
75 unittest.main()