Skip to content

Commit d64ac9d

Browse files
add exists method
1 parent b8b51ec commit d64ac9d

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

ted_sws/notice_publisher/adapters/sftp_notice_publisher.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,16 @@ def remove(self, remote_path: str) -> bool:
6565
"""
6666
self._sftp.remove(remote_path)
6767
return True
68+
69+
def exists(self, remote_path: str) -> bool:
70+
"""
71+
Check if remote_path exists.
72+
:param remote_path:
73+
:return:
74+
"""
75+
if self.is_connected:
76+
try:
77+
self._sftp.stat(remote_path)
78+
except IOError:
79+
return False
80+
return True

tests/e2e/notice_publisher/adapters/test_notice_publisher.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ def test_sftp_notice_publisher():
3232
with pytest.raises(Exception):
3333
sftp_publisher.publish(source_file.name, None)
3434

35+
assert not sftp_publisher.exists(remote_path)
3536
published = sftp_publisher.publish(source_file.name, remote_path)
3637
assert published
37-
assert sftp_publisher.connection.exists(remote_path)
38+
assert sftp_publisher.exists(remote_path)
3839
sftp_publisher.remove(remote_path)
39-
assert not sftp_publisher.connection.exists(remote_path)
40+
assert not sftp_publisher.exists(remote_path)
4041

4142
sftp_publisher.disconnect()
4243

tests/features/notice_publisher/test_notice_publisher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def the_mets_package_available_in_a_shared_sftp_drive(published_notice: Notice,
8181
publisher: SFTPPublisher = SFTPPublisher()
8282
remote_notice_path = f"{sftp_remote_folder_path}/{published_notice.ted_id}.zip"
8383
publisher.connect()
84-
assert publisher.connection.exists(remotepath=remote_notice_path)
84+
assert publisher.exists(remote_path=remote_notice_path)
8585
publisher.disconnect()
8686

8787

0 commit comments

Comments
 (0)