Skip to content

Commit

Permalink
[ruff] fix some python warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpoelen committed Jan 19, 2024
1 parent c686d75 commit ba35944
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 150 deletions.
4 changes: 4 additions & 0 deletions tools/conf_migration_tool/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ Unit tests
* Run tests::

python3 -m unittest discover -t . tests

or

pytest tests
44 changes: 22 additions & 22 deletions tools/conf_migration_tool/tests/test_executable_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,47 @@ def test_operator_greater_than(self):
v_3_5_9 = RedemptionVersion("3.5.9")
v_3_5_10 = RedemptionVersion("3.5.10")
v_3_11_9 = RedemptionVersion("3.11.9")
self.assertFalse(v_3_5_9 > v_3_5_9)
self.assertFalse(v_3_5_9 > v_3_5_10)
self.assertTrue(v_3_5_10 > v_3_5_9)
self.assertTrue(v_3_11_9 > v_3_5_9)
self.assertFalse(v_3_5_9 > v_3_11_9)
assert not (v_3_5_9 > v_3_5_9)
assert not (v_3_5_9 > v_3_5_10)
assert v_3_5_10 > v_3_5_9
assert v_3_11_9 > v_3_5_9
assert not (v_3_5_9 > v_3_11_9)

v_3_5_9c = RedemptionVersion("3.5.9c")
self.assertFalse(v_3_5_9 > v_3_5_9c)
self.assertFalse(v_3_5_9c > v_3_5_9c)
self.assertTrue(v_3_5_9c > v_3_5_9)
assert not (v_3_5_9 > v_3_5_9c)
assert not (v_3_5_9c > v_3_5_9c)
assert v_3_5_9c > v_3_5_9

v_3_5_9d = RedemptionVersion("3.5.9d")
self.assertFalse(v_3_5_9c > v_3_5_9d)
self.assertTrue(v_3_5_9d > v_3_5_9c)
assert not (v_3_5_9c > v_3_5_9d)
assert v_3_5_9d > v_3_5_9c

def test_operator_less_than(self):
v_3_5_9 = RedemptionVersion("3.5.9")
v_3_5_10 = RedemptionVersion("3.5.10")
v_3_11_9 = RedemptionVersion("3.11.9")
self.assertFalse(v_3_5_9 < v_3_5_9)
self.assertFalse(v_3_5_10 < v_3_5_9)
self.assertTrue(v_3_5_9 < v_3_5_10)
self.assertFalse(v_3_11_9 < v_3_5_9)
self.assertTrue(v_3_5_9 < v_3_11_9)
assert not (v_3_5_9 < v_3_5_9)
assert not (v_3_5_10 < v_3_5_9)
assert v_3_5_9 < v_3_5_10
assert not (v_3_11_9 < v_3_5_9)
assert v_3_5_9 < v_3_11_9

v_3_5_9c = RedemptionVersion("3.5.9c")
self.assertFalse(v_3_5_9c < v_3_5_9)
self.assertFalse(v_3_5_9c < v_3_5_9c)
self.assertTrue(v_3_5_9 < v_3_5_9c)
assert not (v_3_5_9c < v_3_5_9)
assert not (v_3_5_9c < v_3_5_9c)
assert v_3_5_9 < v_3_5_9c

v_3_5_9d = RedemptionVersion("3.5.9d")
self.assertFalse(v_3_5_9d < v_3_5_9c)
self.assertTrue(v_3_5_9c < v_3_5_9d)
assert not (v_3_5_9d < v_3_5_9c)
assert v_3_5_9c < v_3_5_9d

def test_operator_str(self):
self.assertEqual(str(RedemptionVersion("3.5.9")), "3.5.9")
assert str(RedemptionVersion("3.5.9")) == "3.5.9"

def test_from_file(self):
v_from_file = RedemptionVersion.from_file(
"./tests/fixtures/REDEMPTION_VERSION")
self.assertEqual(str(v_from_file), "9.1.17")
assert str(v_from_file) == "9.1.17"

