pytest-sftpserver
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.5 - 3.7
TODO
Add more documentation
Add more usage examples
Add TODOs :)
Version History
1.3.0 - 2019-09-16
Updated supported Python versions to 2.7, 3.5 - 3.7.
Droped (official) support for 3.4.
Check / format code with black, isort and flake8.
Fix return type of .read(). (#15, thanks @WeatherGod)
Support the offset parameter on write operations. (#11, #16, thanks @DrNecromant)
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)
Metadata
Release files for pytest-sftpserver 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest-sftpserver-1.3.0.tar.gz | 12.6 kB | Without provenance | Details for pytest-sftpserver-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_sftpserver-1.3.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for pytest_sftpserver-1.3.0-py2.py3-none-any.whl |
Total release size: 30.9 kB
Release files / pytest-sftpserver-1.3.0.tar.gz
| Download URL | pytest-sftpserver-1.3.0.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7ac34a23f63d77e27f67b6a81c9418243733f027eeb8a3061d965b2da7e5cab
|
|
BLAKE2b-256 checksum How to use checksums |
0545f0c545cf1bee1556fed7fb3e7eea77a4691255939522b1d677ecb2c04be8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.9 CPython/2.7.14
|
Release files / pytest_sftpserver-1.3.0-py2.py3-none-any.whl
| Download URL | pytest_sftpserver-1.3.0-py2.py3-none-any.whl |
|---|---|
| Size | 18.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c5e8a37049866d4eabc711db9f1c09e1c02ab72ba290f5fd244939c9a188042f
|
|
BLAKE2b-256 checksum How to use checksums |
5c07a66ce67849514133361887636e0ca187e894bca241686adedd414a06cb50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.9 CPython/2.7.14
|
Security for pytest-sftpserver 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.