blob: 2820d9eec0761122b9c5c27752cbe379c78de91f [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
16from mock import patch, call, Mock, PropertyMock
17from helpers import Helpers
18
19class TestHelpers(unittest.TestCase):
20
21 def setUp(self):
22 # create a mock service instance
23 o = Mock()
24 o.voltha_url = "voltha_url"
25 o.voltha_user = "voltha_user"
26 o.voltha_pass = "voltha_pass"
27 o.p_onos_url = "p_onos_url"
28 o.p_onos_user = "p_onos_user"
29 o.p_onos_pass = "p_onos_pass"
30
31 self.o = o
32
33 def test_format_url(self):
34 url = Helpers.format_url("onf.com")
35 self.assertEqual(url, "http://onf.com")
36 url = Helpers.format_url("http://onf.com")
37 self.assertEqual(url, "http://onf.com")
38
39 def test_get_voltha_info(self):
40 voltha_dict = Helpers.get_voltha_info(self.o)
41
42 self.assertEqual(voltha_dict["url"], "http://voltha_url")
43 self.assertEqual(voltha_dict["user"], "voltha_user")
44 self.assertEqual(voltha_dict["pass"], "voltha_pass")
45
46 def test_get_onos_info(self):
47 p_onos_dict = Helpers.get_p_onos_info(self.o)
48
49 self.assertEqual(p_onos_dict["url"], "http://p_onos_url")
50 self.assertEqual(p_onos_dict["user"], "p_onos_user")
51 self.assertEqual(p_onos_dict["pass"], "p_onos_pass")
52
53 def test_datapath_id_to_hex(self):
54 hex = Helpers.datapath_id_to_hex(55334486016)
55 self.assertEqual(hex, "0000000ce2314000")
56
57 hex = Helpers.datapath_id_to_hex("55334486016")
58 self.assertEqual(hex, "0000000ce2314000")
59
60if __name__ == "__main__":
61 unittest.main()