Giter VIP home page Giter VIP logo

pytest-sftpserver's Introduction

pytest-sftpserver

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

pytest-sftpserver's People

Contributors

ulope avatar

Watchers

Varun Madiath avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.