Skip to main content

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

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:

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

pytest-sftpserver-1.0.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

pytest_sftpserver-1.0.0-py2.py3-none-any.whl (18.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-sftpserver-1.0.0.tar.gz.

File metadata

File hashes

Hashes for pytest-sftpserver-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a848a2ac4097a3afbcdee2f0b5b9b47d5aaf6d41064ce9f21dfae5f7f5ee3788
MD5 273be0537852fb686cfc3355cba2402d
BLAKE2b-256 ab588d8823d906bfbb72717d9088e57de6df747a4c74a7fd7dd7cff00e28f528

See more details on using hashes here.

File details

Details for the file pytest_sftpserver-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_sftpserver-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 876585ef4e6fd2316182fb8d9730cbfd170dab2b09654eb09f319cdb40cbc602
MD5 31a33fda5717c52e48cdcfa1024eb7d1
BLAKE2b-256 e0c2937171724c1cfccb6bdbe6b468d5efb6ebbad3dac33d13b4163727e2d0de

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page