Skip to content

Commit 1cf5372

Browse files
authored
Merge branch 'master' into bcwu-1.14.1
2 parents ed37c81 + 81ff597 commit 1cf5372

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

.github/pull_request_template.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,5 @@
2929
## Checklist:
3030
<!--- Go over all the following points, and put an `x` in all the boxes that apply: -->
3131
<!--- If you need clarification on any of these, feel free to ask. We're here to help! -->
32-
- [ ] I have read the **CONTRIBUTING** document.
33-
- [ ] My code follows the code style of this project.
34-
- [ ] I have updated the documentation as needed.
35-
- [ ] I have added tests to cover my changes.
32+
- [ ] I have added tests to cover my changes.
33+
- [ ] I have updated [CHANGELOG.md](../CHANGELOG.md) to cover notable changes.

rsconnect/api.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ def deploy(self, app_id, app_name, app_title, title_is_default, tarball, env_var
236236
# assume app exists. if it was deleted then Connect will
237237
# raise an error
238238
app = self.app_get(app_id)
239-
self._server.handle_bad_response(app)
239+
try:
240+
self._server.handle_bad_response(app)
241+
except RSConnectException as e:
242+
raise RSConnectException(f"{e} Try setting the --new flag to overwrite the previous deployment.")
240243

241244
app_guid = app["guid"]
242245
if env_vars:
@@ -845,11 +848,21 @@ def validate_app_mode(self, *args, **kwargs):
845848
# Don't read app metadata if app-id is specified. Instead, we need
846849
# to get this from the remote.
847850
if isinstance(self.remote_server, RSConnectServer):
848-
app = get_app_info(self.remote_server, app_id)
849-
existing_app_mode = AppModes.get_by_ordinal(app.get("app_mode", 0), True)
851+
try:
852+
app = get_app_info(self.remote_server, app_id)
853+
existing_app_mode = AppModes.get_by_ordinal(app.get("app_mode", 0), True)
854+
except RSConnectException as e:
855+
raise RSConnectException(
856+
f"{e} Try setting the --new flag to overwrite the previous deployment."
857+
)
850858
elif isinstance(self.remote_server, PositServer):
851-
app = get_rstudio_app_info(self.remote_server, app_id)
852-
existing_app_mode = AppModes.get_by_cloud_name(app.json_data["mode"])
859+
try:
860+
app = get_rstudio_app_info(self.remote_server, app_id)
861+
existing_app_mode = AppModes.get_by_cloud_name(app.json_data["mode"])
862+
except RSConnectException as e:
863+
raise RSConnectException(
864+
f"{e} Try setting the --new flag to overwrite the previous deployment."
865+
)
853866
else:
854867
raise RSConnectException("Unable to infer Connect client.")
855868
if existing_app_mode and existing_app_mode not in (None, AppModes.UNKNOWN, app_mode):

tests/test_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from unittest import TestCase
2+
from unittest.mock import Mock, patch
3+
4+
from rsconnect.exception import RSConnectException
25
from .utils import (
36
require_api_key,
47
require_connect,
@@ -73,3 +76,15 @@ def test_connect_authorization_header(self):
7376
none_connect_server = RSConnectServer("http://test-server", None)
7477
none_connect_client = RSConnectClient(none_connect_server)
7578
self.assertEqual(none_connect_client.get_authorization(), None)
79+
80+
81+
class RSConnectClientTestCase(TestCase):
82+
def test_deploy_existing_application_with_failure(self):
83+
with patch.object(RSConnectClient, "__init__", lambda _, server, cookies, timeout: None):
84+
client = RSConnectClient(Mock(), Mock(), Mock())
85+
client.app_get = Mock(return_value=Mock())
86+
client._server = Mock(spec=RSConnectServer)
87+
client._server.handle_bad_response = Mock(side_effect=RSConnectException(""))
88+
app_id = Mock()
89+
with self.assertRaises(RSConnectException):
90+
client.deploy(app_id, app_name=None, app_title=None, title_is_default=None, tarball=None)

0 commit comments

Comments
 (0)