File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -741,6 +741,47 @@ def test_staging_ingestion_put_fails_if_localFile_not_in_uploads_base_path(self)
741
741
query = f"PUT '{ temp_path } ' INTO 'stage://tmp/{ self .staging_ingestion_user } /tmp/11/15/file1.csv' OVERWRITE"
742
742
cursor .execute (query )
743
743
744
+ def test_staging_ingestion_put_fails_if_file_exists_and_overwrite_not_set (self ):
745
+ """PUT a file into the staging location twice. First command should succeed. Second should fail.
746
+ """
747
+
748
+ fh , temp_path = tempfile .mkstemp ()
749
+
750
+ original_text = "hello world!" .encode ("utf-8" )
751
+
752
+ with open (fh , "wb" ) as fp :
753
+ fp .write (original_text )
754
+
755
+ def perform_put ():
756
+ with self .connection (extra_params = {"uploads_base_path" : temp_path }) as conn :
757
+ cursor = conn .cursor ()
758
+ query = f"PUT '{ temp_path } ' INTO 'stage://tmp/{ self .staging_ingestion_user } /tmp/12/15/file1.csv'"
759
+ cursor .execute (query )
760
+
761
+ def perform_remove ():
762
+ remove_query = (
763
+ f"REMOVE 'stage://tmp/{ self .staging_ingestion_user } /tmp/12/15/file1.csv'"
764
+ )
765
+
766
+ with self .connection (extra_params = {"uploads_base_path" : "/" }) as conn :
767
+ cursor = conn .cursor ()
768
+ cursor .execute (remove_query )
769
+
770
+
771
+ # Make sure file does not exist
772
+ perform_remove ()
773
+
774
+ # Put the file
775
+ perform_put ()
776
+
777
+ # Try to put it again
778
+ with pytest .raises (sql .exc .ServerOperationError ):
779
+ perform_put ()
780
+
781
+ # Clean up after ourselves
782
+ perform_remove ()
783
+
784
+
744
785
def test_staging_ingestion_put_fails_if_absolute_localFile_not_in_uploads_base_path (self ):
745
786
"""
746
787
This test confirms that uploads_base_path and target_file are resolved into absolute paths.
You can’t perform that action at this time.
0 commit comments