Skip to content

Commit

Permalink
Fix lint, Sort mocked config options
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Mar 3, 2023
1 parent 0dd5998 commit f8836f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
20 changes: 10 additions & 10 deletions lib/galaxy/app_unittest_utils/galaxy_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
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
Expand Down
20 changes: 11 additions & 9 deletions test/unit/app/managers/test_UserManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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="[email protected]", username="nopassword")
Expand All @@ -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('[email protected]'), 'qualified': True}" in body
assert (
"{'controller': 'user', 'action': 'activate', 'activation_token': 'activation_token', 'email': Markup('[email protected]'), '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, "[email protected]", "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="[email protected]", username="nopassword")
Expand All @@ -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="[email protected]"))
mock_send_mail.assert_called_once()
mock_unique_id.assert_called_once()
Expand Down

0 comments on commit f8836f6

Please sign in to comment.