1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import pytest
import uuid
from azure.core.credentials import AzureKeyCredential
from azure.core.exceptions import HttpResponseError
from azure.mixedreality.remoterendering import (AssetConversionInputSettings,
AssetConversionOutputSettings,
AssetConversionStatus,
RemoteRenderingClient,
RenderingSessionSize,
RenderingSessionStatus)
from devtools_testutils import AzureRecordedTestCase
class TestRemoteRenderingClient(AzureRecordedTestCase):
def test_create_client(self, account_info):
client = RemoteRenderingClient(
endpoint=account_info["service_endpoint"],
account_id=account_info["account_id"],
account_domain=account_info["account_domain"],
credential=account_info["key_credential"]
)
assert client is not None
def test_create_client_with_invalid_arguments(self, account_info):
with pytest.raises(ValueError):
RemoteRenderingClient(
endpoint=None,
account_id=account_info["account_id"],
account_domain=account_info["account_domain"],
credential=account_info["key_credential"])
with pytest.raises(ValueError):
RemoteRenderingClient(
endpoint=account_info["service_endpoint"],
account_id=None,
account_domain=account_info["account_domain"],
credential=account_info["key_credential"])
with pytest.raises(ValueError):
RemoteRenderingClient(
endpoint=account_info["service_endpoint"],
account_id=account_info["account_id"],
account_domain=None,
credential=account_info["key_credential"])
with pytest.raises(ValueError):
RemoteRenderingClient(
endpoint=account_info["service_endpoint"],
account_id=account_info["account_id"],
account_domain=account_info["account_domain"],
credential=None)
with pytest.raises(ValueError):
RemoteRenderingClient(
endpoint=account_info["service_endpoint"],
account_id=account_info["account_id"],
account_domain=account_info["account_domain"],
credential=account_info["key_credential"],
authentication_endpoint_url="#")
def test_simple_conversion(self, recorded_test, account_info, arr_client):
conversion_id = account_info["id_placeholder"]
if self.is_live:
conversion_id += str(uuid.uuid4())
storage_container_uri = "https://"+account_info["storage_account_name"] + \
".blob."+account_info["storage_endpoint_suffix"]+"/"+account_info["blob_container_name"]
input_settings = AssetConversionInputSettings(
storage_container_uri=storage_container_uri,
relative_input_asset_path="testBox.fbx",
blob_prefix="Input",
storage_container_read_list_sas="?"+account_info["sas_token"]
)
output_settings = AssetConversionOutputSettings(
storage_container_uri=storage_container_uri,
blob_prefix=conversion_id,
storage_container_write_sas="?"+account_info["sas_token"]
)
conversion_poller = arr_client.begin_asset_conversion(
conversion_id=conversion_id, input_settings=input_settings, output_settings=output_settings
)
conversion = arr_client.get_asset_conversion(conversion_id)
assert conversion.id == conversion_id
assert conversion.settings.input_settings.relative_input_asset_path == input_settings.relative_input_asset_path
assert conversion.status != AssetConversionStatus.FAILED
finished_conversion = conversion_poller.result()
assert finished_conversion.id == conversion_id
assert finished_conversion.settings.input_settings.relative_input_asset_path == input_settings.relative_input_asset_path
assert finished_conversion.status == AssetConversionStatus.SUCCEEDED
finished_conversion.output.asset_uri.endswith(conversion_id+"/testBox.arrAsset")
foundConversion = False
conversions = arr_client.list_asset_conversions()
for c in conversions:
if(c.id == conversion_id):
foundConversion = True
break
assert foundConversion == True
def test_failed_conversion_unauthorized(self, recorded_test, account_info):
client = RemoteRenderingClient(
endpoint=account_info["service_endpoint"],
account_id=account_info["account_id"],
account_domain=account_info["account_domain"],
credential=AzureKeyCredential("wrong_key")
)
conversion_id = account_info["id_placeholder"]
if self.is_live:
conversion_id += str(uuid.uuid4())
storage_container_uri = "https://"+account_info["storage_account_name"] + \
".blob."+account_info["storage_endpoint_suffix"]+"/"+account_info["blob_container_name"]
input_settings = AssetConversionInputSettings(
storage_container_uri=storage_container_uri,
relative_input_asset_path="testBox.fbx",
blob_prefix="Input"
# Do not provide SAS access to the container, and assume the test account is not linked to the storage.
)
output_settings = AssetConversionOutputSettings(
storage_container_uri=storage_container_uri,
blob_prefix=conversion_id
# Do not provide SAS access to the container, and assume the test account is not linked to the storage.
)
with pytest.raises(HttpResponseError) as excinfo:
# make the request which cannot access the storage account
conversion_poller = client.begin_asset_conversion(
conversion_id=conversion_id, input_settings=input_settings, output_settings=output_settings
)
exception = excinfo.value
assert exception.status_code == 401
assert "Unauthorized" in exception.message
def test_failed_conversion_no_access(self, recorded_test, account_info, arr_client):
conversion_id = account_info["id_placeholder"]
if self.is_live:
conversion_id += str(uuid.uuid4())
storage_container_uri = "https://"+account_info["storage_account_name"] + \
".blob."+account_info["storage_endpoint_suffix"]+"/"+account_info["blob_container_name"]
input_settings = AssetConversionInputSettings(
storage_container_uri=storage_container_uri,
relative_input_asset_path="testBox.fbx",
blob_prefix="Input"
# Do not provide SAS access to the container, and assume the test account is not linked to the storage.
)
output_settings = AssetConversionOutputSettings(
storage_container_uri=storage_container_uri,
blob_prefix=conversion_id
# Do not provide SAS access to the container, and assume the test account is not linked to the storage.
)
with pytest.raises(HttpResponseError) as excinfo:
# make the request which cannot access the storage account
conversion_poller = arr_client.begin_asset_conversion(
conversion_id=conversion_id, input_settings=input_settings, output_settings=output_settings
)
assert excinfo.value.status_code == 403
error_details = excinfo.value
assert "storage" in error_details.message
assert "permissions" in error_details.message
def test_failed_conversion_missing_asset(self, recorded_test, account_info, arr_client):
conversion_id = account_info["id_placeholder"]
if self.is_live:
conversion_id += str(uuid.uuid4())
storage_container_uri = "https://"+account_info["storage_account_name"] + \
".blob."+account_info["storage_endpoint_suffix"]+"/"+account_info["blob_container_name"]
input_settings = AssetConversionInputSettings(
storage_container_uri=storage_container_uri,
relative_input_asset_path="testBoxWhichDoesNotExist.fbx",
blob_prefix="Input",
storage_container_read_list_sas="?"+account_info["sas_token"]
)
output_settings = AssetConversionOutputSettings(
storage_container_uri=storage_container_uri,
blob_prefix=conversion_id,
storage_container_write_sas="?"+account_info["sas_token"]
)
with pytest.raises(HttpResponseError) as excinfo:
# make the request which fails in polling because of the missing asset
conversion_poller = arr_client.begin_asset_conversion(
conversion_id=conversion_id, input_settings=input_settings, output_settings=output_settings)
conversion_poller.result()
error_details = excinfo.value
assert "invalid input" in error_details.error.message.lower()
assert "logs" in error_details.error.message.lower()
def test_simple_session(self, recorded_test, account_info, arr_client):
session_id = account_info["id_placeholder"]
if self.is_live:
session_id += str(uuid.uuid4())
session_poller = arr_client.begin_rendering_session(
session_id=session_id, size=RenderingSessionSize.STANDARD, lease_time_minutes=15)
session = arr_client.get_rendering_session(session_id)
assert session.id == session_id
assert session.size == RenderingSessionSize.STANDARD
assert session.lease_time_minutes == 15
assert session.status != RenderingSessionStatus.ERROR
ready_session = session_poller.result()
assert ready_session.id == session_id
assert ready_session.size == RenderingSessionSize.STANDARD
assert ready_session.lease_time_minutes == 15
assert ready_session.status == RenderingSessionStatus.READY
assert ready_session.hostname
assert ready_session.arr_inspector_port is not None
assert ready_session.handshake_port is not None
extended_session = arr_client.update_rendering_session(session_id=session_id, lease_time_minutes=20)
assert extended_session.id == session_id
assert extended_session.size == RenderingSessionSize.STANDARD
assert extended_session.lease_time_minutes == 15 or extended_session.lease_time_minutes == 20
assert extended_session.status == RenderingSessionStatus.READY
foundSession = False
for s in arr_client.list_rendering_sessions():
if s.id == session_id:
foundSession = True
break
assert foundSession == True
arr_client.stop_rendering_session(session_id)
stopped_session = arr_client.get_rendering_session(session_id)
assert stopped_session.status == RenderingSessionStatus.STOPPED
def test_failed_session_request(self, recorded_test, account_info, arr_client):
session_id = account_info["id_placeholder"]
if self.is_live:
session_id += str(uuid.uuid4())
with pytest.raises(HttpResponseError) as excinfo:
# Make an invalid request (negative lease time).
session_poller = arr_client.begin_rendering_session(
session_id=session_id, size=RenderingSessionSize.STANDARD, lease_time_minutes=-4)
assert excinfo.value.status_code == 400
exception = excinfo.value
assert "lease" in exception.message.lower()
assert "negative" in exception.message.lower()
|