# # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # 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 requests_mock import dracclient.client from dracclient import exceptions from dracclient.tests import base from dracclient.tests import utils as test_utils @requests_mock.Mocker() class WSManClientTestCase(base.BaseTest): def test_enumerate(self, mock_requests): mock_requests.post('https://1.2.3.4:443/wsman', text='yay!') client = dracclient.client.WSManClient(**test_utils.FAKE_ENDPOINT) resp = client.enumerate('http://resource') self.assertEqual('yay!', resp.text) def test_invoke(self, mock_requests): xml = """ 42 yay! """ # noqa mock_requests.post('https://1.2.3.4:443/wsman', text=xml) client = dracclient.client.WSManClient(**test_utils.FAKE_ENDPOINT) resp = client.invoke('http://resource', 'Foo') self.assertEqual('yay!', resp.find('result').text) def test_invoke_with_expected_return_value(self, mock_requests): xml = """ 42 yay! """ # noqa mock_requests.post('https://1.2.3.4:443/wsman', text=xml) client = dracclient.client.WSManClient(**test_utils.FAKE_ENDPOINT) resp = client.invoke('http://resource', 'Foo', expected_return_value='42') self.assertEqual('yay!', resp.find('result').text) def test_invoke_with_error_return_value(self, mock_requests): xml = """ 2 yay! """ # noqa mock_requests.post('https://1.2.3.4:443/wsman', text=xml) client = dracclient.client.WSManClient(**test_utils.FAKE_ENDPOINT) self.assertRaises(exceptions.DRACOperationFailed, client.invoke, 'http://resource', 'Foo') def test_invoke_with_unexpected_return_value(self, mock_requests): xml = """ 42 yay! """ # noqa mock_requests.post('https://1.2.3.4:443/wsman', text=xml) client = dracclient.client.WSManClient(**test_utils.FAKE_ENDPOINT) self.assertRaises(exceptions.DRACUnexpectedReturnValue, client.invoke, 'http://resource', 'Foo', expected_return_value='4242')