Close the gaps between the documented contract (API-STANDARD, TENANCY, ENTITLEMENTS) and the implementation, and remove committed build artifacts. Security: - verify + process inbound webhooks (HMAC/handler verify, size limit, timestamp tolerance, idempotency via InboundEvent.external_id) - real 2FA login flow (pre-auth challenge; tokens only after verify/recovery) - wire HybridPermission into security/audit views; add API-key rotate and users/<id>/permissions|roles endpoints - tenant-scoped throttling on by default; webhook replay protection - verify MercadoPago webhook signatures - login brute-force guard, configurable password policy, real ALTCHA PoW Correctness: - apply verified billing webhooks idempotently (subscription/entitlement/ invoice/PaymentTransaction); scheduled payment lifecycle jobs - capture audit update diffs automatically; add audit retention purge - working notification retries, per-channel rate limits, log retention - pluggable virus scanner, upload-size limit, pipeline toggle - feature rollout %/environment targeting; settings-driven registrations - workflow guards (instance cap, route depth, self-assignment, clone on re-entry) - wire every previously-dead INFRASYNTH_* setting; drop truly dead ones Delivery: - README + CHANGELOG; CI format check + coverage gate - keep test media out of the tree; untrack .coverage, __pycache__, egg-info, docs/ and invoice artifacts
96 lines
2.8 KiB
Python
96 lines
2.8 KiB
Python
import pytest
|
|
|
|
from infrasynth.notifications.models import (
|
|
ChannelConfig,
|
|
NotificationDispatch,
|
|
NotificationTemplate,
|
|
)
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
class TestNotificationTemplate:
|
|
def test_create(self):
|
|
template = NotificationTemplate.objects.create(
|
|
slug="welcome",
|
|
name="Welcome",
|
|
channel="email",
|
|
subject_template="Hi {{ name }}",
|
|
body_template="Hello {{ name }}",
|
|
is_html=True,
|
|
)
|
|
assert template.slug == "welcome"
|
|
assert template.is_html is True
|
|
|
|
def test_unique_slug_per_namespace(self):
|
|
NotificationTemplate.objects.create(
|
|
slug="welcome",
|
|
name="A",
|
|
channel="email",
|
|
subject_template="",
|
|
body_template="",
|
|
namespace="",
|
|
)
|
|
NotificationTemplate.objects.create(
|
|
slug="welcome",
|
|
name="B",
|
|
channel="email",
|
|
subject_template="",
|
|
body_template="",
|
|
namespace="other",
|
|
)
|
|
assert NotificationTemplate.objects.count() == 2
|
|
with pytest.raises(Exception):
|
|
NotificationTemplate.objects.create(
|
|
slug="welcome",
|
|
name="C",
|
|
channel="email",
|
|
subject_template="",
|
|
body_template="",
|
|
namespace="",
|
|
)
|
|
|
|
|
|
class TestNotificationDispatch:
|
|
def test_default_status_pending(self, user):
|
|
dispatch = NotificationDispatch.objects.create(
|
|
recipient="a@b.com",
|
|
channel="email",
|
|
subject="S",
|
|
body="B",
|
|
)
|
|
assert dispatch.status == NotificationDispatch.Status.PENDING
|
|
assert dispatch.attempt == 0
|
|
assert dispatch.context_snapshot == {}
|
|
|
|
def test_status_choices(self, user):
|
|
dispatch = NotificationDispatch.objects.create(
|
|
recipient="a@b.com",
|
|
channel="sms",
|
|
subject="S",
|
|
body="B",
|
|
status=NotificationDispatch.Status.FAILED,
|
|
)
|
|
assert dispatch.status == "failed"
|
|
|
|
|
|
class TestChannelConfig:
|
|
def test_create(self):
|
|
config = ChannelConfig.objects.create(
|
|
slug="email",
|
|
channel_type="email",
|
|
display_name="Email",
|
|
config={"host": "smtp.example.com"},
|
|
)
|
|
assert config.config["host"] == "smtp.example.com"
|
|
assert config.is_active is True
|
|
assert config.priority == 0
|
|
|
|
def test_slug_is_per_tenant(self):
|
|
config = ChannelConfig.objects.create(
|
|
slug="telegram",
|
|
channel_type="telegram",
|
|
display_name="Telegram",
|
|
)
|
|
assert config.slug == "telegram"
|
|
assert config.pk != "telegram"
|