Skip to content

Commit ad013d3

Browse files
committed
Fix for binary data
- Added test
1 parent 8f90e80 commit ad013d3

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

pytest_sftpserver/sftp/interface.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
from paramiko.sftp_attr import SFTPAttributes
1313
from paramiko.sftp_handle import SFTPHandle
1414
from paramiko.sftp_si import SFTPServerInterface
15-
from six import string_types, text_type
15+
from six import binary_type, string_types, text_type
1616

1717
from pytest_sftpserver.sftp.util import abspath
1818

19+
ACCEPTABLE_TYPES = string_types + (binary_type,)
20+
1921

2022
class VirtualSFTPHandle(SFTPHandle):
2123
def __init__(self, path, content_provider, flags=0):
@@ -41,7 +43,7 @@ def write(self, offset, data):
4143
if content is None:
4244
return SFTP_OK if self.content_provider.put(self.path, data) else SFTP_NO_SUCH_FILE
4345

44-
if not isinstance(content, string_types):
46+
if not isinstance(content, ACCEPTABLE_TYPES):
4547
# Can't offset write into a 'directory' or integer
4648
return SFTP_FAILURE
4749

tests/test_sftp.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def sftpclient(sftpserver):
3232

3333
@pytest.yield_fixture
3434
def content(sftpserver):
35-
with sftpserver.serve_content(deepcopy(CONTENT_OBJ)):
36-
yield
35+
actual_content = deepcopy(CONTENT_OBJ)
36+
with sftpserver.serve_content(actual_content):
37+
yield actual_content
3738

3839

3940
@pytest.mark.xfail(sys.version_info < (2, 7), reason="Intermittently broken on 2.6")
@@ -105,6 +106,14 @@ def test_sftpserver_put_file(content, sftpclient, tmpdir):
105106
assert set(sftpclient.listdir("/a")) == set(["test.txt", "b", "c", "f"])
106107

107108

109+
def test_sftpserver_put_bigger_file(content, sftpclient, tmpdir):
110+
tmpfile = tmpdir.join("test.txt")
111+
file_size = 40000
112+
tmpfile.write("x" * file_size)
113+
sftpclient.put(str(tmpfile), "/a/test.txt")
114+
assert len(content["a"]["test.txt"]) == file_size
115+
116+
108117
def test_sftpserver_round_trip(content, sftpclient, tmpdir):
109118
tmpfile = tmpdir.join("test.txt")
110119
thetext = u"Just some plain, normal text"

0 commit comments

Comments
 (0)