class FirmwareBundlesTest(unittest.TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._firmware_bundles = FirmwareBundles(self.connection) @mock.patch.object(ResourceClient, 'upload') def test_upload(self, mock_upload): firmware_path = "test/SPPgen9snap6.2015_0405.81.iso" self._firmware_bundles.upload(firmware_path) mock_upload.assert_called_once_with(firmware_path, timeout=-1)
class FirmwareBundlesTest(unittest.TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._firmware_bundles = FirmwareBundles(self.connection) @mock.patch.object(TaskMonitor, 'wait_for_task') @mock.patch.object(connection, 'post_multipart') def test_upload(self, mock_upload, mock_wait_task): firmware_path = "test/SPPgen9snap6.2015_0405.81.iso" response = mock.MagicMock(status=200) body = { "category": "tasks", "type": "TaskResourceV2", "associatedResource": { "resourceUri": "/rest/associatedresourceuri" } } mock_upload.return_value = response, body mock_wait_task.return_value = {} self._firmware_bundles.upload(firmware_path) mock_upload.assert_called_once_with('/rest/firmware-bundles', None, firmware_path, 'SPPgen9snap6.2015_0405.81.iso') mock_wait_task.assert_called_once_with(body, -1) @mock.patch.object(TaskMonitor, 'wait_for_task') @mock.patch.object(connection, 'post_multipart') def test_upload_should_raise_exception(self, mock_upload, mock_wait_task): firmware_path = "test/SPPgen9snap6.2015_0405.81.iso" response = mock.MagicMock(status=400) body = {"message": "The file you are attempting to upload is empty."} mock_upload.return_value = response, body try: self._firmware_bundles.upload(firmware_path) except HPOneViewException as e: self.assertEqual( e.msg, "The file you are attempting to upload is empty.") mock_wait_task.assert_not_called() else: self.fail("Expected exception was not raised")
class FirmwareBundlesTest(unittest.TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._firmware_bundles = FirmwareBundles(self.connection) @mock.patch.object(TaskMonitor, 'wait_for_task') @mock.patch.object(connection, 'post_multipart') def test_upload(self, mock_upload, mock_wait_task): firmware_path = "test/SPPgen9snap6.2015_0405.81.iso" response = mock.MagicMock(status=200) body = { "category": "tasks", "type": "TaskResourceV2", "associatedResource": { "resourceUri": "/rest/associatedresourceuri" }} mock_upload.return_value = response, body mock_wait_task.return_value = {} self._firmware_bundles.upload(firmware_path) mock_upload.assert_called_once_with('/rest/firmware-bundles', None, firmware_path, 'SPPgen9snap6.2015_0405.81.iso') mock_wait_task.assert_called_once_with(body, -1) @mock.patch.object(TaskMonitor, 'wait_for_task') @mock.patch.object(connection, 'post_multipart') def test_upload_should_raise_exception(self, mock_upload, mock_wait_task): firmware_path = "test/SPPgen9snap6.2015_0405.81.iso" response = mock.MagicMock(status=400) body = {"message": "The file you are attempting to upload is empty."} mock_upload.return_value = response, body try: self._firmware_bundles.upload(firmware_path) except HPOneViewException as e: self.assertEqual(e.msg, "The file you are attempting to upload is empty.") mock_wait_task.assert_not_called() else: self.fail("Expected exception was not raised")