Files
galaxy/test/unit/app/test_remote_shell.py
T
Nicola Soranzo 7f89e0eab9 Code cleanups from pyupgrade
Found by running:

```
make pyupgrade
ruff check --fix .
ruff check --preview --unsafe-fixes --select=F401 --fix .
make format
make update-client-api-schema
```

The bulk of the changes are replacements of typing deprecated aliases
such as `Dict` and `List` with the standard library classes. These
aliases became redundant in Python 3.9 when the corresponding
pre-existing classes were enhanced to support `[]`, see
https://docs.python.org/3/library/typing.html#deprecated-aliases

Also:
- Update the `pyupgrade` Makefile target to use `--py38-plus` for the
  packages needed by Pulsar, including the new galaxy-tool-util-models
  package.
2025-07-31 11:17:22 +01:00

72 lines
2.5 KiB
Python

import os
import unittest
from typing import (
Any,
)
try:
import mockssh
except ImportError:
mockssh = None
from galaxy.jobs.runners.util.cli import CliInterface
from galaxy.security.ssh_util import (
generate_ssh_keys,
SSHKeys,
)
from galaxy.util.unittest import TestCase
class TestCliInterface(TestCase):
ssh_keys: SSHKeys
username: str
shell_params: dict[str, Any]
cli_interface: CliInterface
@classmethod
def tearDownClass(cls):
os.remove(cls.ssh_keys.private_key_file)
os.remove(cls.ssh_keys.public_key_file)
@classmethod
def setUpClass(cls):
cls.ssh_keys = generate_ssh_keys()
cls.username = "testuser"
cls.shell_params = {
"username": cls.username,
"private_key": cls.ssh_keys.private_key_file,
"strict_host_key_checking": False,
"hostname": "localhost",
}
cls.cli_interface = CliInterface()
def test_secure_shell_plugin_without_strict(self):
if not mockssh:
raise unittest.SkipTest("Skipping tests that require mockssh")
with mockssh.Server(users={self.username: self.ssh_keys.private_key_file}) as server:
self.shell_params["port"] = server.port
self.shell_params["plugin"] = "SecureShell"
self.shell_params["strict_host_key_checking"] = False
self.shell = self.cli_interface.get_shell_plugin(self.shell_params)
result = self.shell.execute(cmd="echo hello")
assert result.stdout.strip() == "hello"
def test_get_shell_plugin(self):
if not mockssh:
raise unittest.SkipTest("Skipping tests that require mockssh")
with mockssh.Server(users={self.username: self.ssh_keys.private_key_file}) as server:
self.shell_params["port"] = server.port
self.shell_params["plugin"] = "ParamikoShell"
self.shell = self.cli_interface.get_shell_plugin(self.shell_params)
assert self.shell.username == self.username
def test_paramiko_shell_plugin(self):
if not mockssh:
raise unittest.SkipTest("Skipping tests that require mockssh")
with mockssh.Server(users={self.username: self.ssh_keys.private_key_file}) as server:
self.shell_params["port"] = server.port
self.shell_params["plugin"] = "ParamikoShell"
self.shell = self.cli_interface.get_shell_plugin(self.shell_params)
result = self.shell.execute(cmd="echo hello")
assert result.stdout.strip() == "hello"