import mock import requests.models as req_mod import requests.structures as req_struct import testtools import pypowervm.adapter as adp import pypowervm.const as c import pypowervm.entities as ent import pypowervm.exceptions as pvmex import pypowervm.tests.lib as testlib import pypowervm.tests.test_fixtures as fx from pypowervm.tests.test_utils import pvmhttp from pypowervm.wrappers import storage as pvm_stor from pypowervm.wrappers import virtual_io_server as pvm_vios logon_text = testlib.file2b("logon.xml") response_text = testlib.file2b("event.xml") NET_BRIDGE_FILE = 'fake_network_bridge.txt' class TestAdapter(testtools.TestCase): """Test cases to test the adapter classes and methods.""" def _mk_response(self, status, content=None): reasons = {200: 'OK', 204: 'No Content', 401: 'Unauthorized'} # Create a Response object, that will serve as a mock return value my_response = req_mod.Response() my_response.status_code = status my_response.reason = reasons[status]
import unittest import mock import requests.models as req_mod import requests.structures as req_struct import pypowervm.adapter as adp import pypowervm.tests.lib as testlib from pypowervm.tests.test_utils import pvmhttp from pypowervm import traits import pypowervm.wrappers.entry_wrapper as ewrap import pypowervm.wrappers.network as net import pypowervm.wrappers.storage as stor _logon_response_text = testlib.file2b("logon_file.xml") _feed_file = pvmhttp.load_pvm_resp( "fake_network_bridge.txt").response.body.encode('utf-8') _entry_file = pvmhttp.load_pvm_resp( "fake_volume_group.txt").response.body.encode('utf-8') class TestTraits(unittest.TestCase): @mock.patch('pypowervm.adapter.Session') def test_traits(self, mock_sess): # PVM MC, local auth mock_sess.mc_type = 'PVM' mock_sess.use_file_auth = True t = traits.APITraits(mock_sess) self.assertFalse(t.vnet_aware)
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import mock import requests.models as req_mod import requests.structures as req_struct import testtools import pypowervm.adapter as adp import pypowervm.exceptions as pvmex import pypowervm.tests.lib as testlib import pypowervm.tests.test_fixtures as fx _logon_response_password = testlib.file2b("logon.xml") _logon_response_file = testlib.file2b("logon_file.xml") class TestAdapter(testtools.TestCase): """Test cases to test the Adapter classes and methods.""" def test_Session(self): """This test is just meant to ensure Session can be instantiated.""" # Passing in 0.0.0.0 will raise a ConnectionError or SSLError, but only # if it gets past all the __init__ setup since _logon is the last # statement. self.assertRaises((pvmex.ConnectionError, pvmex.SSLError), adp.Session, '0.0.0.0', 'uid', 'pwd') @mock.patch('pypowervm.adapter.Session._logon')
import copy import gc import mock import os import requests.models as req_mod import requests.structures as req_struct import subunit import sys import testtools import pypowervm.adapter as adp import pypowervm.exceptions as pvmex import pypowervm.tests.lib as testlib import pypowervm.tests.test_fixtures as fx _logon_response_password = testlib.file2b("logon.xml") _logon_response_file = testlib.file2b("logon_file.xml") class TestSession(subunit.IsolatedTestCase, testtools.TestCase): """Test cases to test the Session classes and methods.""" @mock.patch('time.sleep') @mock.patch('lxml.etree.fromstring', new=mock.Mock()) @mock.patch('pypowervm.adapter.Session._get_auth_tok_from_file', new=mock.Mock()) def test_Session(self, mock_sleep): """Ensure Session can be instantiated, and test logon retries.""" # Passing in 0.0.0.0 will raise a ConnectionError or SSLError, but only # if it gets past all the __init__ setup since _logon is the last # statement.
import mock import requests.models as req_mod import requests.structures as req_struct import testtools import pypowervm.adapter as adp import pypowervm.const as c import pypowervm.entities as ent import pypowervm.exceptions as pvmex import pypowervm.tests.lib as testlib import pypowervm.tests.test_fixtures as fx from pypowervm.tests.test_utils import pvmhttp from pypowervm.wrappers import storage as pvm_stor from pypowervm.wrappers import virtual_io_server as pvm_vios logon_text = testlib.file2b("logon.xml") response_text = testlib.file2b("event.xml") NET_BRIDGE_FILE = 'fake_network_bridge.txt' class TestAdapter(testtools.TestCase): """Test cases to test the adapter classes and methods.""" def _mk_response(self, status, content=None): reasons = {200: 'OK', 204: 'No Content', 401: 'Unauthorized'} # Create a Response object, that will serve as a mock return value my_response = req_mod.Response() my_response.status_code = status my_response.reason = reasons[status] clen = '0'
import unittest import mock import requests.models as req_mod import requests.structures as req_struct import pypowervm.adapter as adp import pypowervm.tests.lib as testlib from pypowervm.tests.test_utils import pvmhttp from pypowervm import traits import pypowervm.wrappers.entry_wrapper as ewrap import pypowervm.wrappers.network as net import pypowervm.wrappers.storage as stor _logon_response_text = testlib.file2b("logon_file.xml") _feed_file = pvmhttp.load_pvm_resp( "fake_network_bridge.txt").response.body.encode('utf-8') _entry_file = pvmhttp.load_pvm_resp( "fake_volume_group.txt").response.body.encode('utf-8') class TestTraits(unittest.TestCase): @mock.patch('pypowervm.adapter.Session') def test_traits(self, mock_sess): # PVM MC, local auth mock_sess.mc_type = 'PVM' mock_sess.use_file_auth = True t = traits.APITraits(mock_sess) self.assertFalse(t.vnet_aware) self.assertFalse(t._is_hmc)