diff --git a/cloudshell/rest/api.py b/cloudshell/rest/api.py index ef1ec4a..679f722 100644 --- a/cloudshell/rest/api.py +++ b/cloudshell/rest/api.py @@ -1,7 +1,7 @@ import os import re import urllib2 -from requests import post +from requests import post, put from cloudshell.rest.exceptions import ShellNotFoundException @@ -56,7 +56,7 @@ def update_shell(self, shell_path): filename = os.path.basename(shell_path) shell_name = os.path.splitext(filename)[0] url = 'http://{0}:{1}/API/Shells/{2}'.format(self.ip, self.port, shell_name) - response = post(url, + response = put(url, files={filename: open(shell_path, 'rb')}, headers={'Authorization': 'Basic ' + self.token}) diff --git a/cloudshell/version.py b/cloudshell/version.py index 4944061..3c86b54 100644 --- a/cloudshell/version.py +++ b/cloudshell/version.py @@ -1 +1 @@ -__version__ = '7.2.0.6' +__version__ = '7.2.0.7' diff --git a/tests/test_packaging_rest_api_client.py b/tests/test_packaging_rest_api_client.py index 5459fe9..563fb00 100644 --- a/tests/test_packaging_rest_api_client.py +++ b/tests/test_packaging_rest_api_client.py @@ -48,8 +48,8 @@ def test_add_shell(self, mock_post, mock_build_opener): self.assertEqual(mock_post.call_args[1]['headers']['Authorization'], 'Basic TOKEN') @patch('cloudshell.rest.api.urllib2.build_opener') - @patch('cloudshell.rest.api.post') - def test_update_shell(self, mock_post, mock_build_opener): + @patch('cloudshell.rest.api.put') + def test_update_shell(self, mock_put, mock_build_opener): # Arrange mock_url = Mock() mock_url.read = Mock(return_value='TOKEN') @@ -58,20 +58,20 @@ def test_update_shell(self, mock_post, mock_build_opener): mock_build_opener.return_value = mock_opener client = PackagingRestApiClient('SERVER', 9000, 'USER', 'PASS', 'Global') self.fs.CreateFile('work//NutShell.zip', contents='ZIP CONTENT') - mock_post.return_value = Response() - mock_post.return_value.status_code = 200 # Ok + mock_put.return_value = Response() + mock_put.return_value.status_code = 200 # Ok # Act client.update_shell('work//NutShell.zip') # Assert - self.assertTrue(mock_post.called, 'Post should be called') - self.assertEqual(mock_post.call_args[0][0], 'http://SERVER:9000/API/Shells/NutShell') - self.assertEqual(mock_post.call_args[1]['headers']['Authorization'], 'Basic TOKEN') \ + self.assertTrue(mock_put.called, 'Post should be called') + self.assertEqual(mock_put.call_args[0][0], 'http://SERVER:9000/API/Shells/NutShell') + self.assertEqual(mock_put.call_args[1]['headers']['Authorization'], 'Basic TOKEN') \ @patch('cloudshell.rest.api.urllib2.build_opener') - @patch('cloudshell.rest.api.post') - def test_update_shell_throws_shell_not_found_exception_when_404_code_returned(self, mock_post, mock_build_opener): + @patch('cloudshell.rest.api.put') + def test_update_shell_throws_shell_not_found_exception_when_404_code_returned(self, mock_put, mock_build_opener): # Arrange mock_url = Mock() mock_url.read = Mock(return_value='TOKEN') @@ -80,8 +80,8 @@ def test_update_shell_throws_shell_not_found_exception_when_404_code_returned(se mock_build_opener.return_value = mock_opener client = PackagingRestApiClient('SERVER', 9000, 'USER', 'PASS', 'Global') self.fs.CreateFile('work//NutShell.zip', contents='ZIP CONTENT') - mock_post.return_value = Response() - mock_post.return_value.status_code = 404 # Not Found + mock_put.return_value = Response() + mock_put.return_value.status_code = 404 # Not Found # Act & Assert self.assertRaises(ShellNotFoundException, client.update_shell, 'work//NutShell.zip')