Skip to content

Commit 1c5bdcd

Browse files
committed
tests: Simplify generating payload
Signed-off-by: Jakub Jelen <[email protected]>
1 parent 225dfa3 commit 1c5bdcd

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

tests/unit/sftp_test.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@ def dst_path(file_paths_pair):
5050
return path
5151

5252

53-
@pytest.fixture
54-
def other_payload():
55-
"""Generate a binary test payload."""
56-
uuid_name = uuid.uuid4()
57-
return 'Original content: {name!s}'.format(name=uuid_name).encode()
53+
@pytest.fixture(params=[32, 1025])
54+
def sized_payload():
55+
"""Generate a binary test payload of size given as a parameter."""
56+
payload_len = 1024 + 1
57+
random_bytes = [ord(random.choice(string.printable)) for _ in range(payload_len)]
58+
return bytes(random_bytes)
5859

5960

6061
@pytest.fixture
61-
def dst_exists_path(file_paths_pair, other_payload):
62+
def dst_exists_path(file_paths_pair, sized_payload):
6263
"""Return a data destination path."""
6364
path = file_paths_pair[1]
64-
path.write_bytes(other_payload)
65+
path.write_bytes(sized_payload)
6566
assert path.exists()
6667
return path
6768

@@ -96,32 +97,24 @@ def test_put_existing(dst_exists_path, src_path, sftp_session, transmit_payload)
9697

9798

9899
@pytest.fixture
99-
def large_payload():
100-
"""Generate a large 1025 byte (1024 + 1B) test payload."""
101-
payload_len = 1024 + 1
102-
random_bytes = [ord(random.choice(string.printable)) for _ in range(payload_len)]
103-
return bytes(random_bytes)
104-
105-
106-
@pytest.fixture
107-
def src_path_large(tmp_path, large_payload):
100+
def src_path_large(tmp_path, sized_payload):
108101
"""Return a remote path to a 1025 byte-sized file.
109102
110103
The pylibssh chunk size is 1024 so the test needs a file that would
111104
execute at least two loops.
112105
"""
113106
path = tmp_path / 'large.txt'
114-
path.write_bytes(large_payload)
107+
path.write_bytes(sized_payload)
115108
return path
116109

117110

118-
def test_put_large(dst_path, src_path_large, sftp_session, large_payload):
111+
def test_put_large(dst_path, src_path_large, sftp_session, sized_payload):
119112
"""Check that SFTP can upload large file."""
120113
sftp_session.put(str(src_path_large), str(dst_path))
121-
assert dst_path.read_bytes() == large_payload
114+
assert dst_path.read_bytes() == sized_payload
122115

123116

124-
def test_get_large(dst_path, src_path_large, sftp_session, large_payload):
117+
def test_get_large(dst_path, src_path_large, sftp_session, sized_payload):
125118
"""Check that SFTP can download large file."""
126119
sftp_session.get(str(src_path_large), str(dst_path))
127-
assert dst_path.read_bytes() == large_payload
120+
assert dst_path.read_bytes() == sized_payload

0 commit comments

Comments
 (0)