Skip to content

Commit 891749f

Browse files
author
Jesse Whitehouse
committed
Add test: PUT fails if file already exists in staging location and OVERWRITE
is not set. Added after PR review Signed-off-by: Jesse Whitehouse <[email protected]>
1 parent 34a0362 commit 891749f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/e2e/driver_tests.py

+41
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,47 @@ def test_staging_ingestion_put_fails_if_localFile_not_in_uploads_base_path(self)
741741
query = f"PUT '{temp_path}' INTO 'stage://tmp/{self.staging_ingestion_user}/tmp/11/15/file1.csv' OVERWRITE"
742742
cursor.execute(query)
743743

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+
744785
def test_staging_ingestion_put_fails_if_absolute_localFile_not_in_uploads_base_path(self):
745786
"""
746787
This test confirms that uploads_base_path and target_file are resolved into absolute paths.

0 commit comments

Comments
 (0)