Skip to content

Commit

Permalink
Rename FRACTAL_EMAIL_SETTINGS->mail_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tcompa committed Feb 4, 2025
1 parent 11ed043 commit 3013d86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
9 changes: 3 additions & 6 deletions fractal_server/app/security/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,15 @@ async def on_after_register(
# Send mail section
settings = Inject(get_settings)

if (
this_user.oauth_accounts
and settings.FRACTAL_EMAIL_SETTINGS is not None
):
if this_user.oauth_accounts and settings.mail_settings is not None:
try:
logger.info(
"START sending email about new signup to "
f"{settings.FRACTAL_EMAIL_SETTINGS.recipients}."
f"{settings.mail_settings.recipients}."
)
mail_new_oauth_signup(
msg=f"New user registered: '{this_user.email}'.",
mail_settings=settings.FRACTAL_EMAIL_SETTINGS,
mail_settings=settings.mail_settings,
)
logger.info("END sending email about new signup.")
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion fractal_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def PIP_CACHE_DIR_ARG(self) -> str:
"""
TBD
"""
FRACTAL_EMAIL_SETTINGS: Optional[MailSettings] = None
mail_settings: Optional[MailSettings] = None

@root_validator(pre=True)
def validate_email_settings(cls, values):
Expand Down
12 changes: 7 additions & 5 deletions tests/no_version/test_unit_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def test_fractal_email():
)
# 1: no mail settings
settings = Settings(**common_attributes)
assert settings.FRACTAL_EMAIL_SETTINGS is None
assert settings.mail_settings is None
# 2: FRACTAL_EMAIL_USE_LOGIN is true, but no password settings
with pytest.raises(ValidationError):
Settings(
Expand Down Expand Up @@ -437,15 +437,17 @@ def test_fractal_email():
FRACTAL_EMAIL_PASSWORD=FRACTAL_EMAIL_PASSWORD,
FRACTAL_EMAIL_PASSWORD_KEY=FRACTAL_EMAIL_PASSWORD_KEY,
)
assert settings.FRACTAL_EMAIL_SETTINGS is not None
assert len(settings.FRACTAL_EMAIL_SETTINGS.recipients) == 2
assert settings.mail_settings is not None
assert len(settings.mail_settings.recipients) == 2
# 5: FRACTAL_EMAIL_USE_LOGIN is false and no password needed
Settings(
settings = Settings(
**common_attributes,
**required_mail_args,
FRACTAL_EMAIL_USE_LOGIN=False,
)
# 6: missing mandatory arguments
assert settings.mail_settings is not None

# 6: missing required arguments
for arg in required_mail_args:
with pytest.raises(ValidationError):
Settings(
Expand Down

0 comments on commit 3013d86

Please sign in to comment.