app-MAIL-temp/tests/models/test_partner_subscription.py
Carlos Quintana c0a4c44e94
Separate code for proton callback handler (#1040)
* Separate code for proton callback handler

* Upgrade migration

* Use simple_login endpoint from Proton API

* Remove unused classes

* Rename Dto class to Data

* Push rename

* Moved link to PartnerUser to allow subscriptions to depend only on it

* Fix test

* PR comments

* Add unique user_id constraint to PartnerUser

* Added more logs

* Added more logs

Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
2022-06-09 10:19:49 +02:00

37 lines
1.1 KiB
Python

from arrow import Arrow
from app.models import Partner, PartnerUser, PartnerSubscription
from app.utils import random_string
from tests.utils import create_new_user, random_email
def test_generate_partner_subscription(flask_client):
partner = Partner.create(
name=random_string(10),
contact_email=random_email(),
commit=True,
)
user = create_new_user()
partner_user = PartnerUser.create(
user_id=user.id,
partner_id=partner.id,
partner_email=random_email(),
commit=True,
)
subs = PartnerSubscription.create(
partner_user_id=partner_user.id,
end_at=Arrow.utcnow().shift(hours=1),
commit=True,
)
retrieved_subscription = PartnerSubscription.find_by_user_id(user.id)
assert retrieved_subscription is not None
assert retrieved_subscription.id == subs.id
assert user.lifetime_or_active_subscription() is True
def test_partner_subscription_for_not_partner_subscription_user(flask_client):
unexistant_subscription = PartnerSubscription.find_by_user_id(999999)
assert unexistant_subscription is None