11"""
2- Test the api methods that require a live sandbox against default
3- - start sandbox
2+ Test the api methods that require an empty, PUBLIC blueprint
43"""
5- import pytest
6- from env_settings import DEFAULT_BLUEPRINT_TEMPLATE
4+ import time
75
6+ import pytest
87from cloudshell .sandbox_rest .sandbox_api import SandboxRestApiSession
8+ from constants import *
9+ from common import *
10+
11+
12+ @pytest .fixture (scope = "module" )
13+ def blueprint_id (admin_session : SandboxRestApiSession , empty_blueprint ):
14+ res_id = get_blueprint_id_from_name (admin_session , empty_blueprint )
15+ assert (type (res_id ) is str )
16+ return res_id
917
1018
1119@pytest .fixture (scope = "module" )
12- def sandbox_id (admin_session : SandboxRestApiSession ):
20+ def sandbox_id (admin_session : SandboxRestApiSession , blueprint_id ):
1321 # start sandbox
1422 start_res = admin_session .start_sandbox (
15- blueprint_id = DEFAULT_BLUEPRINT_TEMPLATE , sandbox_name = "Pytest empty blueprint test"
23+ blueprint_id = blueprint_id , sandbox_name = "Pytest empty blueprint test"
1624 )
1725 sandbox_id = start_res ["id" ]
1826 print (f"Sandbox started: { sandbox_id } " )
@@ -21,46 +29,77 @@ def sandbox_id(admin_session: SandboxRestApiSession):
2129 print (f"\n Sandbox ended: { sandbox_id } " )
2230
2331
32+ @pytest .fixture (scope = "module" )
33+ def setup_execution_id (admin_session : SandboxRestApiSession , sandbox_id : str ):
34+ polling_minutes = 2
35+ counter = 0
36+ while True :
37+ if counter > polling_minutes :
38+ raise Exception ("Timeout waiting for setup to end" )
39+ state = admin_session .get_sandbox_details (sandbox_id )["state" ]
40+ if state == "Ready" :
41+ break
42+ time .sleep (60 )
43+ counter += 1
44+
45+ print ("Rerunning Setup..." )
46+ res = admin_session .run_sandbox_command (sandbox_id = sandbox_id ,
47+ command_name = BLUEPRINT_SETUP_COMMAND )
48+ assert (type (res ) is dict )
49+ print ("Setup re-run execution response" )
50+ pretty_print_response (res )
51+ execution_id = res ["executionId" ]
52+ return execution_id
53+
54+
2455def test_start_stop (admin_session , sandbox_id ):
25- pass
56+ assert (type (sandbox_id ) is str )
57+ print (f"Sandbox ID: { sandbox_id } " )
2658
2759
2860def test_get_sandbox_details (admin_session , sandbox_id ):
2961 details_res = admin_session .get_sandbox_details (sandbox_id )
62+ assert (type (details_res ) is dict )
3063 sb_name = details_res ["name" ]
3164 print (f"Pulled details for sandbox '{ sb_name } '" )
3265
3366
3467def test_get_components (admin_session , sandbox_id ):
35- sb_components = admin_session .get_sandbox_components (sandbox_id )
36- component_count = len (sb_components )
68+ components_res = admin_session .get_sandbox_components (sandbox_id )
69+ assert (type (components_res ) is list )
70+ component_count = len (components_res )
3771 print (f"component count found: { component_count } " )
3872
3973
4074def test_get_sandbox_commands (admin_session , sandbox_id ):
41- sb_commands = admin_session .get_sandbox_commands (sandbox_id )
42- print (f"Sandbox commands: { [x ['name' ] for x in sb_commands ]} " )
43- first_sb_command = admin_session .get_sandbox_command_details (sandbox_id , sb_commands [0 ]["name" ])
75+ commands_res = admin_session .get_sandbox_commands (sandbox_id )
76+ assert (type (commands_res ) is list )
77+ print (f"Sandbox commands: { [x ['name' ] for x in commands_res ]} " )
78+ first_sb_command = admin_session .get_sandbox_command_details (sandbox_id , commands_res [0 ]["name" ])
4479 print (f"SB command name: { first_sb_command ['name' ]} \n " f"description: { first_sb_command ['description' ]} " )
4580
4681
4782def test_get_sandbox_events (admin_session , sandbox_id ):
48- activity = admin_session .get_sandbox_activity (sandbox_id )
49- events = activity ["events" ]
83+ activity_res = admin_session .get_sandbox_activity (sandbox_id )
84+ assert (type (activity_res ) is dict and "events" in activity_res )
85+ events = activity_res ["events" ]
5086 print (f"activity events count: { len (events )} " )
5187
5288
5389def test_get_console_output (admin_session , sandbox_id ):
54- sb_output = admin_session .get_sandbox_output (sandbox_id )
55- entries = sb_output ["entries" ]
90+ output_res = admin_session .get_sandbox_output (sandbox_id )
91+ assert (type (output_res ) is dict and "entries" in output_res )
92+ entries = output_res ["entries" ]
5693 print (f"Sandbox output entries count: { len (entries )} " )
5794
5895
5996def test_get_instructions (admin_session , sandbox_id ):
60- instructions = admin_session .get_sandbox_instructions (sandbox_id )
61- print (f"Pulled sandbox instructions: '{ instructions } '" )
97+ instructions_res = admin_session .get_sandbox_instructions (sandbox_id )
98+ assert (type (instructions_res ) is str )
99+ print (f"Pulled sandbox instructions: '{ instructions_res } '" )
62100
63101
64102def test_extend_sandbox (admin_session , sandbox_id ):
65103 extend_response = admin_session .extend_sandbox (sandbox_id , "PT0H10M" )
104+ assert (type (extend_response ) is dict and "remaining_time" in extend_response )
66105 print (f"extended sandbox. Remaining time: { extend_response ['remaining_time' ]} " )
0 commit comments