app/tests/test_server.py
Carlos Quintana 35f6e67053
feat: user audit log (#2266)
* feat: set up UserAuditLog

* refactor: extract payment callbacks into their own files + handle subscription user_audit_log

* feat: handle account linking for user audit log

* chore: user_audit_log for mailboxes

* chore: user_audit_log for custom domains

* chore: user_audit_log for contacts

* chore: user_audit_log for directories

* fix: do not enforce cronjob being defined in choices + enable user deletion

* chore: user_audit_log for user deletion

* refactor: change emit_user_audit_log function to receive the full user object

* feat: add user_audit_log migration

* test: fix tests

* test: add some tests for user_audit_log

* fix: spf record verification user_audit_log

* chore: add missing index to user_audit_log.created_at

* chore: add missing index to alias_audit_log.created_at
2024-10-16 16:57:59 +02:00

54 lines
1.4 KiB
Python

import arrow
from app.db import Session
from app.models import CoinbaseSubscription
from app.payments.coinbase import handle_coinbase_event
from tests.utils import create_new_user
def test_redirect_login_page(flask_client):
"""Start with a blank database."""
rv = flask_client.get("/")
assert rv.status_code == 302
assert rv.location == "http://sl.test/auth/login"
def test_coinbase_webhook(flask_client):
r = flask_client.post("/coinbase")
assert r.status_code == 400
def test_handle_coinbase_event_new_subscription(flask_client):
user = create_new_user()
handle_coinbase_event(
{"data": {"code": "AAAAAA", "metadata": {"user_id": str(user.id)}}}
)
assert user.is_paid()
assert user.is_premium()
assert CoinbaseSubscription.get_by(user_id=user.id) is not None
def test_handle_coinbase_event_extend_subscription(flask_client):
user = create_new_user()
user.trial_end = None
Session.commit()
cb = CoinbaseSubscription.create(
user_id=user.id, end_at=arrow.now().shift(days=-400), commit=True
)
assert not cb.is_active()
assert not user.is_paid()
assert not user.is_premium()
handle_coinbase_event(
{"data": {"code": "AAAAAA", "metadata": {"user_id": str(user.id)}}}
)
assert user.is_paid()
assert user.is_premium()
assert CoinbaseSubscription.get_by(user_id=user.id) is not None