Skip to content

Commit c141e55

Browse files
marcosnavmarcosnav
andauthored
Update the generated content draft URL (#688)
* Update content draft URL * Use draft terminology. Update tests for Draft URL * Lint --------- Co-authored-by: marcosnav <[email protected]>
1 parent 7775740 commit c141e55

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

rsconnect/api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class RSConnectClientDeployResult(TypedDict):
371371
app_id: str
372372
app_guid: str | None
373373
app_url: str
374-
preview_url: str | None
374+
draft_url: str | None
375375
title: str | None
376376

377377

@@ -606,17 +606,17 @@ def deploy(
606606

607607
task = self.content_deploy(app_guid, app_bundle["id"], activate=activate)
608608

609-
# http://ADDRESS/preview/APP_GUID/BUNDLE_ID
610-
# Using replace makes this a bit more robust to changes in the URL structure
611-
# like connect being served on a subpath.
612-
preview_url = app["url"].replace("/content/", "/preview/").rstrip("/") + f"/{app_bundle['id']}"
609+
# http://ADDRESS/DASHBOARD-PATH/#/apps/GUID/draft/BUNDLE_ID_TO_PREVIEW
610+
# Pulling v1 content to get the full dashboard URL
611+
app_v1 = self.content_get(app["guid"])
612+
draft_url = app_v1["dashboard_url"] + f"/draft/{app_bundle['id']}"
613613

614614
return {
615615
"task_id": task["task_id"],
616616
"app_id": app_id,
617617
"app_guid": app["guid"],
618618
"app_url": app["url"],
619-
"preview_url": preview_url if not activate else None,
619+
"draft_url": draft_url if not activate else None,
620620
"title": app["title"],
621621
}
622622

@@ -1126,7 +1126,7 @@ def deploy_bundle(self, activate: bool = True):
11261126
app_id=str(prepare_deploy_result.app_id),
11271127
app_guid=None,
11281128
task_id=None,
1129-
preview_url=None,
1129+
draft_url=None,
11301130
title=self.title,
11311131
)
11321132
return self
@@ -1168,8 +1168,8 @@ def emit_task_log(
11681168
log_lines = self.remote_server.handle_bad_response(log_lines)
11691169

11701170
log_callback.info("Deployment completed successfully.")
1171-
if self.deployed_info.get("preview_url"):
1172-
log_callback.info("\t Preview content URL: %s", self.deployed_info["preview_url"])
1171+
if self.deployed_info.get("draft_url"):
1172+
log_callback.info("\t Draft content URL: %s", self.deployed_info["draft_url"])
11731173
else:
11741174
app_config = self.client.app_config(self.deployed_info["app_id"])
11751175
app_config = self.remote_server.handle_bad_response(app_config)

tests/test_main.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,20 @@ def post_application_deploy_callback(request, uri, response_headers):
229229
status=200,
230230
)
231231

232+
httpretty.register_uri(
233+
httpretty.GET,
234+
"http://fake_server/__api__/v1/content/1234-5678-9012-3456",
235+
body=json.dumps(
236+
{
237+
"dashboard_url": "http://fake_server/connect/#/apps/1234-5678-9012-3456",
238+
}
239+
),
240+
adding_headers={"Content-Type": "application/json"},
241+
status=200,
242+
)
243+
244+
expected_content_url = "http://fake_server/content/1234-5678-9012-3456"
245+
expected_draft_url = "http://fake_server/connect/#/apps/1234-5678-9012-3456/draft/FAKE_BUNDLE_ID"
232246
try:
233247
runner = CliRunner()
234248
args = apply_common_args(["deploy", command, target], server="http://fake_server", key="FAKE_API_KEY")
@@ -249,11 +263,9 @@ def post_application_deploy_callback(request, uri, response_headers):
249263
assert deploy_api_invoked == [True]
250264
assert "Deployment completed successfully." in caplog.text
251265
if expected_activate:
252-
assert "Direct content URL: http://fake_server/content/1234-5678-9012-3456" in caplog.text
266+
assert f"Direct content URL: {expected_content_url}" in caplog.text
253267
else:
254-
assert (
255-
"Preview content URL: http://fake_server/preview/1234-5678-9012-3456/FAKE_BUNDLE_ID" in caplog.text
256-
)
268+
assert f"Draft content URL: {expected_draft_url}" in caplog.text
257269
finally:
258270
if original_api_key_value:
259271
os.environ["CONNECT_API_KEY"] = original_api_key_value

0 commit comments

Comments
 (0)