Skip to content

Commit b77ca87

Browse files
fix tests
1 parent 6366f2d commit b77ca87

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

tests/tests_app/runners/test_cloud.py

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,9 +1422,6 @@ def test_open(self, monkeypatch):
14221422

14231423
mock_client.cloud_space_service_create_cloud_space.return_value = V1CloudSpace(id="cloudspace_id")
14241424
mock_client.cloud_space_service_create_lightning_run.return_value = V1LightningRun(id="run_id")
1425-
mock_client.cloud_space_service_create_lightning_run_instance.return_value = Externalv1LightningappInstance(
1426-
id="instance_id"
1427-
)
14281425

14291426
mock_client.cluster_service_list_clusters.return_value = V1ListClustersResponse([Externalv1Cluster(id="test")])
14301427
cloud_backend = mock.MagicMock()
@@ -1445,9 +1442,6 @@ def test_open(self, monkeypatch):
14451442
cloudspace_id="cloudspace_id",
14461443
body=mock.ANY,
14471444
)
1448-
mock_client.cloud_space_service_create_lightning_run_instance.assert_called_once_with(
1449-
project_id="test-project-id", cloudspace_id="cloudspace_id", id="run_id", body=mock.ANY
1450-
)
14511445

14521446
assert mock_client.cloud_space_service_create_cloud_space.call_args.kwargs["body"].name == "test_space"
14531447

@@ -1565,10 +1559,6 @@ def test_reopen(self, monkeypatch, capsys):
15651559
body=mock.ANY,
15661560
)
15671561

1568-
mock_client.lightningapp_instance_service_update_lightningapp_instance_release.assert_called_once_with(
1569-
project_id="test-project-id", id="instance_id", body=Body4(release_id="run_id")
1570-
)
1571-
15721562
out, _ = capsys.readouterr()
15731563
assert "will not overwrite the files in your CloudSpace." in out
15741564

@@ -2012,12 +2002,11 @@ def run(self):
20122002

20132003

20142004
@pytest.mark.parametrize(
2015-
"project, cloudspace_name, run_instance, user, tab, lightning_cloud_url, expected_url",
2005+
"project, run_instance, user, tab, lightning_cloud_url, expected_url",
20162006
[
20172007
# Old style
20182008
(
20192009
V1Membership(),
2020-
"any",
20212010
Externalv1LightningappInstance(id="test-app-id"),
20222011
V1GetUserResponse(username="tester", features=V1UserFeatures()),
20232012
"logs",
@@ -2026,7 +2015,6 @@ def run(self):
20262015
),
20272016
(
20282017
V1Membership(),
2029-
"any",
20302018
Externalv1LightningappInstance(id="test-app-id"),
20312019
V1GetUserResponse(username="tester", features=V1UserFeatures()),
20322020
"logs",
@@ -2036,25 +2024,58 @@ def run(self):
20362024
# New style
20372025
(
20382026
V1Membership(name="tester's project"),
2039-
"test/app",
2040-
Externalv1LightningappInstance(),
2027+
Externalv1LightningappInstance(name="test/job"),
20412028
V1GetUserResponse(username="tester", features=V1UserFeatures(project_selector=True)),
20422029
"logs",
20432030
"https://lightning.ai",
2044-
"https://lightning.ai/tester/tester%27s_project/apps/test~app/logs",
2031+
"https://lightning.ai/tester/tester%27s%20project/jobs/test%2Fjob/logs",
20452032
),
20462033
(
20472034
V1Membership(name="tester's project"),
2048-
"test/app",
2049-
Externalv1LightningappInstance(),
2035+
Externalv1LightningappInstance(name="test/job"),
20502036
V1GetUserResponse(username="tester", features=V1UserFeatures(project_selector=True)),
20512037
"logs",
2038+
"https://localhost:9800",
2039+
"https://localhost:9800/tester/tester%27s%20project/jobs/test%2Fjob/logs",
2040+
),
2041+
],
2042+
)
2043+
def test_get_app_url(monkeypatch, project, run_instance, user, tab, lightning_cloud_url, expected_url):
2044+
mock_client = mock.MagicMock()
2045+
mock_client.auth_service_get_user.return_value = user
2046+
cloud_backend = mock.MagicMock(client=mock_client)
2047+
monkeypatch.setattr(backends, "CloudBackend", mock.MagicMock(return_value=cloud_backend))
2048+
2049+
runtime = CloudRuntime()
2050+
2051+
with mock.patch(
2052+
"lightning.app.runners.cloud.get_lightning_cloud_url", mock.MagicMock(return_value=lightning_cloud_url)
2053+
):
2054+
assert runtime._get_app_url(project, run_instance, tab) == expected_url
2055+
2056+
2057+
@pytest.mark.parametrize(
2058+
"user, project, cloudspace_name, tab, lightning_cloud_url, expected_url",
2059+
[
2060+
(
2061+
V1GetUserResponse(username="tester", features=V1UserFeatures()),
2062+
V1Membership(name="default-project"),
2063+
"test/cloudspace",
2064+
"code",
2065+
"https://lightning.ai",
2066+
"https://lightning.ai/tester/default-project/apps/test%2Fcloudspace/code",
2067+
),
2068+
(
2069+
V1GetUserResponse(username="tester", features=V1UserFeatures()),
2070+
V1Membership(name="Awesome Project"),
2071+
"The Best CloudSpace ever",
2072+
"web-ui",
20522073
"http://localhost:9800",
2053-
"http://localhost:9800/tester/tester%27s_project/apps/test~app/logs",
2074+
"http://localhost:9800/tester/Awesome%20Project/apps/The%20Best%20CloudSpace%20ever/web-ui",
20542075
),
20552076
],
20562077
)
2057-
def test_get_app_url(monkeypatch, project, cloudspace_name, run_instance, user, tab, lightning_cloud_url, expected_url):
2078+
def test_get_cloudspace_url(monkeypatch, user, project, cloudspace_name, tab, lightning_cloud_url, expected_url):
20582079
mock_client = mock.MagicMock()
20592080
mock_client.auth_service_get_user.return_value = user
20602081
cloud_backend = mock.MagicMock(client=mock_client)
@@ -2065,4 +2086,4 @@ def test_get_app_url(monkeypatch, project, cloudspace_name, run_instance, user,
20652086
with mock.patch(
20662087
"lightning.app.runners.cloud.get_lightning_cloud_url", mock.MagicMock(return_value=lightning_cloud_url)
20672088
):
2068-
assert runtime._get_app_url(project, cloudspace_name, run_instance, tab) == expected_url
2089+
assert runtime._get_cloudspace_url(project, cloudspace_name, tab) == expected_url

0 commit comments

Comments
 (0)