@@ -70,9 +70,9 @@ def test_put_success_returns_self(self):
70
70
test_input = [1 , 2 , 3 ]
71
71
result = blob .put (test_input )
72
72
# Should return the blob itself (self) on success
73
- self .assertIsInstance (result , LocalFileBlob )
74
- self .assertEqual (result , blob )
75
-
73
+ self .assertIsInstance (result , StorageExportResult )
74
+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
75
+
76
76
def test_put_file_write_error_returns_string (self ):
77
77
blob = LocalFileBlob (os .path .join (TEST_FOLDER , "write_error_blob" ))
78
78
test_input = [1 , 2 , 3 ]
@@ -129,8 +129,8 @@ def test_put_with_lease_period_success(self):
129
129
lease_period = 60
130
130
131
131
result = blob .put (test_input , lease_period = lease_period )
132
- self .assertIsInstance (result , LocalFileBlob )
133
- self .assertEqual (result , blob )
132
+ self .assertIsInstance (result , StorageExportResult )
133
+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
134
134
# File should have .lock extension due to lease period
135
135
self .assertTrue (blob .fullpath .endswith (".lock" ))
136
136
@@ -150,17 +150,17 @@ def test_put_empty_data_success(self):
150
150
empty_data = []
151
151
152
152
result = blob .put (empty_data )
153
- self .assertIsInstance (result , LocalFileBlob )
154
- self .assertEqual (result , blob )
153
+ self .assertIsInstance (result , StorageExportResult )
154
+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
155
155
156
156
def test_put_large_data_success (self ):
157
157
blob = LocalFileBlob (os .path .join (TEST_FOLDER , "large_data_blob" ))
158
158
# Create a large list of data
159
159
large_data = [{"id" : i , "value" : f"data_{ i } " } for i in range (1000 )]
160
160
161
161
result = blob .put (large_data )
162
- self .assertIsInstance (result , LocalFileBlob )
163
- self .assertEqual (result , blob )
162
+ self .assertIsInstance (result , StorageExportResult )
163
+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
164
164
165
165
# Verify data can be retrieved
166
166
retrieved_data = blob .get ()
@@ -174,13 +174,25 @@ def test_put_return_type_consistency(self):
174
174
175
175
# Test successful case
176
176
result_success = blob .put (test_input )
177
- self .assertTrue (isinstance (result_success , LocalFileBlob ) or isinstance (result_success , str ))
177
+ self .assertTrue (isinstance (result_success , StorageExportResult ) or isinstance (result_success , str ))
178
178
179
179
# Test error case
180
180
blob2 = LocalFileBlob (os .path .join (TEST_FOLDER , "consistency_blob2" ))
181
181
with mock .patch ("os.rename" , side_effect = Exception ("Test error" )):
182
182
result_error = blob2 .put (test_input )
183
183
self .assertIsInstance (result_error , str )
184
+
185
+ def test_put_invalid_return_type (self ):
186
+ blob = LocalFileBlob (os .path .join (TEST_FOLDER , "invalid_return_blob" ))
187
+ test_input = [1 , 2 , 3 ]
188
+
189
+ # This tests that even if os.rename somehow returns something unexpected,
190
+ # the put method still maintains its type contract
191
+ with mock .patch ("os.rename" , return_value = 42 ):
192
+ result = blob .put (test_input )
193
+ # Should either convert to string or return StorageExportResult
194
+ self .assertTrue (isinstance (result , (StorageExportResult , str )),
195
+ f"Expected StorageExportResult or str, got { type (result )} " )
184
196
185
197
@unittest .skip ("transient storage" )
186
198
def test_put (self ):
@@ -334,7 +346,7 @@ def test_put_success_returns_localfileblob(self):
334
346
test_input = (1 , 2 , 3 )
335
347
with LocalFileStorage (os .path .join (TEST_FOLDER , "success_test" )) as stor :
336
348
result = stor .put (test_input , lease_period = 0 ) # No lease period so file is immediately available
337
- self .assertIsInstance (result , LocalFileBlob )
349
+ self .assertIsInstance (result , StorageExportResult )
338
350
self .assertEqual (stor .get ().get (), test_input )
339
351
340
352
def test_put_blob_put_failure_returns_string (self ):
@@ -379,19 +391,19 @@ def test_put_with_lease_period(self):
379
391
380
392
with LocalFileStorage (os .path .join (TEST_FOLDER , "lease_test" )) as stor :
381
393
result = stor .put (test_input , lease_period = custom_lease_period )
382
- self .assertIsInstance (result , LocalFileBlob )
394
+ self .assertIsInstance (result , StorageExportResult )
383
395
# Verify the file was created with lease period
384
- self .assertTrue (result . fullpath . endswith ( ".lock" ) )
396
+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
385
397
386
398
def test_put_default_lease_period (self ):
387
399
test_input = (1 , 2 , 3 )
388
400
389
401
with LocalFileStorage (os .path .join (TEST_FOLDER , "default_lease_test" ), lease_period = 90 ) as stor :
390
402
result = stor .put (test_input )
391
- self .assertIsInstance (result , LocalFileBlob )
403
+ self .assertIsInstance (result , StorageExportResult )
392
404
# File should be created with lease (since default lease_period > 0)
393
- self .assertTrue (result . fullpath . endswith ( ".lock" ) )
394
-
405
+ self .assertEqual (result , StorageExportResult . LOCAL_FILE_BLOB_SUCCESS )
406
+
395
407
def test_check_and_set_folder_permissions_oserror_sets_exception_state (self ):
396
408
test_input = (1 , 2 , 3 )
397
409
test_error_message = "OSError: Permission denied creating directory"
@@ -671,7 +683,7 @@ def test_exception_state_cleared_and_storage_recovery(self):
671
683
with LocalFileStorage (os .path .join (TEST_FOLDER , "recovery_test2" )) as stor2 :
672
684
if stor2 ._enabled : # Storage should be enabled now
673
685
result = stor2 .put (test_input , lease_period = 0 )
674
- self .assertIsInstance (result , LocalFileBlob )
686
+ self .assertIsInstance (result , StorageExportResult )
675
687
retrieved_data = stor2 .get ().get ()
676
688
self .assertEqual (retrieved_data , test_input )
677
689
@@ -740,6 +752,17 @@ def test_readonly_state_interaction_with_storage_put_method(self):
740
752
# When storage is disabled and readonly state is set, put() should return CLIENT_READONLY
741
753
result = stor .put (test_input )
742
754
self .assertEqual (result , StorageExportResult .CLIENT_READONLY )
755
+
756
+ def test_storage_put_invalid_return_type (self ):
757
+ test_input = (1 , 2 , 3 )
758
+
759
+ with LocalFileStorage (os .path .join (TEST_FOLDER , "invalid_return_test" )) as stor :
760
+ # Mock _check_storage_size to return a non-boolean value
761
+ with mock .patch .object (stor , '_check_storage_size' , return_value = 42 ):
762
+ result = stor .put (test_input )
763
+ # Should maintain return type contract despite invalid internal return
764
+ self .assertTrue (isinstance (result , (StorageExportResult , str )),
765
+ f"Expected StorageExportResult or str, got { type (result )} " )
743
766
744
767
def test_readonly_state_priority_over_exception_state (self ):
745
768
test_input = (1 , 2 , 3 )
0 commit comments