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
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

8.1.1.0 (2017-08-27)
--------------------

* remodeling update_shell to also accept shell name

8.1.0.1 (2017-06-12)
--------------------

Expand Down
11 changes: 8 additions & 3 deletions cloudshell/rest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ def add_shell(self, shell_path):
if response.status_code != 201:
raise Exception(response.text)

def update_shell(self, shell_path):
def update_shell(self, shell_path, shell_name=None):
"""
Updates an existing Shell Entity in CloudShell
:param shell_path:
:param shell_path: The path to the shell file
:param shell_name: The shell name. if not supplied the shell name is derived from the shell path
:return:
"""
filename = os.path.basename(shell_path)
shell_name = os.path.splitext(filename)[0]
shell_name = shell_name or self._get_shell_name_from_filename(filename)
url = 'http://{0}:{1}/API/Shells/{2}'.format(self.ip, self.port, shell_name)
response = put(url,
files={filename: open(shell_path, 'rb')},
Expand Down Expand Up @@ -86,3 +87,7 @@ def get_installed_standards(self):
@staticmethod
def _urlencode(s):
return s.replace('+', '%2B').replace('/', '%2F').replace('=', '%3D')

@staticmethod
def _get_shell_name_from_filename(filename):
return os.path.splitext(filename)[0]
2 changes: 1 addition & 1 deletion cloudshell/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '8.1.0.1'
__version__ = '8.1.1.0'
20 changes: 12 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
[bumpversion]
current_version = 0.1.0
current_version = 8.1.1.0
commit = True
tag = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.(?P<build>\d+)
serialize = {major}.{minor}.{patch}.{build}

[bumpversion:file:setup.py]
search = version='{current_version}'
replace = version='{new_version}'
[bumpversion:file:cloudshell/version.py]

[bumpversion:file:cloudshell_rest_api/__init__.py]
search = __version__ = '{current_version}'
replace = __version__ = '{new_version}'
[bumpversion:part:release_name]
values =
major
minor
patch
build

[bdist_wheel]
universal = 1

[flake8]
exclude = docs

25 changes: 24 additions & 1 deletion tests/test_packaging_rest_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ def test_update_shell(self, mock_put, mock_build_opener):
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.put')
def test_update_shell_name_given(self, mock_put, mock_build_opener):
# Arrange
mock_url = Mock()
mock_url.read = Mock(return_value='TOKEN')
mock_opener = Mock()
mock_opener.open = Mock(return_value=mock_url)
mock_build_opener.return_value = mock_opener
client = PackagingRestApiClient('SERVER', 9000, 'USER', 'PASS', 'Global')
self.fs.CreateFile('work//NutShell.zip', contents='ZIP CONTENT')
mock_put.return_value = Response()
mock_put.return_value.status_code = 200 # Ok

# Act
client.update_shell('work//NutShell.zip', 'my_amazing_shell')

# Assert
self.assertTrue(mock_put.called, 'Put should be called')
self.assertEqual(mock_put.call_args[0][0], 'http://SERVER:9000/API/Shells/my_amazing_shell')
self.assertEqual(mock_put.call_args[1]['headers']['Authorization'], 'Basic TOKEN') \

@patch('cloudshell.rest.api.urllib2.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):
Expand Down Expand Up @@ -97,13 +119,14 @@ def test_get_installed_standards(self, mock_get, mock_build_opener):
mock_build_opener.return_value = mock_opener
client = PackagingRestApiClient('SERVER', 9000, 'USER', 'PASS', 'Global')
mock_get.return_value = Response()
mock_get.return_value._content = "[]" # hack - empty response content
mock_get.return_value.status_code = 200 # Ok

# Act
client.get_installed_standards()

# Assert
self.assertTrue(mock_get.called, 'Post should be called')
self.assertTrue(mock_get.called, 'Get should be called')
self.assertEqual(mock_get.call_args[0][0], 'http://SERVER:9000/API/Standards')
self.assertEqual(mock_get.call_args[1]['headers']['Authorization'], 'Basic TOKEN')

Expand Down