1010
1111namespace OpenAI . Tests . Files ;
1212
13- [ Parallelizable ( ParallelScope . Fixtures ) ]
1413[ Category ( "Uploads" ) ]
1514public class UploadsTests : OpenAIRecordedTestBase
1615{
@@ -29,7 +28,7 @@ public async Task CreateUploadWorks(bool useTopLevelClient)
2928 // are setting the internal Uploads client correctly.
3029
3130 OpenAIFileClient fileClient = useTopLevelClient
32- ? CreateProxyFromClient ( TestHelpers . GetTestTopLevelClient ( ) . GetOpenAIFileClient ( ) )
31+ ? GetProxiedTestTopLevelClient ( ) . GetOpenAIFileClient ( )
3332 : GetTestClient ( ) ;
3433 BinaryContent content = BinaryContent . Create ( BinaryData . FromObjectAsJson ( new
3534 {
@@ -60,77 +59,83 @@ public async Task CreateUploadWorks(bool useTopLevelClient)
6059 [ Test ]
6160 public async Task AddUploadPartWorks ( )
6261 {
63- OpenAIFileClient fileClient = GetTestClient ( ) ;
64- UploadDetails uploadDetails = await CreateTestUploadAsync ( fileClient ) ;
65- using MultiPartFormDataBinaryContent content = new ( ) ;
66-
67- content . Add ( [ 1 , 2 , 3 , 4 ] , "data" , "data" , "application/octet-stream" ) ;
68-
69- ClientResult result = await fileClient . AddUploadPartAsync ( uploadDetails . Id , content , content . ContentType ) ;
70- BinaryData response = result . GetRawResponse ( ) . Content ;
71- using JsonDocument jsonDocument = JsonDocument . Parse ( response ) ;
72- UploadPartDetails uploadPartDetails = GetUploadPartDetails ( jsonDocument ) ;
73-
74- Assert . That ( uploadPartDetails . Id , Does . StartWith ( "part_" ) ) ;
75- Assert . That ( uploadPartDetails . Object , Is . EqualTo ( "upload.part" ) ) ;
76- Assert . That ( uploadPartDetails . CreatedAt , Is . GreaterThanOrEqualTo ( uploadDetails . CreatedAt ) ) ;
77- Assert . That ( uploadPartDetails . UploadId , Is . EqualTo ( uploadDetails . Id ) ) ;
62+ using ( Recording . DisableRequestBodyRecording ( ) ) // Temp pending https://github.com/Azure/azure-sdk-tools/issues/11901
63+ {
64+ OpenAIFileClient fileClient = GetTestClient ( ) ;
65+ UploadDetails uploadDetails = await CreateTestUploadAsync ( fileClient ) ;
66+ using MultiPartFormDataBinaryContent content = new ( ) ;
67+
68+ content . Add ( [ 1 , 2 , 3 , 4 ] , "data" , "data" , "application/octet-stream" ) ;
69+
70+ ClientResult result = await fileClient . AddUploadPartAsync ( uploadDetails . Id , content , content . ContentType ) ;
71+ BinaryData response = result . GetRawResponse ( ) . Content ;
72+ using JsonDocument jsonDocument = JsonDocument . Parse ( response ) ;
73+ UploadPartDetails uploadPartDetails = GetUploadPartDetails ( jsonDocument ) ;
74+
75+ Assert . That ( uploadPartDetails . Id , Does . StartWith ( "part_" ) ) ;
76+ Assert . That ( uploadPartDetails . Object , Is . EqualTo ( "upload.part" ) ) ;
77+ Assert . That ( uploadPartDetails . CreatedAt , Is . GreaterThanOrEqualTo ( uploadDetails . CreatedAt ) ) ;
78+ Assert . That ( uploadPartDetails . UploadId , Is . EqualTo ( uploadDetails . Id ) ) ;
79+ }
7880 }
7981
8082 [ Test ]
8183 public async Task CompleteUploadWorks ( )
8284 {
83- OpenAIFileClient fileClient = GetTestClient ( ) ;
84- UploadDetails createdUploadDetails = await CreateTestUploadAsync ( fileClient ) ;
85- using MultiPartFormDataBinaryContent firstPartContent = new ( ) ;
86- using MultiPartFormDataBinaryContent secondPartContent = new ( ) ;
85+ using ( Recording . DisableRequestBodyRecording ( ) ) // Temp pending https://github.com/Azure/azure-sdk-tools/issues/11901
86+ {
87+ OpenAIFileClient fileClient = GetTestClient ( ) ;
88+ UploadDetails createdUploadDetails = await CreateTestUploadAsync ( fileClient ) ;
89+ using MultiPartFormDataBinaryContent firstPartContent = new ( ) ;
90+ using MultiPartFormDataBinaryContent secondPartContent = new ( ) ;
8791
88- firstPartContent . Add ( [ 1 , 2 , 3 , 4 ] , "data" , "data" , "application/octet-stream" ) ;
89- secondPartContent . Add ( [ 5 , 6 , 7 , 8 ] , "data" , "data" , "application/octet-stream" ) ;
92+ firstPartContent . Add ( [ 1 , 2 , 3 , 4 ] , "data" , "data" , "application/octet-stream" ) ;
93+ secondPartContent . Add ( [ 5 , 6 , 7 , 8 ] , "data" , "data" , "application/octet-stream" ) ;
9094
91- UploadPartDetails firstPartDetails = await AddTestUploadPartAsync ( fileClient , createdUploadDetails . Id , firstPartContent ) ;
92- UploadPartDetails secondPartDetails = await AddTestUploadPartAsync ( fileClient , createdUploadDetails . Id , secondPartContent ) ;
95+ UploadPartDetails firstPartDetails = await AddTestUploadPartAsync ( fileClient , createdUploadDetails . Id , firstPartContent ) ;
96+ UploadPartDetails secondPartDetails = await AddTestUploadPartAsync ( fileClient , createdUploadDetails . Id , secondPartContent ) ;
9397
94- BinaryContent content = BinaryContent . Create ( BinaryData . FromObjectAsJson ( new
95- {
96- part_ids = new [ ] {
98+ BinaryContent content = BinaryContent . Create ( BinaryData . FromObjectAsJson ( new
99+ {
100+ part_ids = new [ ] {
97101 firstPartDetails . Id ,
98102 secondPartDetails . Id
99103 }
100- } ) ) ;
101-
102- ClientResult result = await fileClient . CompleteUploadAsync ( createdUploadDetails . Id , content ) ;
103-
104- BinaryData response = result . GetRawResponse ( ) . Content ;
105- using JsonDocument jsonDocument = JsonDocument . Parse ( response ) ;
106- JsonElement fileElement = jsonDocument . RootElement . GetProperty ( "file" ) ;
107- string fileId = fileElement . GetProperty ( "id" ) . GetString ( ) ;
108-
109- await fileClient . DeleteFileAsync ( fileId ) ;
110-
111- UploadDetails completedUploadDetails = GetUploadDetails ( jsonDocument ) ;
112-
113- Assert . That ( completedUploadDetails . Id , Is . EqualTo ( createdUploadDetails . Id ) ) ;
114- Assert . That ( completedUploadDetails . Object , Is . EqualTo ( createdUploadDetails . Object ) ) ;
115- Assert . That ( completedUploadDetails . Bytes , Is . EqualTo ( createdUploadDetails . Bytes ) ) ;
116- Assert . That ( completedUploadDetails . CreatedAt , Is . EqualTo ( createdUploadDetails . CreatedAt ) ) ;
117- Assert . That ( completedUploadDetails . Filename , Is . EqualTo ( createdUploadDetails . Filename ) ) ;
118- Assert . That ( completedUploadDetails . Purpose , Is . EqualTo ( createdUploadDetails . Purpose ) ) ;
119- Assert . That ( completedUploadDetails . Status , Is . EqualTo ( "completed" ) ) ;
120- Assert . That ( completedUploadDetails . ExpiresAt , Is . EqualTo ( createdUploadDetails . ExpiresAt ) ) ;
121-
122- string fileObject = fileElement . GetProperty ( "object" ) . GetString ( ) ;
123- int fileBytes = fileElement . GetProperty ( "bytes" ) . GetInt32 ( ) ;
124- long fileCreatedAt = fileElement . GetProperty ( "created_at" ) . GetInt64 ( ) ;
125- string filename = fileElement . GetProperty ( "filename" ) . GetString ( ) ;
126- string filePurpose = fileElement . GetProperty ( "purpose" ) . GetString ( ) ;
127-
128- Assert . That ( fileId , Does . StartWith ( "file-" ) ) ;
129- Assert . That ( fileObject , Is . EqualTo ( "file" ) ) ;
130- Assert . That ( fileBytes , Is . EqualTo ( createdUploadDetails . Bytes ) ) ;
131- Assert . That ( fileCreatedAt , Is . GreaterThanOrEqualTo ( createdUploadDetails . CreatedAt ) ) ;
132- Assert . That ( filename , Is . EqualTo ( createdUploadDetails . Filename ) ) ;
133- Assert . That ( filePurpose , Is . EqualTo ( createdUploadDetails . Purpose ) ) ;
104+ } ) ) ;
105+
106+ ClientResult result = await fileClient . CompleteUploadAsync ( createdUploadDetails . Id , content ) ;
107+
108+ BinaryData response = result . GetRawResponse ( ) . Content ;
109+ using JsonDocument jsonDocument = JsonDocument . Parse ( response ) ;
110+ JsonElement fileElement = jsonDocument . RootElement . GetProperty ( "file" ) ;
111+ string fileId = fileElement . GetProperty ( "id" ) . GetString ( ) ;
112+
113+ await fileClient . DeleteFileAsync ( fileId ) ;
114+
115+ UploadDetails completedUploadDetails = GetUploadDetails ( jsonDocument ) ;
116+
117+ Assert . That ( completedUploadDetails . Id , Is . EqualTo ( createdUploadDetails . Id ) ) ;
118+ Assert . That ( completedUploadDetails . Object , Is . EqualTo ( createdUploadDetails . Object ) ) ;
119+ Assert . That ( completedUploadDetails . Bytes , Is . EqualTo ( createdUploadDetails . Bytes ) ) ;
120+ Assert . That ( completedUploadDetails . CreatedAt , Is . EqualTo ( createdUploadDetails . CreatedAt ) ) ;
121+ Assert . That ( completedUploadDetails . Filename , Is . EqualTo ( createdUploadDetails . Filename ) ) ;
122+ Assert . That ( completedUploadDetails . Purpose , Is . EqualTo ( createdUploadDetails . Purpose ) ) ;
123+ Assert . That ( completedUploadDetails . Status , Is . EqualTo ( "completed" ) ) ;
124+ Assert . That ( completedUploadDetails . ExpiresAt , Is . EqualTo ( createdUploadDetails . ExpiresAt ) ) ;
125+
126+ string fileObject = fileElement . GetProperty ( "object" ) . GetString ( ) ;
127+ int fileBytes = fileElement . GetProperty ( "bytes" ) . GetInt32 ( ) ;
128+ long fileCreatedAt = fileElement . GetProperty ( "created_at" ) . GetInt64 ( ) ;
129+ string filename = fileElement . GetProperty ( "filename" ) . GetString ( ) ;
130+ string filePurpose = fileElement . GetProperty ( "purpose" ) . GetString ( ) ;
131+
132+ Assert . That ( fileId , Does . StartWith ( "file-" ) ) ;
133+ Assert . That ( fileObject , Is . EqualTo ( "file" ) ) ;
134+ Assert . That ( fileBytes , Is . EqualTo ( createdUploadDetails . Bytes ) ) ;
135+ Assert . That ( fileCreatedAt , Is . GreaterThanOrEqualTo ( createdUploadDetails . CreatedAt ) ) ;
136+ Assert . That ( filename , Is . EqualTo ( createdUploadDetails . Filename ) ) ;
137+ Assert . That ( filePurpose , Is . EqualTo ( createdUploadDetails . Purpose ) ) ;
138+ }
134139 }
135140
136141 [ Test ]
@@ -160,7 +165,7 @@ private async Task<UploadDetails> CreateTestUploadAsync(OpenAIFileClient fileCli
160165 BinaryContent content = BinaryContent . Create ( BinaryData . FromObjectAsJson ( new
161166 {
162167 purpose = "fine-tune" ,
163- filename = "uploads_test_file" + Guid . NewGuid ( ) + ".jsonl" ,
168+ filename = "uploads_test_file" + Recording . Random . NewGuid ( ) + ".jsonl" ,
164169 bytes = 8 ,
165170 mime_type = "text/jsonl"
166171 } ) ) ;
0 commit comments