Skip to main content

py.test plugin to locally test sftp server connections.

Project description

Latest Version Build status Code coverage Supported versions License

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 :)

Version History

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

  • Clened 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:

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.1.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

pytest_sftpserver-1.1.1-py2.py3-none-any.whl (19.3 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for pytest-sftpserver-1.1.1.tar.gz
Algorithm Hash digest
SHA256 24a7a9289b2124d2e0a15a1f1cc2fcde3bb6c5f3bfee7e151ea6936bdd852c24
MD5 92dc7d12d9f3a2f46d90a65251c6ec3c
BLAKE2b-256 adab6f151f0a191dfd0a98af2d8a849602c25ca5a9c8e45b35902f4472b5fdc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_sftpserver-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a142ca9afdd7d78c3dbd6a630902e12df39e3c0b426725ba6bba6c466c2c3d13
MD5 960e2c44206fb61c45bd05293244040f
BLAKE2b-256 57be8fdb12242028d96603936fe33a7e1935cd5a27c6f1b372d7ea9718d51a17

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