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

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

Uploaded Source

Built Distribution

pytest_sftpserver-1.0.1-py2.py3-none-any.whl (18.9 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for pytest-sftpserver-1.0.1.tar.gz
Algorithm Hash digest
SHA256 09cbfd562f5b527bd62b5614cd7499f0bb9976feb15f686effc157739aaf1add
MD5 e7e3f516c10b06e863d4200d10118afd
BLAKE2b-256 ae9b506bf001bc484438dabf95ddf336b293bf1af9cbddff3744485e080ead99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_sftpserver-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 96573e94363fca925a86469d96a358c60ab1b16337977fc9c659c8a76809ddbe
MD5 42caa552c43584c6d0c725b222c071ad
BLAKE2b-256 a8b1e6a76905df12dd42acfb3f3c08dc906345597494472a1e0e3078c65273d2

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