clipwright/tests/test_metering_free_plan.py
juancarlos.cavero 26135fb485 feat(abuse): abrir free a email normal + bloquear dominios desechables
El free ya no exige Google: cualquier cuenta Google o de email permanente
entra. Para que no sea un grifo de minutos gratis:
- Bloqueo de dominios desechables/temp-mail en el registro por email
  (cloud/disposable_domains.txt, 155 dominios: los clásicos temp-mail + los
  vistos en nuestra propia DB). Refrescable desde el proyecto upstream.
- Normalización de alias: gmail dots/+tags y +tags de otros proveedores se
  colapsan a una sola cuenta canónica, para que foo+1@ / f.oo@ no minten
  cuentas infinitas. Aplicado en magic-link y en Google OAuth.
- free_plan_eligible: Google siempre; email solo si el dominio no es
  desechable (defensa en profundidad además del bloqueo en registro).
- Popup de bienvenida ahora sale una vez por navegador en el primer registro
  (Google o email), no solo a los no-entitled; el botón free arranca directo
  sin forzar Google.

Verificado: registro con mailinator/luckfeed -> 400; gmail -> 200. 115 tests
(9 nuevos de email_policy).
2026-07-21 00:45:54 +02:00

55 lines
2.3 KiB
Python

"""Free-plan eligibility and synthetic period logic (pure functions, no DB)."""
from datetime import datetime, timezone
from types import SimpleNamespace
import pytest
from cloud import config, metering
def _user(google_sub="g-123", email="x@gmail.com"):
return SimpleNamespace(google_sub=google_sub, email=email)
class TestFreePlanEligible:
def test_google_user_is_eligible(self):
assert metering.free_plan_eligible(_user()) is True
def test_permanent_email_user_is_eligible(self):
# Free is open to real email accounts now, not just Google.
assert metering.free_plan_eligible(_user(google_sub=None, email="real@gmail.com")) is True
assert metering.free_plan_eligible(_user(google_sub=None, email="real@outlook.com")) is True
def test_disposable_email_user_is_not_eligible(self):
assert metering.free_plan_eligible(_user(google_sub=None, email="x@mailinator.com")) is False
assert metering.free_plan_eligible(_user(google_sub=None, email="x@luckfeed.com")) is False
def test_none_user_is_not_eligible(self):
assert metering.free_plan_eligible(None) is False
def test_zero_minutes_disables_free_plan(self, monkeypatch):
monkeypatch.setattr(config, "FREE_PLAN_MINUTES", 0)
assert metering.free_plan_eligible(_user()) is False
class TestFreePeriodEnd:
@pytest.mark.parametrize("now, expected", [
(datetime(2026, 7, 20, 12, 30, tzinfo=timezone.utc),
datetime(2026, 8, 1, tzinfo=timezone.utc)),
(datetime(2026, 12, 31, 23, 59, 59, tzinfo=timezone.utc),
datetime(2027, 1, 1, tzinfo=timezone.utc)),
(datetime(2026, 1, 1, 0, 0, 0, tzinfo=timezone.utc),
datetime(2026, 2, 1, tzinfo=timezone.utc)),
])
def test_first_instant_of_next_month(self, now, expected):
assert metering.free_period_end(now) == expected
def test_stable_within_a_month(self):
a = metering.free_period_end(datetime(2026, 7, 1, tzinfo=timezone.utc))
b = metering.free_period_end(datetime(2026, 7, 31, 23, 59, tzinfo=timezone.utc))
assert a == b
def test_rolls_over_at_month_boundary(self):
july = metering.free_period_end(datetime(2026, 7, 31, 23, 59, tzinfo=timezone.utc))
august = metering.free_period_end(datetime(2026, 8, 1, 0, 0, 1, tzinfo=timezone.utc))
assert august > july