app/tests/test_server.py
Carlos Quintana 59957ec08b
chore: fix regex warnings on python 3.12 (#2400)
* deps: update some dependencies to fix warnings

* chore: move from sl.local to sl.lan for local development

* fix: mark string as regex

* chore: move facebook import to handler so its not global

* test: fix tests

* style: lint fixes

* test: move all .test and .local to .lan

* ci: do not use setup-python in lint
2025-02-26 15:41:50 +01:00

55 lines
1.4 KiB
Python

import arrow
from app.config import EMAIL_DOMAIN
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 == f"http://{EMAIL_DOMAIN}/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