Skip to content

Commit d1a86c8

Browse files
committed
feat: add more tests
1 parent f3d0531 commit d1a86c8

1 file changed

Lines changed: 143 additions & 0 deletions

File tree

‎packages/uipath-platform/tests/services/test_attachments_service.py‎

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,149 @@ def test_attachments_service_conforms_to_attachments_protocol(
12301230
assert isinstance(conforming, AttachmentsProtocol)
12311231

12321232

1233+
class TestAttachmentsServiceTimeout:
1234+
"""Tests for custom timeout parameter in upload methods."""
1235+
1236+
def test_upload_with_custom_timeout(
1237+
self,
1238+
httpx_mock: HTTPXMock,
1239+
service: AttachmentsService,
1240+
base_url: str,
1241+
org: str,
1242+
tenant: str,
1243+
blob_uri_response: dict[str, Any],
1244+
) -> None:
1245+
"""Test that custom timeout is accepted in sync upload."""
1246+
content = "Test content"
1247+
file_name = "test.txt"
1248+
1249+
httpx_mock.add_response(
1250+
url=f"{base_url}{org}{tenant}/orchestrator_/odata/Attachments",
1251+
method="POST",
1252+
status_code=200,
1253+
json=blob_uri_response,
1254+
)
1255+
1256+
httpx_mock.add_response(
1257+
url=blob_uri_response["BlobFileAccess"]["Uri"],
1258+
method="PUT",
1259+
status_code=201,
1260+
)
1261+
1262+
# Pass custom timeout - this exercises the timeout parameter path
1263+
attachment_key = service.upload(
1264+
name=file_name,
1265+
content=content,
1266+
timeout=120.0,
1267+
)
1268+
1269+
assert attachment_key == uuid.UUID(blob_uri_response["Id"])
1270+
1271+
def test_upload_with_file_path_custom_timeout(
1272+
self,
1273+
httpx_mock: HTTPXMock,
1274+
service: AttachmentsService,
1275+
base_url: str,
1276+
org: str,
1277+
tenant: str,
1278+
temp_file: Tuple[str, str, str],
1279+
blob_uri_response: dict[str, Any],
1280+
) -> None:
1281+
"""Test that custom timeout is accepted in sync upload from file."""
1282+
content, file_name, file_path = temp_file
1283+
1284+
httpx_mock.add_response(
1285+
url=f"{base_url}{org}{tenant}/orchestrator_/odata/Attachments",
1286+
method="POST",
1287+
status_code=200,
1288+
json=blob_uri_response,
1289+
)
1290+
1291+
httpx_mock.add_response(
1292+
url=blob_uri_response["BlobFileAccess"]["Uri"],
1293+
method="PUT",
1294+
status_code=201,
1295+
)
1296+
1297+
attachment_key = service.upload(
1298+
name=file_name,
1299+
source_path=file_path,
1300+
timeout=90.0,
1301+
)
1302+
1303+
assert attachment_key == uuid.UUID(blob_uri_response["Id"])
1304+
1305+
@pytest.mark.asyncio
1306+
async def test_upload_async_with_custom_timeout(
1307+
self,
1308+
httpx_mock: HTTPXMock,
1309+
service: AttachmentsService,
1310+
base_url: str,
1311+
org: str,
1312+
tenant: str,
1313+
blob_uri_response: dict[str, Any],
1314+
) -> None:
1315+
"""Test that custom timeout is accepted in async upload."""
1316+
content = "Test content async"
1317+
file_name = "test_async.txt"
1318+
1319+
httpx_mock.add_response(
1320+
url=f"{base_url}{org}{tenant}/orchestrator_/odata/Attachments",
1321+
method="POST",
1322+
status_code=200,
1323+
json=blob_uri_response,
1324+
)
1325+
1326+
httpx_mock.add_response(
1327+
url=blob_uri_response["BlobFileAccess"]["Uri"],
1328+
method="PUT",
1329+
status_code=201,
1330+
)
1331+
1332+
attachment_key = await service.upload_async(
1333+
name=file_name,
1334+
content=content,
1335+
timeout=150.0,
1336+
)
1337+
1338+
assert attachment_key == uuid.UUID(blob_uri_response["Id"])
1339+
1340+
@pytest.mark.asyncio
1341+
async def test_upload_async_with_file_path_custom_timeout(
1342+
self,
1343+
httpx_mock: HTTPXMock,
1344+
service: AttachmentsService,
1345+
base_url: str,
1346+
org: str,
1347+
tenant: str,
1348+
temp_file: Tuple[str, str, str],
1349+
blob_uri_response: dict[str, Any],
1350+
) -> None:
1351+
"""Test that custom timeout is accepted in async upload from file."""
1352+
content, file_name, file_path = temp_file
1353+
1354+
httpx_mock.add_response(
1355+
url=f"{base_url}{org}{tenant}/orchestrator_/odata/Attachments",
1356+
method="POST",
1357+
status_code=200,
1358+
json=blob_uri_response,
1359+
)
1360+
1361+
httpx_mock.add_response(
1362+
url=blob_uri_response["BlobFileAccess"]["Uri"],
1363+
method="PUT",
1364+
status_code=201,
1365+
)
1366+
1367+
attachment_key = await service.upload_async(
1368+
name=file_name,
1369+
source_path=file_path,
1370+
timeout=180.0,
1371+
)
1372+
1373+
assert attachment_key == uuid.UUID(blob_uri_response["Id"])
1374+
1375+
12331376
class TestAttachmentsServiceRequiresAuth:
12341377
"""Tests for uploads when RequiresAuth is True (uses self.request with timeout)."""
12351378

0 commit comments

Comments
 (0)