-
Notifications
You must be signed in to change notification settings - Fork 28
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
ref: Remove references to plan and stripe consts #1130
Merged
ajay-sentry
merged 5 commits into
main
from
Ajay/remove-references-to-old-plan-representations
Feb 10, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7218333
remove all old plan representation and stripe id references, fix tests
ajay-sentry 4330f01
ref: Plan query optimizations (#1131)
ajay-sentry aff49b3
add test
ajay-sentry a2a853a
robustness for flaky
ajay-sentry 849c411
Merge branch 'main' into Ajay/remove-references-to-old-plan-represent…
ajay-sentry 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ def get_all_admins_for_owners(owners: QuerySet[Owner]): | |
|
||
|
||
def mock_all_plans_and_tiers(): | ||
TierFactory(tier_name=TierName.BASIC.value) | ||
|
||
trial_tier = TierFactory(tier_name=TierName.TRIAL.value) | ||
PlanFactory( | ||
tier=trial_tier, | ||
|
@@ -39,18 +41,7 @@ def mock_all_plans_and_tiers(): | |
"Unlimited private repositories", | ||
"Priority Support", | ||
], | ||
) | ||
|
||
basic_tier = TierFactory(tier_name=TierName.BASIC.value) | ||
PlanFactory( | ||
name=PlanName.FREE_PLAN_NAME.value, | ||
tier=basic_tier, | ||
marketing_name="Developer", | ||
benefits=[ | ||
"Up to 1 user", | ||
"Unlimited public repositories", | ||
"Unlimited private repositories", | ||
], | ||
stripe_id="plan_trial", | ||
) | ||
|
||
pro_tier = TierFactory(tier_name=TierName.PRO.value) | ||
|
@@ -67,6 +58,7 @@ def mock_all_plans_and_tiers(): | |
billing_rate=BillingRate.MONTHLY.value, | ||
base_unit_price=PlanPrice.MONTHLY.value, | ||
paid_plan=True, | ||
stripe_id="plan_pro", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mocked out the stripe_ids for us here for easy referencing |
||
) | ||
PlanFactory( | ||
name=PlanName.CODECOV_PRO_YEARLY.value, | ||
|
@@ -81,6 +73,7 @@ def mock_all_plans_and_tiers(): | |
billing_rate=BillingRate.ANNUALLY.value, | ||
base_unit_price=PlanPrice.YEARLY.value, | ||
paid_plan=True, | ||
stripe_id="plan_pro_yearly", | ||
) | ||
|
||
team_tier = TierFactory(tier_name=TierName.TEAM.value) | ||
|
@@ -98,6 +91,7 @@ def mock_all_plans_and_tiers(): | |
base_unit_price=PlanPrice.TEAM_MONTHLY.value, | ||
monthly_uploads_limit=2500, | ||
paid_plan=True, | ||
stripe_id="plan_team_monthly", | ||
) | ||
PlanFactory( | ||
name=PlanName.TEAM_YEARLY.value, | ||
|
@@ -113,6 +107,7 @@ def mock_all_plans_and_tiers(): | |
base_unit_price=PlanPrice.TEAM_YEARLY.value, | ||
monthly_uploads_limit=2500, | ||
paid_plan=True, | ||
stripe_id="plan_team_yearly", | ||
) | ||
|
||
sentry_tier = TierFactory(tier_name=TierName.SENTRY.value) | ||
|
@@ -130,6 +125,7 @@ def mock_all_plans_and_tiers(): | |
"Unlimited private repositories", | ||
"Priority Support", | ||
], | ||
stripe_id="plan_sentry_monthly", | ||
) | ||
PlanFactory( | ||
name=PlanName.SENTRY_YEARLY.value, | ||
|
@@ -145,6 +141,7 @@ def mock_all_plans_and_tiers(): | |
"Unlimited private repositories", | ||
"Priority Support", | ||
], | ||
stripe_id="plan_sentry_yearly", | ||
) | ||
|
||
enterprise_tier = TierFactory(tier_name=TierName.ENTERPRISE.value) | ||
|
@@ -161,6 +158,7 @@ def mock_all_plans_and_tiers(): | |
"Unlimited private repositories", | ||
"Priority Support", | ||
], | ||
stripe_id="plan_enterprise_cloud_monthly", | ||
) | ||
PlanFactory( | ||
name=PlanName.ENTERPRISE_CLOUD_YEARLY.value, | ||
|
@@ -175,6 +173,7 @@ def mock_all_plans_and_tiers(): | |
"Unlimited private repositories", | ||
"Priority Support", | ||
], | ||
stripe_id="plan_enterprise_cloud_yearly", | ||
) | ||
|
||
PlanFactory( | ||
|
@@ -190,4 +189,5 @@ def mock_all_plans_and_tiers(): | |
"Unlimited public repositories", | ||
"Unlimited private repositories", | ||
], | ||
stripe_id="plan_default_free", | ||
) |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
from billing.helpers import mock_all_plans_and_tiers | ||
from billing.views import StripeWebhookHandler | ||
from codecov_auth.models import Plan | ||
|
||
from ..constants import StripeHTTPHeaders | ||
|
||
|
@@ -721,7 +722,7 @@ def test_customer_subscription_created_early_returns_if_unverified_payment( | |
"object": { | ||
"id": "sub_123", | ||
"customer": "cus_123", | ||
"plan": {"id": "plan_H6P16wij3lUuxg"}, | ||
"plan": {"id": "plan_pro_yearly"}, | ||
"metadata": {"obo_organization": self.owner.ownerid}, | ||
"quantity": 20, | ||
} | ||
|
@@ -776,7 +777,7 @@ def test_customer_subscription_created_does_nothing_if_plan_not_paid_user_plan( | |
"object": { | ||
"id": "FOEKDCDEQ", | ||
"customer": "sdo050493", | ||
"plan": {"id": "?"}, | ||
"plan": {"id": "plan_free"}, | ||
"metadata": {"obo_organization": self.owner.ownerid}, | ||
"quantity": 20, | ||
} | ||
|
@@ -809,7 +810,7 @@ def test_customer_subscription_created_sets_plan_info( | |
"object": { | ||
"id": stripe_subscription_id, | ||
"customer": stripe_customer_id, | ||
"plan": {"id": "plan_H6P16wij3lUuxg"}, | ||
"plan": {"id": "plan_pro_yearly"}, | ||
"metadata": {"obo_organization": self.owner.ownerid}, | ||
"quantity": quantity, | ||
"status": "active", | ||
|
@@ -849,7 +850,7 @@ def test_customer_subscription_created_can_trigger_trial_expiration( | |
"object": { | ||
"id": stripe_subscription_id, | ||
"customer": stripe_customer_id, | ||
"plan": {"id": "plan_H6P16wij3lUuxg"}, | ||
"plan": {"id": "plan_pro_yearly"}, | ||
"metadata": {"obo_organization": self.owner.ownerid}, | ||
"quantity": quantity, | ||
"default_payment_method": "blabla", | ||
|
@@ -882,7 +883,7 @@ def test_customer_subscription_updated_does_not_change_subscription_if_not_paid_ | |
"object": { | ||
"id": self.owner.stripe_subscription_id, | ||
"customer": self.owner.stripe_customer_id, | ||
"plan": {"id": "?"}, | ||
"plan": {"id": "plan_free"}, | ||
"metadata": {"obo_organization": self.owner.ownerid}, | ||
"quantity": 20, | ||
"status": "active", | ||
|
@@ -929,7 +930,7 @@ def test_customer_subscription_updated_does_not_change_subscription_if_there_is_ | |
"object": { | ||
"id": self.owner.stripe_subscription_id, | ||
"customer": self.owner.stripe_customer_id, | ||
"plan": {"id": "plan_H6P16wij3lUuxg"}, | ||
"plan": {"id": "plan_pro_yearly"}, | ||
"metadata": {"obo_organization": self.owner.ownerid}, | ||
"quantity": 20, | ||
"status": "active", | ||
|
@@ -985,7 +986,7 @@ def test_customer_subscription_updated_sets_free_and_deactivates_all_repos_if_in | |
"id": self.owner.stripe_subscription_id, | ||
"customer": self.owner.stripe_customer_id, | ||
"plan": { | ||
"id": "plan_H6P16wij3lUuxg", | ||
"id": "plan_pro_yearly", | ||
}, | ||
"metadata": {"obo_organization": self.owner.ownerid}, | ||
"quantity": 20, | ||
|
@@ -1088,7 +1089,7 @@ def test_customer_subscription_updated_sets_free_and_deactivates_all_repos_if_in | |
"id": self.owner.stripe_subscription_id, | ||
"customer": self.owner.stripe_customer_id, | ||
"plan": { | ||
"id": "plan_H6P16wij3lUuxg", | ||
"id": "plan_pro_yearly", | ||
}, | ||
"metadata": {"obo_organization": self.owner.ownerid}, | ||
"quantity": 20, | ||
|
@@ -1149,7 +1150,7 @@ def test_customer_subscription_updated_sets_fields_on_success( | |
"object": { | ||
"id": self.owner.stripe_subscription_id, | ||
"customer": self.owner.stripe_customer_id, | ||
"plan": {"id": "plan_H6P16wij3lUuxg"}, | ||
"plan": {"id": "plan_pro_yearly"}, | ||
"metadata": {"obo_organization": self.owner.ownerid}, | ||
"quantity": quantity, | ||
"status": "active", | ||
|
@@ -1200,7 +1201,7 @@ def test_customer_subscription_updated_sets_fields_on_success_multiple_owner( | |
"object": { | ||
"id": self.owner.stripe_subscription_id, | ||
"customer": self.owner.stripe_customer_id, | ||
"plan": {"id": "plan_H6P16wij3lUuxg"}, | ||
"plan": {"id": "plan_pro_yearly"}, | ||
"metadata": {"obo_organization": self.owner.ownerid}, | ||
"quantity": quantity, | ||
"status": "active", | ||
|
@@ -1238,7 +1239,7 @@ def test_customer_subscription_updated_logs_error_if_no_matching_owners( | |
"object": { | ||
"id": "sub_notexist", | ||
"customer": "cus_notexist", | ||
"plan": {"id": "plan_H6P16wij3lUuxg"}, | ||
"plan": {"id": "plan_pro_yearly"}, | ||
"metadata": {"obo_organization": 1}, | ||
"quantity": 8, | ||
"status": "active", | ||
|
@@ -1254,7 +1255,7 @@ def test_customer_subscription_updated_logs_error_if_no_matching_owners( | |
extra={ | ||
"stripe_subscription_id": "sub_notexist", | ||
"stripe_customer_id": "cus_notexist", | ||
"plan_id": "plan_H6P16wij3lUuxg", | ||
"plan_id": "plan_pro_yearly", | ||
}, | ||
) | ||
|
||
|
@@ -1267,7 +1268,7 @@ def test_subscription_schedule_released_updates_owner_with_existing_subscription | |
self.owner.save() | ||
|
||
self.new_params = { | ||
"new_plan": "plan_H6P3KZXwmAbqPS", | ||
"new_plan": "plan_pro_yearly", | ||
"new_quantity": 7, | ||
"subscription_id": "sub_123", | ||
} | ||
|
@@ -1288,7 +1289,8 @@ def test_subscription_schedule_released_updates_owner_with_existing_subscription | |
) | ||
|
||
self.owner.refresh_from_db() | ||
assert self.owner.plan == settings.STRIPE_PLAN_VALS[self.new_params["new_plan"]] | ||
plan = Plan.objects.get(stripe_id=self.new_params["new_plan"]) | ||
assert self.owner.plan == plan.name | ||
assert self.owner.plan_user_count == self.new_params["new_quantity"] | ||
|
||
@patch("services.billing.stripe.Subscription.retrieve") | ||
|
@@ -1304,7 +1306,7 @@ def test_subscription_schedule_released_updates_multiple_owners_with_existing_su | |
self.other_owner.save() | ||
|
||
self.new_params = { | ||
"new_plan": "plan_H6P3KZXwmAbqPS", | ||
"new_plan": "plan_pro_yearly", | ||
"new_quantity": 7, | ||
"subscription_id": "sub_123", | ||
} | ||
|
@@ -1326,12 +1328,11 @@ def test_subscription_schedule_released_updates_multiple_owners_with_existing_su | |
|
||
self.owner.refresh_from_db() | ||
self.other_owner.refresh_from_db() | ||
assert self.owner.plan == settings.STRIPE_PLAN_VALS[self.new_params["new_plan"]] | ||
|
||
plan = Plan.objects.get(stripe_id=self.new_params["new_plan"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had to change up the assertions a bit here to match |
||
assert self.owner.plan == plan.name | ||
assert self.owner.plan_user_count == self.new_params["new_quantity"] | ||
assert ( | ||
self.other_owner.plan | ||
== settings.STRIPE_PLAN_VALS[self.new_params["new_plan"]] | ||
) | ||
assert self.other_owner.plan == plan.name | ||
assert self.other_owner.plan_user_count == self.new_params["new_quantity"] | ||
|
||
@patch("logging.Logger.error") | ||
|
@@ -1342,7 +1343,7 @@ def test_subscription_schedule_released_logs_error_if_owner_does_not_exist( | |
log_error_mock, | ||
): | ||
self.new_params = { | ||
"new_plan": "plan_H6P3KZXwmAbqPS", | ||
"new_plan": "plan_pro_yearly", | ||
"new_quantity": 7, | ||
"subscription_id": "sub_notexist", | ||
} | ||
|
@@ -1367,7 +1368,7 @@ def test_subscription_schedule_released_logs_error_if_owner_does_not_exist( | |
extra={ | ||
"stripe_subscription_id": "sub_notexist", | ||
"stripe_customer_id": "cus_123", | ||
"plan_id": "plan_H6P3KZXwmAbqPS", | ||
"plan_id": "plan_pro_yearly", | ||
}, | ||
) | ||
|
||
|
@@ -1383,7 +1384,7 @@ def test_subscription_schedule_created_logs_a_new_schedule( | |
self.owner.save() | ||
|
||
self.params = { | ||
"new_plan": "plan_H6P3KZXwmAbqPS", | ||
"new_plan": "plan_pro_yearly", | ||
"new_quantity": 7, | ||
"subscription_id": subscription_id, | ||
} | ||
|
@@ -1410,7 +1411,7 @@ def test_subscription_schedule_updated_logs_changes_to_schedule( | |
original_plan = "users-pr-inappy" | ||
original_quantity = 10 | ||
subscription_id = "sub_1K8xfkGlVGuVgOrkxvroyZdH" | ||
new_plan = "plan_H6P3KZXwmAbqPS" | ||
new_plan = "plan_pro_yearly" | ||
new_quantity = 7 | ||
self.owner.plan = original_plan | ||
self.owner.plan_user_count = original_quantity | ||
|
Oops, something went wrong.
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.
This was so much cleaner to me
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.
ya previous way was so annoying