simple-module-mail 0.0.41__tar.gz → 0.0.43__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/.gitignore +3 -0
  2. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/PKG-INFO +3 -3
  3. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/mail/constants.py +11 -0
  4. simple_module_mail-0.0.43/mail/data_compatibility.py +38 -0
  5. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/mail/module.py +7 -1
  6. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/pyproject.toml +3 -3
  7. simple_module_mail-0.0.43/tests/test_mail_data_compatibility.py +38 -0
  8. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/LICENSE +0 -0
  9. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/README.md +0 -0
  10. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/mail/__init__.py +0 -0
  11. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/mail/py.typed +0 -0
  12. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/mail/runtime.py +0 -0
  13. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/mail/sender.py +0 -0
  14. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/mail/settings.py +0 -0
  15. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/mail/state.py +0 -0
  16. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/tests/test_mail_health.py +0 -0
  17. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/tests/test_mail_lifecycle.py +0 -0
  18. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/tests/test_mail_sender.py +0 -0
  19. {simple_module_mail-0.0.41 → simple_module_mail-0.0.43}/tests/test_mail_settings_migration.py +0 -0
@@ -22,6 +22,9 @@ node_modules/
22
22
 
23
23
  # Database
24
24
  *.db
25
+ *.db-wal
26
+ *.db-shm
27
+ *.db-journal
25
28
  *.sqlite3
26
29
 
27
30
  # Module-managed runtime state (e.g. uploaded dataset files,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: simple_module_mail
3
- Version: 0.0.41
3
+ Version: 0.0.43
4
4
  Summary: Outgoing mail (SMTP or console) for simple_module apps, configured from the DB-backed settings
5
5
  Project-URL: Homepage, https://github.com/antosubash/simple_module_python
6
6
  Project-URL: Repository, https://github.com/antosubash/simple_module_python
@@ -12,8 +12,8 @@ License-File: LICENSE
12
12
  Keywords: email,mail,simple-module,smtp
13
13
  Requires-Python: >=3.12
14
14
  Requires-Dist: aiosmtplib<6,>=3.0
15
- Requires-Dist: simple-module-core==0.0.41
16
- Requires-Dist: simple-module-settings==0.0.41
15
+ Requires-Dist: simple-module-core==0.0.43
16
+ Requires-Dist: simple-module-settings==0.0.43
17
17
  Description-Content-Type: text/markdown
18
18
 
19
19
  # simple_module_mail
@@ -22,3 +22,14 @@ MAX_PORT = 65535
22
22
  #: Seconds per SMTP operation (aiosmtplib defaults to 60). A send can run in a
23
23
  #: request's after-commit hook, so a hung server must not hold it for a minute.
24
24
  SMTP_TIMEOUT_SECONDS = 15.0
25
+
26
+ UPGRADE_SETTINGS_NAMESPACE = "mail.settings_namespace_v1"
27
+ LEGACY_MAIL_KEYS = (
28
+ "users.mailer",
29
+ "users.smtp_host",
30
+ "users.smtp_port",
31
+ "users.smtp_username",
32
+ "users.smtp_password",
33
+ "users.smtp_from",
34
+ "users.smtp_tls",
35
+ )
@@ -0,0 +1,38 @@
1
+ """Detect system settings that still use the pre-mail-module namespace."""
2
+
3
+ from simple_module_core.data_compatibility import DataCompatibilityIssue
4
+ from simple_module_db.stored_settings import (
5
+ SCOPE_SYSTEM,
6
+ SYSTEM_SCOPE_ID,
7
+ settings_table_clause,
8
+ settings_table_exists,
9
+ )
10
+ from sqlalchemy import select
11
+ from sqlalchemy.ext.asyncio import AsyncSession
12
+
13
+ from mail.constants import LEGACY_MAIL_KEYS, UPGRADE_SETTINGS_NAMESPACE
14
+
15
+
16
+ async def check_data_compatibility(db: AsyncSession) -> list[DataCompatibilityIssue]:
17
+ if not await settings_table_exists(db):
18
+ return []
19
+ settings = settings_table_clause()
20
+ found = await db.scalar(
21
+ select(settings.c.key)
22
+ .where(
23
+ settings.c.scope == SCOPE_SYSTEM,
24
+ settings.c.scope_id == SYSTEM_SCOPE_ID,
25
+ settings.c.key.in_(LEGACY_MAIL_KEYS),
26
+ )
27
+ .limit(1)
28
+ )
29
+ if found is None:
30
+ return []
31
+ return [
32
+ DataCompatibilityIssue(
33
+ upgrade_id=UPGRADE_SETTINGS_NAMESPACE,
34
+ message="Obsolete system users.mailer/SMTP settings must move to mail.*; "
35
+ "target values win.",
36
+ severity="warning",
37
+ )
38
+ ]
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import TYPE_CHECKING
5
+ from typing import TYPE_CHECKING, Any
6
6
 
