mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-06 23:09:55 +01:00
This commit intends to mock SSH server that not depends on OS which the test running on for testing purpose.
45 lines
899 B
Python
45 lines
899 B
Python
import mockssh
|
|
import os
|
|
from pytest import yield_fixture
|
|
|
|
from dvc.remote.ssh.connection import SSHConnection
|
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
user = "user"
|
|
key_path = os.path.join(here, "{0}.key".format(user))
|
|
|
|
|
|
@yield_fixture()
|
|
def server():
|
|
users = {user: key_path}
|
|
with mockssh.Server(users) as s:
|
|
yield s
|
|
|
|
|
|
def _client(server):
|
|
client = SSHConnection(
|
|
server.host, username=user, port=server.port, key_filename=key_path
|
|
)
|
|
return client
|
|
|
|
|
|
def test_connection(server):
|
|
client = _client(server)
|
|
ls = client.execute("ls /")
|
|
assert ls
|
|
|
|
|
|
def test_isdir(server):
|
|
client = _client(server)
|
|
path = here
|
|
isdir = client.isdir(path=path)
|
|
assert isdir is True
|
|
|
|
|
|
def test_file_exists(server):
|
|
client = _client(server)
|
|
path = "/path/to/file"
|
|
file_path = client.file_exists(path=path)
|
|
assert file_path is False
|