Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cloudshell/rest/api.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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})

Expand Down
2 changes: 1 addition & 1 deletion cloudshell/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '7.2.0.6'
__version__ = '7.2.0.7'
22 changes: 11 additions & 11 deletions tests/test_packaging_rest_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down