From 9d64dcc9ac64e0dcd5622f2ab3e0cbc260ae1830 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Fri, 15 Nov 2024 14:09:43 +0100 Subject: [PATCH] tests: Reproduer for overriding existing files Signed-off-by: Jakub Jelen --- tests/unit/sftp_test.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/unit/sftp_test.py b/tests/unit/sftp_test.py index 1572c0d66..93446bd9f 100644 --- a/tests/unit/sftp_test.py +++ b/tests/unit/sftp_test.py @@ -50,6 +50,22 @@ def dst_path(file_paths_pair): return path +@pytest.fixture +def other_payload(): + """Generate a binary test payload.""" + uuid_name = uuid.uuid4() + return 'Original content: {name!s}'.format(name=uuid_name).encode() + + +@pytest.fixture +def dst_exists_path(file_paths_pair, other_payload): + """Return a data destination path.""" + path = file_paths_pair[1] + path.write_bytes(other_payload) + assert path.exists() + return path + + def test_make_sftp(sftp_session): """Smoke-test SFTP instance creation.""" assert sftp_session @@ -67,6 +83,12 @@ def test_get(dst_path, src_path, sftp_session, transmit_payload): assert dst_path.read_bytes() == transmit_payload +def test_get_existing(dst_exists_path, src_path, sftp_session, transmit_payload): + """Check that SFTP file download works when target file exists.""" + sftp_session.get(str(src_path), str(dst_exists_path)) + assert dst_exists_path.read_bytes() == transmit_payload + + @pytest.fixture def large_payload(): """Generate a large 1025 byte (1024 + 1B) test payload."""