7
7
  from simple_module_core.health import HealthCheck, HealthRegistry
8
8
  from simple_module_core.mail import install_mail_resolver, install_mail_sender
@@ -12,6 +12,7 @@ from mail import constants as c
12
12
 
13
13
  if TYPE_CHECKING:
14
14
  from fastapi import FastAPI
15
+ from simple_module_core.data_compatibility import DataCompatibilityIssue
15
16
  from simple_module_core.events import EventBus
16
17
 
17
18
 
@@ -65,6 +66,11 @@ class MailModule(ModuleBase):
65
66
 
66
67
  bus.subscribe(SettingsReloaded, _reinstall)
67
68
 
69
+ async def check_data_compatibility(self, db: Any) -> list[DataCompatibilityIssue]:
70
+ from mail.data_compatibility import check_data_compatibility
71
+
72
+ return await check_data_compatibility(db)
73
+
68
74
  async def on_startup(self, app: FastAPI) -> None:
69
75
  from mail.runtime import install_app_sender
70
76
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "simple_module_mail"
3
- version = "0.0.41"
3
+ version = "0.0.43"
4
4
  description = "Outgoing mail (SMTP or console) for simple_module apps, configured from the DB-backed settings"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -9,8 +9,8 @@ requires-python = ">=3.12"
9
9
  authors = [{ name = "Anto Subash", email = "antosubash@live.com" }]
10
10
  keywords = ["simple-module", "mail", "smtp", "email"]
11
11
  dependencies = [
12
- "simple_module_core==0.0.41",
13
- "simple_module_settings==0.0.41",
12
+ "simple_module_core==0.0.43",
13
+ "simple_module_settings==0.0.43",
14
14
  "aiosmtplib>=3.0,<6",
15
15
  ]
16
16
 
@@ -0,0 +1,38 @@
1
+ """Only obsolete system mail keys require a host revision (#711)."""
2
+
3
+ import pytest
4
+ from mail.module import MailModule
5
+ from sqlalchemy import text
6
+ from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
7
+
8
+
9
+ @pytest.mark.parametrize(
10
+ ("scope", "scope_id", "key", "expected"),
11
+ [
12
+ ("system", "", "users.smtp_password", True),
13
+ ("system", "", "users.mailer", True),
14
+ ("tenant", "one", "users.smtp_host", False),
15
+ ("system", "other", "users.mailer", False),
16
+ ("system", "", "mail.smtp_host", False),
17
+ ("system", "", "users.unrelated", False),
18
+ ],
19
+ )
20
+ async def test_mail_obsolete_system_keys(scope, scope_id, key, expected):
21
+ engine = create_async_engine("sqlite+aiosqlite:///:memory:")
22
+ try:
23
+ async with engine.begin() as conn:
24
+ await conn.execute(
25
+ text("CREATE TABLE settings_setting (scope TEXT, scope_id TEXT, key TEXT)")
26
+ )
27
+ await conn.execute(
28
+ text("INSERT INTO settings_setting VALUES (:scope, :scope_id, :key)"),
29
+ {"scope": scope, "scope_id": scope_id, "key": key},
30
+ )
31
+ async with async_sessionmaker(engine)() as db:
32
+ issues = await MailModule().check_data_compatibility(db)
33
+ assert bool(issues) is expected
34
+ if expected:
35
+ assert issues[0].upgrade_id == "mail.settings_namespace_v1"
36
+ assert issues[0].severity == "warning"
37
+ finally:
38
+ await engine.dispose()