with self.assertRaises(Exception):
RedemptionVersion.from_file(
Expand Down
4 changes: 4 additions & 0 deletions tools/sesman/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ Unit tests
* Run tests::

python3 -m unittest discover -t . tests

or

pytest tests
10 changes: 3 additions & 7 deletions tools/sesman/sesmanworker/sesman.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,10 +1084,7 @@ def get_service(self) -> Tuple[Union[None, bool], str]:
'target_service': self.target_service_name,
}
if not self.internal_target:
self.internal_target = (
True if self.target_service_name == 'INTERNAL'
else False
)
self.internal_target = (self.target_service_name == 'INTERNAL')
self.send_data(data_to_send)
_status = True
elif self.shared.get('selector') == MAGICASK:
Expand Down Expand Up @@ -1244,8 +1241,7 @@ def get_service(self) -> Tuple[Union[None, bool], str]:
data_to_send['target_service'] = service_name
self._full_user_device_account = f"{target_login}@{device_name}:{wab_login}"
if not self.internal_target:
self.internal_target = (True if s[2] == 'INTERNAL'
else False)
self.internal_target = (s[2] == 'INTERNAL')
self.send_data(data_to_send)
self.target_service_name = service_name
self.target_group = s[0]
Expand Down Expand Up @@ -1839,7 +1835,7 @@ def connect_to_target(self, selected_target) -> Tuple[Union[None, bool], str]:

if _status:
module = kv.get('proto_dest')
if module not in ['RDP', 'VNC', 'INTERNAL']:
if module not in {'RDP', 'VNC', 'INTERNAL'}:
module = 'RDP'
if self.internal_target:
module = 'INTERNAL'
Expand Down
4 changes: 2 additions & 2 deletions tools/sesman/tests/test_addrutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Test_addrutils(unittest.TestCase):
def test_is_device_in_subnet_failure(self):
def expect_false_result(device, subnet):
with self.subTest(device=device, subnet=subnet):
self.assertFalse(is_device_in_subnet(device, subnet))
assert not is_device_in_subnet(device, subnet)


# with subnet param badly formatted
Expand Down Expand Up @@ -65,7 +65,7 @@ def expect_false_result(device, subnet):
def test_is_device_in_subnet_success(self):
def expect_true_result(device, subnet):
with self.subTest(device=device, subnet=subnet):
self.assertTrue(is_device_in_subnet(device, subnet), f"device={device} subnet={subnet}")
assert is_device_in_subnet(device, subnet)


# with subnet matching (with IPv4 only)
Expand Down
2 changes: 1 addition & 1 deletion tools/sesman/tests/test_proxy_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Test_RdpProxyLog(unittest.TestCase):
@patch('syslog.syslog')
def test_log(self, mock):
def test_log(self, mock): # noqa: PLR6301
logger = RdpProxyLog()
logger.update_context(1234, 'myname')

