-
-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lifetime in partner subscriptions #2331
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""empty message | ||
|
||
Revision ID: 085f77996ce3 | ||
Revises: 0f3ee15b0014 | ||
Create Date: 2024-11-26 19:20:32.227899 | ||
|
||
""" | ||
import sqlalchemy_utils | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '085f77996ce3' | ||
down_revision = '0f3ee15b0014' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('partner_subscription', sa.Column('lifetime', sa.Boolean(), server_default='0', nullable=False)) | ||
op.alter_column('partner_subscription', 'end_at', | ||
existing_type=postgresql.TIMESTAMP(), | ||
nullable=True) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('partner_subscription', 'end_at', | ||
existing_type=postgresql.TIMESTAMP(), | ||
nullable=False) | ||
op.drop_column('partner_subscription', 'lifetime') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import arrow | ||
|
||
from app.account_linking import ( | ||
SLPlan, | ||
SLPlanType, | ||
set_plan_for_partner_user, | ||
) | ||
from app.db import Session | ||
from app.models import User, PartnerUser, PartnerSubscription | ||
from app.proton.utils import get_proton_partner | ||
from app.utils import random_string | ||
from tests.utils import random_email | ||
|
||
partner_user_id: int = 0 | ||
|
||
|
||
def setup_module(): | ||
global partner_user_id | ||
email = random_email() | ||
external_id = random_string() | ||
sl_user = User.create(email, commit=True) | ||
partner_user_id = PartnerUser.create( | ||
user_id=sl_user.id, | ||
partner_id=get_proton_partner().id, | ||
external_user_id=external_id, | ||
partner_email=email, | ||
commit=True, | ||
).id | ||
|
||
|
||
def setup_function(func): | ||
Session.query(PartnerSubscription).delete() | ||
|
||
|
||
def test_free_plan_removes_sub(): | ||
pu = PartnerUser.get(partner_user_id) | ||
sub_id = PartnerSubscription.create( | ||
partner_user_id=partner_user_id, | ||
end_at=arrow.utcnow(), | ||
lifetime=False, | ||
commit=True, | ||
).id | ||
set_plan_for_partner_user(pu, plan=SLPlan(type=SLPlanType.Free, expiration=None)) | ||
assert PartnerSubscription.get(sub_id) is None | ||
|
||
|
||
def test_premium_plan_updates_expiration(): | ||
pu = PartnerUser.get(partner_user_id) | ||
sub_id = PartnerSubscription.create( | ||
partner_user_id=partner_user_id, | ||
end_at=arrow.utcnow(), | ||
lifetime=False, | ||
commit=True, | ||
).id | ||
new_expiration = arrow.utcnow().shift(days=+10) | ||
set_plan_for_partner_user( | ||
pu, plan=SLPlan(type=SLPlanType.Premium, expiration=new_expiration) | ||
) | ||
assert PartnerSubscription.get(sub_id).end_at == new_expiration | ||
|
||
|
||
def test_premium_plan_creates_sub(): | ||
pu = PartnerUser.get(partner_user_id) | ||
new_expiration = arrow.utcnow().shift(days=+10) | ||
set_plan_for_partner_user( | ||
pu, plan=SLPlan(type=SLPlanType.Premium, expiration=new_expiration) | ||
) | ||
assert ( | ||
PartnerSubscription.get_by(partner_user_id=partner_user_id).end_at | ||
== new_expiration | ||
) | ||
|
||
|
||
def test_lifetime_creates_sub(): | ||
pu = PartnerUser.get(partner_user_id) | ||
new_expiration = arrow.utcnow().shift(days=+10) | ||
set_plan_for_partner_user( | ||
pu, plan=SLPlan(type=SLPlanType.PremiumLifetime, expiration=new_expiration) | ||
) | ||
sub = PartnerSubscription.get_by(partner_user_id=partner_user_id) | ||
assert sub is not None | ||
assert sub.end_at is None | ||
assert sub.lifetime | ||
|
||
|
||
def test_lifetime_updates_sub(): | ||
pu = PartnerUser.get(partner_user_id) | ||
sub_id = PartnerSubscription.create( | ||
partner_user_id=partner_user_id, | ||
end_at=arrow.utcnow(), | ||
lifetime=False, | ||
commit=True, | ||
).id | ||
set_plan_for_partner_user( | ||
pu, plan=SLPlan(type=SLPlanType.PremiumLifetime, expiration=arrow.utcnow()) | ||
) | ||
sub = PartnerSubscription.get(sub_id) | ||
assert sub is not None | ||
assert sub.end_at is None | ||
assert sub.lifetime |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this function implemented? I cannot find it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good one. fixed.