@@ -154,6 +154,67 @@ def file(tmp_path: Path, uuid_factory: Callable[[], str]) -> FileForTesting:
154
154
)
155
155
156
156
157
+ @pytest .fixture
158
+ def two_files (tmp_path : Path , uuid_factory : Callable [[], str ]) -> list [FileForTesting ]:
159
+ """Creates multiple test files (different content, same bucket/folder path, different file names)"""
160
+ file_name_1 = "test_image_1.svg"
161
+ file_name_2 = "test_image_2.svg"
162
+ file_content = (
163
+ b'<svg width="109" height="113" viewBox="0 0 109 113" fill="none" xmlns="http://www.w3.org/2000/svg"> '
164
+ b'<path d="M63.7076 110.284C60.8481 113.885 55.0502 111.912 54.9813 107.314L53.9738 40.0627L99.1935 '
165
+ b'40.0627C107.384 40.0627 111.952 49.5228 106.859 55.9374L63.7076 110.284Z" fill="url(#paint0_linear)"/> '
166
+ b'<path d="M63.7076 110.284C60.8481 113.885 55.0502 111.912 54.9813 107.314L53.9738 40.0627L99.1935 '
167
+ b'40.0627C107.384 40.0627 111.952 49.5228 106.859 55.9374L63.7076 110.284Z" fill="url(#paint1_linear)" '
168
+ b'fill-opacity="0.2"/> <path d="M45.317 2.07103C48.1765 -1.53037 53.9745 0.442937 54.0434 5.041L54.4849 '
169
+ b'72.2922H9.83113C1.64038 72.2922 -2.92775 62.8321 2.1655 56.4175L45.317 2.07103Z" fill="#3ECF8E"/> <defs>'
170
+ b'<linearGradient id="paint0_linear" x1="53.9738" y1="54.974" x2="94.1635" y2="71.8295"'
171
+ b'gradientUnits="userSpaceOnUse"> <stop stop-color="#249361"/> <stop offset="1" stop-color="#3ECF8E"/> '
172
+ b'</linearGradient> <linearGradient id="paint1_linear" x1="36.1558" y1="30.578" x2="54.4844" y2="65.0806" '
173
+ b'gradientUnits="userSpaceOnUse"> <stop/> <stop offset="1" stop-opacity="0"/> </linearGradient> </defs> </svg>'
174
+ )
175
+ file_content_2 = (
176
+ b'<svg width="119" height="123" viewBox="0 0 119 123" fill="none" xmlns="http://www.w3.org/2000/svg"> '
177
+ b'<path d="M63.7076 110.284C60.8481 113.885 55.0502 111.912 54.9813 107.314L53.9738 40.0627L99.1935 '
178
+ b'40.0627C107.384 40.0627 111.952 49.5228 106.859 55.9374L63.7076 110.284Z" fill="url(#paint0_linear)"/> '
179
+ b'<path d="M63.7076 110.284C60.8481 113.885 55.0502 111.912 54.9813 107.314L53.9738 40.0627L99.1935 '
180
+ b'40.0627C107.384 40.0627 111.952 49.5228 106.859 55.9374L63.7076 110.284Z" fill="url(#paint1_linear)" '
181
+ b'fill-opacity="0.2"/> <path d="M45.317 2.07103C48.1765 -1.53037 53.9745 0.442937 54.0434 5.041L54.4849 '
182
+ b'72.2922H9.83113C1.64038 72.2922 -2.92775 62.8321 2.1655 56.4175L45.317 2.07103Z" fill="#3FDF8E"/> <defs>'
183
+ b'<linearGradient id="paint0_linear" x1="53.9738" y1="54.974" x2="94.1635" y2="71.8295"'
184
+ b'gradientUnits="userSpaceOnUse"> <stop stop-color="#249361"/> <stop offset="1" stop-color="#3FDF8E"/> '
185
+ b'</linearGradient> <linearGradient id="paint1_linear" x1="36.1558" y1="30.578" x2="54.4844" y2="65.0806" '
186
+ b'gradientUnits="userSpaceOnUse"> <stop/> <stop offset="1" stop-opacity="0"/> </linearGradient> </defs> </svg>'
187
+ )
188
+ bucket_folder = uuid_factory ()
189
+ bucket_path_1 = f"{ bucket_folder } /{ file_name_1 } "
190
+ bucket_path_2 = f"{ bucket_folder } /{ file_name_2 } "
191
+ file_path_1 = tmp_path / file_name_1
192
+ file_path_2 = tmp_path / file_name_2
193
+ with open (file_path_1 , "wb" ) as f :
194
+ f .write (file_content )
195
+ with open (file_path_2 , "wb" ) as f :
196
+ f .write (file_content_2 )
197
+
198
+ return [
199
+ FileForTesting (
200
+ name = file_name_1 ,
201
+ local_path = str (file_path_1 ),
202
+ bucket_folder = bucket_folder ,
203
+ bucket_path = bucket_path_1 ,
204
+ mime_type = "image/svg+xml" ,
205
+ file_content = file_content ,
206
+ ),
207
+ FileForTesting (
208
+ name = file_name_2 ,
209
+ local_path = str (file_path_2 ),
210
+ bucket_folder = bucket_folder ,
211
+ bucket_path = bucket_path_2 ,
212
+ mime_type = "image/svg+xml" ,
213
+ file_content = file_content_2 ,
214
+ ),
215
+ ]
216
+
217
+
157
218
@pytest .fixture
158
219
def multi_file (tmp_path : Path , uuid_factory : Callable [[], str ]) -> list [FileForTesting ]:
159
220
"""Creates multiple test files (same content, same bucket/folder path, different file names)"""
@@ -221,6 +282,33 @@ def test_client_upload(
221
282
assert image_info .get ("metadata" , {}).get ("mimetype" ) == file .mime_type
222
283
223
284
285
+ def test_client_update (
286
+ storage_file_client : SyncBucketProxy ,
287
+ two_files : list [FileForTesting ],
288
+ ) -> None :
289
+ """Ensure we can upload files to a bucket"""
290
+ storage_file_client .upload (
291
+ two_files [0 ].bucket_path ,
292
+ two_files [0 ].local_path ,
293
+ {"content-type" : two_files [0 ].mime_type },
294
+ )
295
+
296
+ storage_file_client .update (
297
+ two_files [0 ].bucket_path ,
298
+ two_files [1 ].local_path ,
299
+ {"content-type" : two_files [1 ].mime_type },
300
+ )
301
+
302
+ image = storage_file_client .download (two_files [0 ].bucket_path )
303
+ file_list = storage_file_client .list (two_files [0 ].bucket_folder )
304
+ image_info = next (
305
+ (f for f in file_list if f .get ("name" ) == two_files [0 ].name ), None
306
+ )
307
+
308
+ assert image == two_files [1 ].file_content
309
+ assert image_info .get ("metadata" , {}).get ("mimetype" ) == two_files [1 ].mime_type
310
+
311
+
224
312
@pytest .mark .parametrize (
225
313
"path" , ["foobar.txt" , "example/nested.jpg" , "/leading/slash.png" ]
226
314
)
0 commit comments