powervc-driver/neutron-powervc/test/test_utils.py
Le Tian Ren bb7da09624 Fix copyright headline in the source files
Change-Id: Ie1b0dac8a8ec1e6d02217fe03159c78a69f6dc5d
Closes-Bug: #1317657
2014-05-09 13:05:20 +08:00

66 lines
2.4 KiB
Python

# Copyright 2013 IBM Corp.
import unittest
import mox
from powervc.neutron.common import utils
"""
UT for utils functions
"""
class TestUtils(unittest.TestCase):
def setUp(self):
# Initialize the MOX instance
self.moxer = mox.Mox()
def tearDown(self):
pass
def test_is_network_in_white_list(self):
self.assertTrue(self._test_case_is_network_in_white_list
(['*'], 'anything'))
self.assertTrue(self._test_case_is_network_in_white_list
(['*'], None))
self.assertTrue(self._test_case_is_network_in_white_list
(['*'], ''))
self.assertFalse(self._test_case_is_network_in_white_list
(['?'], ''))
self.assertFalse(self._test_case_is_network_in_white_list
([], ''))
self.assertFalse(self._test_case_is_network_in_white_list
([], 'anything'))
self.assertTrue(self._test_case_is_network_in_white_list
(['VLAN1'], 'VLAN1'))
self.assertFalse(self._test_case_is_network_in_white_list
(['VLAN1'], 'VLAN'))
self.assertFalse(self._test_case_is_network_in_white_list
(['VLAN1'], ''))
self.assertFalse(self._test_case_is_network_in_white_list
(['VLAN1'], None))
self.assertTrue(self._test_case_is_network_in_white_list
(['VLAN1', 'V2'], 'VLAN1'))
self.assertTrue(self._test_case_is_network_in_white_list
(['VLAN1', 'V2'], 'V2'))
self.assertFalse(self._test_case_is_network_in_white_list
(['VLAN1', 'V2'], 'V3'))
self.assertTrue(self._test_case_is_network_in_white_list
(['VLAN1', 'V?'], 'V3'))
self.assertTrue(self._test_case_is_network_in_white_list
(['VLAN1', 'V[34]'], 'V3'))
self.assertFalse(self._test_case_is_network_in_white_list
(['VLAN1', 'V[34]'], 'V5'))
def _test_case_is_network_in_white_list(self, whitelist, net_name):
self.moxer.StubOutWithMock(utils, "_get_map_white_list")
utils._get_map_white_list().AndReturn(whitelist)
self.moxer.ReplayAll()
net = {'name': net_name}
rtn = utils.is_network_in_white_list(net)
self.moxer.VerifyAll()
self.moxer.UnsetStubs()
return rtn