From f8836f6b20ee647691dcb47e9a553d0f05fc3405 Mon Sep 17 00:00:00 2001 From: guerler Date: Thu, 2 Mar 2023 13:23:27 -0500 Subject: [PATCH] Fix lint, Sort mocked config options --- lib/galaxy/app_unittest_utils/galaxy_mock.py | 20 ++++++++++---------- test/unit/app/managers/test_UserManager.py | 20 +++++++++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/galaxy/app_unittest_utils/galaxy_mock.py b/lib/galaxy/app_unittest_utils/galaxy_mock.py index 0b0bd273664d..15cd8a9912e2 100644 --- a/lib/galaxy/app_unittest_utils/galaxy_mock.py +++ b/lib/galaxy/app_unittest_utils/galaxy_mock.py @@ -185,25 +185,25 @@ def __init__(self, **kwargs): self.user_activation_on = False self.new_user_dataset_access_role_default_private = False - self.expose_dataset_path = True + self.activation_grace_period = 0 self.allow_user_dataset_purge = True self.allow_user_creation = True + self.auth_config_file = "config/auth_conf.xml.sample" + self.custom_activation_email_message = "custom_activation_email_message" self.email_domain_allowlist_content = None self.email_domain_blocklist_content = None + self.email_from = "email_from" self.enable_old_display_applications = True - self.redact_username_in_logs = False - self.auth_config_file = "config/auth_conf.xml.sample" self.error_email_to = "admin@email.to" - self.password_expiration_period = 0 - self.terms_url = "terms_url" + self.expose_dataset_path = True + self.hostname = "hostname" self.instance_resource_url = "instance_resource_url" - self.custom_activation_email_message = "custom_activation_email_message" - self.activation_grace_period = 0 - self.templates_dir = "templates" - self.email_from = "email_from" + self.password_expiration_period = 0 self.pretty_datetime_format = "pretty_datetime_format" + self.redact_username_in_logs = False self.smtp_server = True - self.hostname = "hostname" + self.terms_url = "terms_url" + self.templates_dir = "templates" self.umask = 0o77 self.flush_per_n_datasets = 0 diff --git a/test/unit/app/managers/test_UserManager.py b/test/unit/app/managers/test_UserManager.py index 60c6d191e545..00152b51ca97 100644 --- a/test/unit/app/managers/test_UserManager.py +++ b/test/unit/app/managers/test_UserManager.py @@ -4,11 +4,10 @@ Executable directly using: python -m test.unit.managers.test_UserManager """ from datetime import datetime +from unittest.mock import patch from sqlalchemy import desc -from unittest import mock - from galaxy import ( exceptions, model, @@ -192,7 +191,7 @@ def test_empty_password(self): def testable_url_for(*a, **k): return f"(url_for): {k}" - @mock.patch("routes.url_for", testable_url_for) + @patch("routes.url_for", testable_url_for) def test_activation_email(self): self.log("should produce the activation email") self.user_manager.create(email="user@nopassword.com", username="nopassword") @@ -204,16 +203,19 @@ def validate_send_email(frm, to, subject, body, config, html=None): assert subject == "Galaxy Account Activation" assert "custom_activation_email_message" in body assert "Hello nopassword" in body - assert "{'controller': 'user', 'action': 'activate', 'activation_token': 'activation_token', 'email': Markup('user@nopassword.com'), 'qualified': True}" in body + assert ( + "{'controller': 'user', 'action': 'activate', 'activation_token': 'activation_token', 'email': Markup('user@nopassword.com'), 'qualified': True}" + in body + ) - with mock.patch("galaxy.util.send_mail", side_effect=validate_send_email) as mock_send_mail: - with mock.patch("galaxy.util.hash_util.new_secure_hash_v2", return_value="activation_token") as mock_hash_util: + with patch("galaxy.util.send_mail", side_effect=validate_send_email) as mock_send_mail: + with patch("galaxy.util.hash_util.new_secure_hash_v2", return_value="activation_token") as mock_hash_util: result = self.user_manager.send_activation_email(self.trans, "user@nopassword.com", "nopassword") mock_send_mail.assert_called_once() mock_hash_util.assert_called_once() assert result is True - @mock.patch("routes.url_for", testable_url_for) + @patch("routes.url_for", testable_url_for) def test_reset_email(self): self.log("should produce the password reset email") self.user_manager.create(email="user@nopassword.com", username="nopassword") @@ -226,8 +228,8 @@ def validate_send_email(frm, to, subject, body, config, html=None): assert "reset your Galaxy password" in body assert "{'controller': 'login', 'action': 'start', 'token': 'reset_token'}" in body - with mock.patch("galaxy.util.send_mail", side_effect=validate_send_email) as mock_send_mail: - with mock.patch("galaxy.model.unique_id", return_value="reset_token") as mock_unique_id: + with patch("galaxy.util.send_mail", side_effect=validate_send_email) as mock_send_mail: + with patch("galaxy.model.unique_id", return_value="reset_token") as mock_unique_id: result = self.user_manager.send_reset_email(self.trans, dict(email="user@nopassword.com")) mock_send_mail.assert_called_once() mock_unique_id.assert_called_once()