py.test plugin to locally test sftp server connections.
Project description
pytest-sftpserver is a plugin for pytest that provides a local SFTP-Server fixture.
The SFTP-Server provided by this fixture serves content not from files but directly from Python objects.
Quickstart
Assume you want to test a function that downloads a file from an SFTP-Server:
from contextlib import closing
import paramiko
def get_sftp_file(host, port, username, password, path):
with closing(paramiko.Transport((host, port))) as transport:
transport.connect(username=username, password=password)
with closing(paramiko.SFTPClient.from_transport(transport)) as sftpclient:
with sftpclient.open(path, "r") as sftp_file:
return sftp_file.read()
This plugin allows to test such functions without having to spin up an external SFTP-Server by providing a pytest fixture called sftpserver. You use it simply by adding a parameter named sftpserver to your test function:
def test_sftp_fetch(sftpserver):
with sftpserver.serve_content({'a_dir': {'somefile.txt': "File content"}}):
assert get_sftp_file(sftpserver.host, sftpserver.port, "user",
"pw", "/a_dir/somefile.txt") == "File content"
As can be seen from this example sftpserver serves content directly from python objects instead of files.
Installation
pip install pytest-sftpserver
Supported Python versions
This package supports the following Python versions:
2.7, 3.4 - 3.6
TODO
Add more documentation
Add more usage examples
Add TODOs :)
Version History
1.2.0 - 2018-03-28
Updated supported Python versions to 2.7, 3.4 - 3.6. Droped (official) support for 2.6 and 3.2, 3.3.
Now always uses posixpath internally to avoid problems when running on Windows (#7, #8, thanks @dundeemt)
Fixed broken readme badges (#14, thanks @movermeyer)
1.1.2 - 2015-06-01
Fixed a bug in stat size calculation (#4)
Fixed mkdir() overwriting existing content (#5)
Thanks to @zerok for both bug reports and accompanying tests.
1.1.1 - 2015-04-04
Fixed broken chmod() behaviour for non-existing ‘files’ (Thanks @dundeemt)
1.1.0 - 2014-10-15
Fixed broken stat() behaviour for non-existing ‘files’
Slightly increased test coverage
1.0.2 - 2014-07-27
Fixed broken test on Python 2.6
1.0.1 - 2014-07-27
Added Python 3.2 support
Cleaned up tox configuration
1.0.0 - 2014-07-18
Initial release
License
Licensed unter the MIT License. See file LICENSE.
Inspiration
The implementation and idea for this plugin is in part based upon:
The Twisted Conch in 60 Seconds series (although I ended up not using twisted, this was very helpful understanding SFTP internals)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-sftpserver-1.2.0.tar.gz
.
File metadata
- Download URL: pytest-sftpserver-1.2.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81da1672dbc48572577a22e9dd7fde88ffbaa39f0c5bcb6563f103df6b107078 |
|
MD5 | 2311d621445ee5facb520c424a69e236 |
|
BLAKE2b-256 | 9527c06e68b22bac618e5a2f90d0390cae347ac4d9e2743c01ad5394f684248b |
File details
Details for the file pytest_sftpserver-1.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_sftpserver-1.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31793de87582a5ea10e20dc334224949c7922fe7620e0b21d55fd607b9180a30 |
|
MD5 | 3f07a7db2b1f2d458904c9ff15dc6d57 |
|
BLAKE2b-256 | 9b6009343d604a6b3040aaef2e4dcaf15f3f477480402e18a859b5e54055abac |