@@ -1597,6 +1597,7 @@ def test_download_batch_transform_result(
15971597 status_code = 200 ,
15981598 json = {
15991599 "uri" : "https://storage.example.com/result.csv" ,
1600+ "isEncrypted" : False ,
16001601 },
16011602 )
16021603
@@ -1670,6 +1671,7 @@ async def test_download_batch_transform_result_async(
16701671 status_code = 200 ,
16711672 json = {
16721673 "uri" : "https://storage.example.com/result.csv" ,
1674+ "isEncrypted" : False ,
16731675 },
16741676 )
16751677
@@ -1741,6 +1743,7 @@ def test_download_batch_transform_result_creates_nested_directories(
17411743 status_code = 200 ,
17421744 json = {
17431745 "uri" : "https://storage.example.com/result.csv" ,
1746+ "isEncrypted" : False ,
17441747 },
17451748 )
17461749
@@ -1760,6 +1763,68 @@ def test_download_batch_transform_result_creates_nested_directories(
17601763 assert destination .read_bytes () == b"col1,col2\n val1,val2"
17611764 assert destination .parent .exists ()
17621765
1766+ def test_download_batch_transform_result_encrypted (
1767+ self ,
1768+ httpx_mock : HTTPXMock ,
1769+ service : ContextGroundingService ,
1770+ base_url : str ,
1771+ org : str ,
1772+ tenant : str ,
1773+ version : str ,
1774+ tmp_path ,
1775+ ) -> None :
1776+ httpx_mock .add_response (
1777+ url = f"{ base_url } { org } { tenant } /ecs_/v2/batchRag/test-batch-id" ,
1778+ status_code = 200 ,
1779+ json = {
1780+ "id" : "test-batch-id" ,
1781+ "name" : "test-batch-transform" ,
1782+ "lastBatchRagStatus" : "Successful" ,
1783+ "prompt" : "Summarize documents" ,
1784+ "targetFileGlobPattern" : "**" ,
1785+ "useWebSearchGrounding" : False ,
1786+ "outputColumns" : [
1787+ {"name" : "summary" , "description" : "Document summary" }
1788+ ],
1789+ "createdDate" : "2024-01-15T10:30:00Z" ,
1790+ },
1791+ )
1792+
1793+ httpx_mock .add_response (
1794+ url = f"{ base_url } { org } { tenant } /ecs_/v2/batchRag/test-batch-id/GetReadUri" ,
1795+ status_code = 200 ,
1796+ json = {
1797+ "uri" : f"{ base_url } { org } { tenant } /ecs_/v2/batchRag/test-batch-id/DownloadBlob" ,
1798+ "isEncrypted" : True ,
1799+ },
1800+ )
1801+
1802+ httpx_mock .add_response (
1803+ url = f"{ base_url } { org } { tenant } /ecs_/v2/batchRag/test-batch-id/DownloadBlob" ,
1804+ status_code = 200 ,
1805+ content = b"encrypted,data\n val1,val2" ,
1806+ )
1807+
1808+ destination = tmp_path / "result_encrypted.csv"
1809+ service .download_batch_transform_result (
1810+ id = "test-batch-id" ,
1811+ destination_path = str (destination ),
1812+ )
1813+
1814+ assert destination .exists ()
1815+ assert destination .read_bytes () == b"encrypted,data\n val1,val2"
1816+
1817+ sent_requests = httpx_mock .get_requests ()
1818+ if sent_requests is None :
1819+ raise Exception ("No request was sent" )
1820+
1821+ # Verify the DownloadBlob endpoint was called with Authorization header
1822+ download_request = sent_requests [2 ]
1823+ assert download_request .method == "GET"
1824+ assert "/DownloadBlob" in str (download_request .url )
1825+ assert "Authorization" in download_request .headers
1826+ assert download_request .headers ["Authorization" ].startswith ("Bearer " )
1827+
17631828 def test_create_ephemeral_index (
17641829 self ,
17651830 httpx_mock : HTTPXMock ,
@@ -1903,6 +1968,7 @@ async def test_download_batch_transform_result_async_creates_nested_directories(
19031968 status_code = 200 ,
19041969 json = {
19051970 "uri" : "https://storage.example.com/result.csv" ,
1971+ "isEncrypted" : False ,
19061972 },
19071973 )
19081974
@@ -1921,3 +1987,66 @@ async def test_download_batch_transform_result_async_creates_nested_directories(
19211987 assert destination .exists ()
19221988 assert destination .read_bytes () == b"col1,col2\n val1,val2"
19231989 assert destination .parent .exists ()
1990+
1991+ @pytest .mark .anyio
1992+ async def test_download_batch_transform_result_async_encrypted (
1993+ self ,
1994+ httpx_mock : HTTPXMock ,
1995+ service : ContextGroundingService ,
1996+ base_url : str ,
1997+ org : str ,
1998+ tenant : str ,
1999+ version : str ,
2000+ tmp_path ,
2001+ ) -> None :
2002+ httpx_mock .add_response (
2003+ url = f"{ base_url } { org } { tenant } /ecs_/v2/batchRag/test-batch-id" ,
2004+ status_code = 200 ,
2005+ json = {
2006+ "id" : "test-batch-id" ,
2007+ "name" : "test-batch-transform" ,
2008+ "lastBatchRagStatus" : "Successful" ,
2009+ "prompt" : "Summarize documents" ,
2010+ "targetFileGlobPattern" : "**" ,
2011+ "useWebSearchGrounding" : False ,
2012+ "outputColumns" : [
2013+ {"name" : "summary" , "description" : "Document summary" }
2014+ ],
2015+ "createdDate" : "2024-01-15T10:30:00Z" ,
2016+ },
2017+ )
2018+
2019+ httpx_mock .add_response (
2020+ url = f"{ base_url } { org } { tenant } /ecs_/v2/batchRag/test-batch-id/GetReadUri" ,
2021+ status_code = 200 ,
2022+ json = {
2023+ "uri" : f"{ base_url } { org } { tenant } /ecs_/v2/batchRag/test-batch-id/DownloadBlob" ,
2024+ "isEncrypted" : True ,
2025+ },
2026+ )
2027+
2028+ httpx_mock .add_response (
2029+ url = f"{ base_url } { org } { tenant } /ecs_/v2/batchRag/test-batch-id/DownloadBlob" ,
2030+ status_code = 200 ,
2031+ content = b"encrypted,data\n val1,val2" ,
2032+ )
2033+
2034+ destination = tmp_path / "result_encrypted.csv"
2035+ await service .download_batch_transform_result_async (
2036+ id = "test-batch-id" ,
2037+ destination_path = str (destination ),
2038+ )
2039+
2040+ assert destination .exists ()
2041+ assert destination .read_bytes () == b"encrypted,data\n val1,val2"
2042+
2043+ sent_requests = httpx_mock .get_requests ()
2044+ if sent_requests is None :
2045+ raise Exception ("No request was sent" )
2046+
2047+ # Verify the DownloadBlob endpoint was called with Authorization header
2048+ download_request = sent_requests [2 ]
2049+ assert download_request .method == "GET"
2050+ assert "/DownloadBlob" in str (download_request .url )
2051+ assert "Authorization" in download_request .headers
2052+ assert download_request .headers ["Authorization" ].startswith ("Bearer " )
0 commit comments