|
11 | 11 |
|
12 | 12 | """
|
13 | 13 | import os
|
| 14 | +import shutil |
14 | 15 |
|
15 | 16 | from ansys.api.speos import grpc_stub
|
| 17 | +from ansys.api.speos.file.v1 import file_transfer |
| 18 | +import ansys.api.speos.file.v1.file_transfer_pb2 as file_transfer__v1__pb2 |
| 19 | +import ansys.api.speos.file.v1.file_transfer_pb2_grpc as file_transfer__v1__pb2_grpc |
16 | 20 | import ansys.api.speos.simulation.v1.simulation_pb2 as simulation__v1__pb2
|
17 | 21 | import ansys.api.speos.simulation.v1.simulation_pb2_grpc as simulation__v1__pb2_grpc
|
18 | 22 |
|
19 |
| -from conftest import config, test_path |
| 23 | +from conftest import config, local_test_path, test_path |
20 | 24 | from helper import does_file_exist, remove_file
|
21 | 25 |
|
22 | 26 |
|
@@ -74,3 +78,112 @@ def test_simulation():
|
74 | 78 | delete_request = simulation__v1__pb2.Delete_Request()
|
75 | 79 | delete_request.guid = guid_simu.guid
|
76 | 80 | simulation_manager_stub.Delete(delete_request)
|
| 81 | + |
| 82 | + |
| 83 | +def test_simu_allocateSyst_load_run_with_file_transfer(): |
| 84 | + # Stubs creations |
| 85 | + file_transfer_stub = grpc_stub.get_stub_insecure_channel( |
| 86 | + target="localhost:50051", |
| 87 | + stub_type=file_transfer__v1__pb2_grpc.FileTransferServiceStub, |
| 88 | + ) |
| 89 | + simu_manager_stub = grpc_stub.get_stub_insecure_channel( |
| 90 | + target="localhost:50051", |
| 91 | + stub_type=simulation__v1__pb2_grpc.SpeosSimulationsManagerStub, |
| 92 | + ) |
| 93 | + simu_stub = grpc_stub.get_stub_insecure_channel( |
| 94 | + target="localhost:50051", |
| 95 | + stub_type=simulation__v1__pb2_grpc.SpeosSimulationStub, |
| 96 | + ) |
| 97 | + |
| 98 | + # Use upload_folder helper provided within ansys.api.speos.file.v1 |
| 99 | + sv5_name = "LG_50M_Colorimetric_short.sv5" |
| 100 | + upload_responses = file_transfer.upload_folder( |
| 101 | + file_transfer_service_stub=file_transfer_stub, |
| 102 | + folder_path=os.path.join(local_test_path, sv5_name), |
| 103 | + main_file_name=sv5_name, |
| 104 | + ) |
| 105 | + sv5_res_uri = [upload_res.info.uri for upload_res in upload_responses if upload_res.info.file_name == sv5_name][0] |
| 106 | + |
| 107 | + # Allocate system |
| 108 | + create_res = simu_manager_stub.Create(simulation__v1__pb2.Create_Request()) |
| 109 | + |
| 110 | + # Load sv5 into allocated system |
| 111 | + simu_stub.Load(simulation__v1__pb2.Load_Request(guid=create_res.guid, input_file_path=sv5_res_uri)) |
| 112 | + |
| 113 | + # Run |
| 114 | + run_res = simu_stub.Run(simulation__v1__pb2.Run_Request(guid=create_res.guid)) |
| 115 | + assert len(run_res.result_upload_responses) == 2 |
| 116 | + assert run_res.result_upload_responses[0].info.file_name == "ASSEMBLY1.DS (0).Dom Irradiance Sensor (0).xmp" |
| 117 | + assert run_res.result_upload_responses[1].info.file_name == "ASSEMBLY1.DS (0).html" |
| 118 | + |
| 119 | + # Delete files on Server |
| 120 | + # Files uploaded |
| 121 | + file_transfer_stub.Delete(file_transfer__v1__pb2.Delete_Request(uri=sv5_res_uri)) |
| 122 | + # Results from simu |
| 123 | + for res_uploaded in run_res.result_upload_responses: |
| 124 | + file_transfer_stub.Delete(file_transfer__v1__pb2.Delete_Request(uri=res_uploaded.info.uri)) |
| 125 | + |
| 126 | + |
| 127 | +def test_simu_allocateSyst_load_save_with_file_transfer(): |
| 128 | + # Stubs creations |
| 129 | + file_transfer_stub = grpc_stub.get_stub_insecure_channel( |
| 130 | + target="localhost:50051", |
| 131 | + stub_type=file_transfer__v1__pb2_grpc.FileTransferServiceStub, |
| 132 | + ) |
| 133 | + simu_manager_stub = grpc_stub.get_stub_insecure_channel( |
| 134 | + target="localhost:50051", |
| 135 | + stub_type=simulation__v1__pb2_grpc.SpeosSimulationsManagerStub, |
| 136 | + ) |
| 137 | + simu_stub = grpc_stub.get_stub_insecure_channel( |
| 138 | + target="localhost:50051", |
| 139 | + stub_type=simulation__v1__pb2_grpc.SpeosSimulationStub, |
| 140 | + ) |
| 141 | + sv5_name = "LG_50M_Colorimetric_short.sv5" |
| 142 | + blue_spectrum = "Blue Spectrum.spectrum" |
| 143 | + red_spectrum = "Red Spectrum.spectrum" |
| 144 | + |
| 145 | + # Use upload_folder helper provided within ansys.api.speos.file.v1 |
| 146 | + upload_responses = file_transfer.upload_folder( |
| 147 | + file_transfer_service_stub=file_transfer_stub, |
| 148 | + folder_path=os.path.join(local_test_path, sv5_name), |
| 149 | + main_file_name=sv5_name, |
| 150 | + ) |
| 151 | + sv5_res_uri = [upload_res.info.uri for upload_res in upload_responses if upload_res.info.file_name == sv5_name][0] |
| 152 | + |
| 153 | + # Allocate system |
| 154 | + create_res = simu_manager_stub.Create(simulation__v1__pb2.Create_Request()) |
| 155 | + |
| 156 | + # Load sv5 into allocated system |
| 157 | + simu_stub.Load(simulation__v1__pb2.Load_Request(guid=create_res.guid, input_file_path=sv5_res_uri)) |
| 158 | + |
| 159 | + # Reserve an item in file system in order to perform a Save |
| 160 | + reserve_res = file_transfer_stub.Reserve(file_transfer__v1__pb2.Reserve_Request()) |
| 161 | + # And Save |
| 162 | + simu_stub.Save(simulation__v1__pb2.Save_Request(guid=create_res.guid, input_folder_path=reserve_res.uri)) |
| 163 | + |
| 164 | + # We can then list dependencies of the reserved item to check that it contains two deps with correct names |
| 165 | + deps_response = file_transfer_stub.ListDependencies( |
| 166 | + file_transfer__v1__pb2.ListDependencies_Request(uri=reserve_res.uri) |
| 167 | + ) |
| 168 | + assert len(deps_response.dependency_infos) == 2 |
| 169 | + assert [dep_info for dep_info in deps_response.dependency_infos if dep_info.file_name == blue_spectrum] |
| 170 | + assert [dep_info for dep_info in deps_response.dependency_infos if dep_info.file_name == red_spectrum] |
| 171 | + |
| 172 | + # And download locally the simu saved - using download_folder helper provided within ansys.api.speos.file.v1 |
| 173 | + download_loc = os.path.join(local_test_path, "download_simu") |
| 174 | + os.mkdir(download_loc) |
| 175 | + download_responses = file_transfer.download_folder( |
| 176 | + file_transfer_service_stub=file_transfer_stub, main_file_uri=reserve_res.uri, download_location=download_loc |
| 177 | + ) |
| 178 | + # Check that file are well downloaded |
| 179 | + for res in download_responses: |
| 180 | + downloaded_file = os.path.join(download_loc, res.info.file_name) |
| 181 | + assert os.path.exists(downloaded_file) |
| 182 | + assert os.path.getsize(downloaded_file) == res.info.file_size |
| 183 | + shutil.rmtree(download_loc) |
| 184 | + |
| 185 | + # Delete files on Server |
| 186 | + # Files uploaded |
| 187 | + file_transfer_stub.Delete(file_transfer__v1__pb2.Delete_Request(uri=sv5_res_uri)) |
| 188 | + # Files saved |
| 189 | + file_transfer_stub.Delete(file_transfer__v1__pb2.Delete_Request(uri=reserve_res.uri)) |
0 commit comments