99
1010import pytest
1111from lightning_cloud .openapi import (
12- Body4 ,
1312 CloudspaceIdRunsBody ,
1413 Externalv1Cluster ,
1514 Externalv1LightningappInstance ,
@@ -1422,9 +1421,6 @@ def test_open(self, monkeypatch):
14221421
14231422 mock_client .cloud_space_service_create_cloud_space .return_value = V1CloudSpace (id = "cloudspace_id" )
14241423 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- )
14281424
14291425 mock_client .cluster_service_list_clusters .return_value = V1ListClustersResponse ([Externalv1Cluster (id = "test" )])
14301426 cloud_backend = mock .MagicMock ()
@@ -1445,9 +1441,6 @@ def test_open(self, monkeypatch):
14451441 cloudspace_id = "cloudspace_id" ,
14461442 body = mock .ANY ,
14471443 )
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- )
14511444
14521445 assert mock_client .cloud_space_service_create_cloud_space .call_args .kwargs ["body" ].name == "test_space"
14531446
@@ -1565,10 +1558,6 @@ def test_reopen(self, monkeypatch, capsys):
15651558 body = mock .ANY ,
15661559 )
15671560
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-
15721561 out , _ = capsys .readouterr ()
15731562 assert "will not overwrite the files in your CloudSpace." in out
15741563
@@ -2012,12 +2001,11 @@ def run(self):
20122001
20132002
20142003@pytest .mark .parametrize (
2015- "project, cloudspace_name, run_instance, user, tab, lightning_cloud_url, expected_url" ,
2004+ "project, run_instance, user, tab, lightning_cloud_url, expected_url" ,
20162005 [
20172006 # Old style
20182007 (
20192008 V1Membership (),
2020- "any" ,
20212009 Externalv1LightningappInstance (id = "test-app-id" ),
20222010 V1GetUserResponse (username = "tester" , features = V1UserFeatures ()),
20232011 "logs" ,
@@ -2026,7 +2014,6 @@ def run(self):
20262014 ),
20272015 (
20282016 V1Membership (),
2029- "any" ,
20302017 Externalv1LightningappInstance (id = "test-app-id" ),
20312018 V1GetUserResponse (username = "tester" , features = V1UserFeatures ()),
20322019 "logs" ,
@@ -2036,25 +2023,58 @@ def run(self):
20362023 # New style
20372024 (
20382025 V1Membership (name = "tester's project" ),
2039- "test/app" ,
2040- Externalv1LightningappInstance (),
2026+ Externalv1LightningappInstance (name = "test/job" ),
20412027 V1GetUserResponse (username = "tester" , features = V1UserFeatures (project_selector = True )),
20422028 "logs" ,
20432029 "https://lightning.ai" ,
2044- "https://lightning.ai/tester/tester%27s_project/apps /test~app /logs" ,
2030+ "https://lightning.ai/tester/tester%27s%20project/jobs /test%2Fjob /logs" ,
20452031 ),
20462032 (
20472033 V1Membership (name = "tester's project" ),
2048- "test/app" ,
2049- Externalv1LightningappInstance (),
2034+ Externalv1LightningappInstance (name = "test/job" ),
20502035 V1GetUserResponse (username = "tester" , features = V1UserFeatures (project_selector = True )),
20512036 "logs" ,
2037+ "https://localhost:9800" ,
2038+ "https://localhost:9800/tester/tester%27s%20project/jobs/test%2Fjob/logs" ,
2039+ ),
2040+ ],
2041+ )
2042+ def test_get_app_url (monkeypatch , project , run_instance , user , tab , lightning_cloud_url , expected_url ):
2043+ mock_client = mock .MagicMock ()
2044+ mock_client .auth_service_get_user .return_value = user
2045+ cloud_backend = mock .MagicMock (client = mock_client )
2046+ monkeypatch .setattr (backends , "CloudBackend" , mock .MagicMock (return_value = cloud_backend ))
2047+
2048+ runtime = CloudRuntime ()
2049+
2050+ with mock .patch (
2051+ "lightning.app.runners.cloud.get_lightning_cloud_url" , mock .MagicMock (return_value = lightning_cloud_url )
2052+ ):
2053+ assert runtime ._get_app_url (project , run_instance , tab ) == expected_url
2054+
2055+
2056+ @pytest .mark .parametrize (
2057+ "user, project, cloudspace_name, tab, lightning_cloud_url, expected_url" ,
2058+ [
2059+ (
2060+ V1GetUserResponse (username = "tester" , features = V1UserFeatures ()),
2061+ V1Membership (name = "default-project" ),
2062+ "test/cloudspace" ,
2063+ "code" ,
2064+ "https://lightning.ai" ,
2065+ "https://lightning.ai/tester/default-project/apps/test%2Fcloudspace/code" ,
2066+ ),
2067+ (
2068+ V1GetUserResponse (username = "tester" , features = V1UserFeatures ()),
2069+ V1Membership (name = "Awesome Project" ),
2070+ "The Best CloudSpace ever" ,
2071+ "web-ui" ,
20522072 "http://localhost:9800" ,
2053- "http://localhost:9800/tester/tester%27s_project /apps/test~app/logs " ,
2073+ "http://localhost:9800/tester/Awesome%20Project /apps/The%20Best%20CloudSpace%20ever/web-ui " ,
20542074 ),
20552075 ],
20562076)
2057- def test_get_app_url (monkeypatch , project , cloudspace_name , run_instance , user , tab , lightning_cloud_url , expected_url ):
2077+ def test_get_cloudspace_url (monkeypatch , user , project , cloudspace_name , tab , lightning_cloud_url , expected_url ):
20582078 mock_client = mock .MagicMock ()
20592079 mock_client .auth_service_get_user .return_value = user
20602080 cloud_backend = mock .MagicMock (client = mock_client )
@@ -2065,4 +2085,4 @@ def test_get_app_url(monkeypatch, project, cloudspace_name, run_instance, user,
20652085 with mock .patch (
20662086 "lightning_app.runners.cloud.get_lightning_cloud_url" , mock .MagicMock (return_value = lightning_cloud_url )
20672087 ):
2068- assert runtime ._get_app_url (project , cloudspace_name , run_instance , tab ) == expected_url
2088+ assert runtime ._get_cloudspace_url (project , cloudspace_name , tab ) == expected_url
0 commit comments