Expand Down
172 changes: 76 additions & 96 deletions tools/sesman/tests/test_sesmanconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,104 +9,84 @@ def test_fr(self):
Tests some keywords are present in translated message
"""
SESMANCONF.language = 'fr'
self.assertIn("fermée à", TR(Sesmsg.SESSION_CLOSED_S))
self.assertIn("licence", TR(Sesmsg.LICENCE_BLOCKER))
self.assertIn("authentification",
TR(Sesmsg.AUTH_FAILED_WAB_S) % "user")
self.assertIn("enregistrement", TR(Sesmsg.ERROR_RECORD_PATH))
self.assertIn("répertoire", TR(Sesmsg.ERROR_RECORD_PATH_S) % "chemin")
self.assertIn("valider", TR(Sesmsg.VALID_AUTHORISATION))
self.assertIn("afficher", TR(Sesmsg.NOT_DISPLAY_MESSAGE))
self.assertIn("changer votre mot de passe", TR(Sesmsg.CHANGEPASSWORD))
self.assertIn("terminée par le client",
TR(Sesmsg.CONNECTION_CLOSED_BY_CLIENT))
self.assertIn("Utilisateur", TR(Sesmsg.EMPTY_USER))
self.assertIn("non valide", TR(Sesmsg.INVALID_USER))
self.assertIn("erreur", TR(Sesmsg.NO_ERROR))
self.assertIn("Cible %s inconnu", TR(Sesmsg.TARGET_S_NOT_FOUND))
self.assertIn("cible", TR(Sesmsg.TARGET_UNREACHABLE))
self.assertIn("échecs", TR(Sesmsg.TOO_MANY_LOGIN_FAILURES))
self.assertIn("enregistrement", TR(Sesmsg.TRACE_WRITER_FAILED_S))
self.assertIn("X509", TR(Sesmsg.X509_AUTH_REFUSED_BY_USER))
self.assertIn("URL Redirection", TR(Sesmsg.URL_AUTH_REFUSED_BY_USER))
self.assertIn("refusé", TR(Sesmsg.NOT_ACCEPT_MESSAGE))
self.assertIn("sélectionnée", TR(Sesmsg.SELECTED_TARGET))
self.assertIn("parsing", TR(Sesmsg.USERNAME_PARSE_ERROR_S))
self.assertIn("expirera", TR(Sesmsg.PASSWORD_EXPIRE_IN_S_DAYS))
self.assertIn("imminente", TR(Sesmsg.PASSWORD_EXPIRE_SOON))
self.assertIn("authentification passthrough",
TR(Sesmsg.PASSTHROUGH_AUTH_FAILED_S))
self.assertIn("dans le sous-réseau", TR(Sesmsg.IN_SUBNET_S))
self.assertIn("pas au sous-réseau", TR(Sesmsg.NO_MATCH_SUBNET_S_S))
self.assertIn("Erreur", TR(Sesmsg.ERROR_S))
self.assertIn("Echec d'authentification",
TR(Sesmsg.AUTHENTICATION_FAILED))
self.assertIn("Compte verrouillé", TR(Sesmsg.ACCOUNT_LOCKED))
self.assertIn("démarrage", TR(Sesmsg.START_SESSION_FAILED))
self.assertIn("Motif interdit détecté", TR(Sesmsg.PATTERN_KILL))
self.assertIn("Session Probe", TR(Sesmsg.SESPROBE_LAUNCH_FAILED))
self.assertIn("coupé la connexion",
TR(Sesmsg.SESPROBE_KEEPALIVE_MISSED))
self.assertIn("Connexion sortante",
TR(Sesmsg.SESPROBE_OUTBOUND_CONNECTION_BLOCKING_FAILED))
self.assertIn("Processus", TR(Sesmsg.SESPROBE_PROCESS_BLOCKING_FAILED))
self.assertIn("Echec de lancement",
TR(Sesmsg.SESPROBE_FAILED_TO_RUN_STARTUP_APPLICATION))
self.assertIn("reconnexion de Session Probe",
TR(Sesmsg.SESPROBE_RECONNECTION))
self.assertIn("erreur fatale",
TR(Sesmsg.APPLICATION_FATAL_ERROR))
assert "fermée à" in TR(Sesmsg.SESSION_CLOSED_S)
assert "licence" in TR(Sesmsg.LICENCE_BLOCKER)
assert "authentification" in TR(Sesmsg.AUTH_FAILED_WAB_S) % "user"
assert "enregistrement" in TR(Sesmsg.ERROR_RECORD_PATH)
assert "répertoire" in TR(Sesmsg.ERROR_RECORD_PATH_S) % "chemin"
assert "valider" in TR(Sesmsg.VALID_AUTHORISATION)
assert "afficher" in TR(Sesmsg.NOT_DISPLAY_MESSAGE)
assert "changer votre mot de passe" in TR(Sesmsg.CHANGEPASSWORD)
assert "terminée par le client" in TR(Sesmsg.CONNECTION_CLOSED_BY_CLIENT)
assert "Utilisateur" in TR(Sesmsg.EMPTY_USER)
assert "non valide" in TR(Sesmsg.INVALID_USER)
assert "erreur" in TR(Sesmsg.NO_ERROR)
assert "Cible %s inconnu" in TR(Sesmsg.TARGET_S_NOT_FOUND)
assert "cible" in TR(Sesmsg.TARGET_UNREACHABLE)
assert "échecs" in TR(Sesmsg.TOO_MANY_LOGIN_FAILURES)
assert "enregistrement" in TR(Sesmsg.TRACE_WRITER_FAILED_S)
assert "X509" in TR(Sesmsg.X509_AUTH_REFUSED_BY_USER)
assert "URL Redirection" in TR(Sesmsg.URL_AUTH_REFUSED_BY_USER)
assert "refusé" in TR(Sesmsg.NOT_ACCEPT_MESSAGE)
assert "sélectionnée" in TR(Sesmsg.SELECTED_TARGET)
assert "parsing" in TR(Sesmsg.USERNAME_PARSE_ERROR_S)
assert "expirera" in TR(Sesmsg.PASSWORD_EXPIRE_IN_S_DAYS)
assert "imminente" in TR(Sesmsg.PASSWORD_EXPIRE_SOON)
assert "authentification passthrough" in TR(Sesmsg.PASSTHROUGH_AUTH_FAILED_S)
assert "dans le sous-réseau" in TR(Sesmsg.IN_SUBNET_S)
assert "pas au sous-réseau" in TR(Sesmsg.NO_MATCH_SUBNET_S_S)
assert "Erreur" in TR(Sesmsg.ERROR_S)
assert "Echec d'authentification" in TR(Sesmsg.AUTHENTICATION_FAILED)
assert "Compte verrouillé" in TR(Sesmsg.ACCOUNT_LOCKED)
assert "démarrage" in TR(Sesmsg.START_SESSION_FAILED)
assert "Motif interdit détecté" in TR(Sesmsg.PATTERN_KILL)
assert "Session Probe" in TR(Sesmsg.SESPROBE_LAUNCH_FAILED)
assert "coupé la connexion" in TR(Sesmsg.SESPROBE_KEEPALIVE_MISSED)
assert "Connexion sortante" in TR(Sesmsg.SESPROBE_OUTBOUND_CONNECTION_BLOCKING_FAILED)
assert "Processus" in TR(Sesmsg.SESPROBE_PROCESS_BLOCKING_FAILED)
assert "Echec de lancement" in TR(Sesmsg.SESPROBE_FAILED_TO_RUN_STARTUP_APPLICATION)
assert "reconnexion de Session Probe" in TR(Sesmsg.SESPROBE_RECONNECTION)
assert "erreur fatale" in TR(Sesmsg.APPLICATION_FATAL_ERROR)

def test_en(self):
"""
Tests some keywords are present in translated message
"""
self.assertIn("close at", TR(Sesmsg.SESSION_CLOSED_S))
self.assertIn("licence", TR(Sesmsg.LICENCE_BLOCKER))
self.assertIn("Authentication",
TR(Sesmsg.AUTH_FAILED_WAB_S) % "user")
self.assertIn("recording path", TR(Sesmsg.ERROR_RECORD_PATH))
self.assertIn("recording path for",
TR(Sesmsg.ERROR_RECORD_PATH_S) % "chemin")
self.assertIn("Validate", TR(Sesmsg.VALID_AUTHORISATION))
self.assertIn("display message", TR(Sesmsg.NOT_DISPLAY_MESSAGE))
self.assertIn("change your password", TR(Sesmsg.CHANGEPASSWORD))
self.assertIn("closed by client",
TR(Sesmsg.CONNECTION_CLOSED_BY_CLIENT))
self.assertIn("Empty user", TR(Sesmsg.EMPTY_USER))
self.assertIn("Invalid user", TR(Sesmsg.INVALID_USER))
self.assertIn("No error", TR(Sesmsg.NO_ERROR))
self.assertIn("not found", TR(Sesmsg.TARGET_S_NOT_FOUND))
self.assertIn("unreachable", TR(Sesmsg.TARGET_UNREACHABLE))
self.assertIn("many login failures", TR(Sesmsg.TOO_MANY_LOGIN_FAILURES))
self.assertIn("writer failed", TR(Sesmsg.TRACE_WRITER_FAILED_S))
self.assertIn("X509", TR(Sesmsg.X509_AUTH_REFUSED_BY_USER))
self.assertIn("URL Redirection", TR(Sesmsg.URL_AUTH_REFUSED_BY_USER))
self.assertIn("refused", TR(Sesmsg.NOT_ACCEPT_MESSAGE))
self.assertIn("Selected", TR(Sesmsg.SELECTED_TARGET))
self.assertIn("parse error", TR(Sesmsg.USERNAME_PARSE_ERROR_S))
self.assertIn("will expire in", TR(Sesmsg.PASSWORD_EXPIRE_IN_S_DAYS))
self.assertIn("expire soon", TR(Sesmsg.PASSWORD_EXPIRE_SOON))
self.assertIn("Passthrough authentication failed",
TR(Sesmsg.PASSTHROUGH_AUTH_FAILED_S))
self.assertIn("subnet", TR(Sesmsg.IN_SUBNET_S))
self.assertIn("not in", TR(Sesmsg.NO_MATCH_SUBNET_S_S))
self.assertIn("Error", TR(Sesmsg.ERROR_S))
self.assertIn("Authentication failed",
TR(Sesmsg.AUTHENTICATION_FAILED))
self.assertIn("Account locked", TR(Sesmsg.ACCOUNT_LOCKED))
self.assertIn("Failed to start", TR(Sesmsg.START_SESSION_FAILED))
self.assertIn("Forbidden pattern", TR(Sesmsg.PATTERN_KILL))
self.assertIn("Could not launch Session Probe",
TR(Sesmsg.SESPROBE_LAUNCH_FAILED))
self.assertIn("connection closed",
TR(Sesmsg.SESPROBE_KEEPALIVE_MISSED))
self.assertIn("outbound connection",
TR(Sesmsg.SESPROBE_OUTBOUND_CONNECTION_BLOCKING_FAILED))
self.assertIn("process", TR(Sesmsg.SESPROBE_PROCESS_BLOCKING_FAILED))
self.assertIn("application launch failed",
TR(Sesmsg.SESPROBE_FAILED_TO_RUN_STARTUP_APPLICATION))
self.assertIn("Unauthorized Session Probe reconnection",
TR(Sesmsg.SESPROBE_RECONNECTION))
self.assertIn("fatal error",
TR(Sesmsg.APPLICATION_FATAL_ERROR))
assert "close at" in TR(Sesmsg.SESSION_CLOSED_S)
assert "licence" in TR(Sesmsg.LICENCE_BLOCKER)
assert "Authentication" in TR(Sesmsg.AUTH_FAILED_WAB_S) % "user"
assert "recording path" in TR(Sesmsg.ERROR_RECORD_PATH)
assert "recording path for" in TR(Sesmsg.ERROR_RECORD_PATH_S) % "chemin"
assert "Validate" in TR(Sesmsg.VALID_AUTHORISATION)
assert "display message" in TR(Sesmsg.NOT_DISPLAY_MESSAGE)
assert "change your password" in TR(Sesmsg.CHANGEPASSWORD)
assert "closed by client" in TR(Sesmsg.CONNECTION_CLOSED_BY_CLIENT)
assert "Empty user" in TR(Sesmsg.EMPTY_USER)
assert "Invalid user" in TR(Sesmsg.INVALID_USER)
assert "No error" in TR(Sesmsg.NO_ERROR)
assert "not found" in TR(Sesmsg.TARGET_S_NOT_FOUND)
assert "unreachable" in TR(Sesmsg.TARGET_UNREACHABLE)
assert "many login failures" in TR(Sesmsg.TOO_MANY_LOGIN_FAILURES)
assert "writer failed" in TR(Sesmsg.TRACE_WRITER_FAILED_S)
assert "X509" in TR(Sesmsg.X509_AUTH_REFUSED_BY_USER)
assert "URL Redirection" in TR(Sesmsg.URL_AUTH_REFUSED_BY_USER)
assert "refused" in TR(Sesmsg.NOT_ACCEPT_MESSAGE)
assert "Selected" in TR(Sesmsg.SELECTED_TARGET)
assert "parse error" in TR(Sesmsg.USERNAME_PARSE_ERROR_S)
assert "will expire in" in TR(Sesmsg.PASSWORD_EXPIRE_IN_S_DAYS)
assert "expire soon" in TR(Sesmsg.PASSWORD_EXPIRE_SOON)
assert "Passthrough authentication failed" in TR(Sesmsg.PASSTHROUGH_AUTH_FAILED_S)
assert "subnet" in TR(Sesmsg.IN_SUBNET_S)
assert "not in" in TR(Sesmsg.NO_MATCH_SUBNET_S_S)
assert "Error" in TR(Sesmsg.ERROR_S)
assert "Authentication failed" in TR(Sesmsg.AUTHENTICATION_FAILED)
assert "Account locked" in TR(Sesmsg.ACCOUNT_LOCKED)
assert "Failed to start" in TR(Sesmsg.START_SESSION_FAILED)
assert "Forbidden pattern" in TR(Sesmsg.PATTERN_KILL)
assert "Could not launch Session Probe" in TR(Sesmsg.SESPROBE_LAUNCH_FAILED)
assert "connection closed" in TR(Sesmsg.SESPROBE_KEEPALIVE_MISSED)
assert "outbound connection" in TR(Sesmsg.SESPROBE_OUTBOUND_CONNECTION_BLOCKING_FAILED)
assert "process" in TR(Sesmsg.SESPROBE_PROCESS_BLOCKING_FAILED)
assert "application launch failed" in TR(Sesmsg.SESPROBE_FAILED_TO_RUN_STARTUP_APPLICATION)
assert "Unauthorized Session Probe reconnection" in TR(Sesmsg.SESPROBE_RECONNECTION)
assert "fatal error" in TR(Sesmsg.APPLICATION_FATAL_ERROR)
Loading

0 comments on commit ba35944

Please sign in to comment.