用于测试的Mock SSH服务器
项目描述
mock-ssh-server 包含一个Python上下文管理器,用于实现测试目的的SSH服务器。它建立在paramiko之上,因此不需要安装OpenSSH二进制文件。
示例用法
作为py.test插件
import os
from pytest import yield_fixture
import mockssh
@yield_fixture()
def server():
users = {
"sample-user": "/path/to/user-private-key",
}
with mockssh.Server(users) as s:
yield s
def test_ssh_session(server):
for uid in server.users:
with server.client(uid) as c:
_, stdout, _ = c.exec_command("ls /")
assert stdout.read()
def test_sftp_session(server):
for uid in server.users:
target_dir = tempfile.mkdtemp()
target_fname = os.path.join(target_dir, "foo")
assert not os.access(target_fname, os.F_OK)
with server.client(uid) as c:
sftp = c.open_sftp()
sftp.put(__file__, target_fname, confirm=True)
assert os.access(target_fname, os.F_OK)
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
mock-ssh-server-0.9.1.tar.gz (12.8 kB 查看哈希值)
构建分发
mock_ssh_server-0.9.1-py3-none-any.whl (14.5 kB 查看哈希值)