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.6 - 2.7
3.2 - 3.4
TODO
Add more documentation
Add more usage examples
Add TODOs :)
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.0.2.tar.gz
.
File metadata
- Download URL: pytest-sftpserver-1.0.2.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b43db0f8ae3f59f3b54e4c44b349ea1ebed2ded85f851df73f1e7908e4773913 |
|
MD5 | 5702d0d0b82cd50119ee2653c7eaa787 |
|
BLAKE2b-256 | bac02581e563cf62fc7aed412bcfb131994455ce834b31178f40cc85e5136153 |
File details
Details for the file pytest_sftpserver-1.0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_sftpserver-1.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c01d68c55000a0f8c6c39fd7f7821403e4a01a09594b51948ef7d1785afa8b21 |
|
MD5 | 9a11afbe46503c12acbb7852f6d4cc9c |
|
BLAKE2b-256 | 74e0701c8d982abd55cfd7bc869bd6c9d83c6509ff8948877f9a19cf7c9b69e2 |