Skip to content
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
merged 5 commits into from
Feb 10, 2025

Conversation

ajay-sentry
Copy link
Contributor

@ajay-sentry ajay-sentry commented Feb 5, 2025

Purpose/Motivation

This PR is meant to clean up the final few references of the "plan constants" that are no longer needed since migration to the Plan and Tiers tables.

As part of the cleanup, not only are we removing references to those plans but also to the "stripe id": "plan name" maps for dev/stage/prod which have also been ported over to the plan table.

I'm not sure if it would really matter but probably better to keep references to our plans, even if they're hashed values, away from the client as we modify or add more plans in the future. Plus, it's one less thing for us to mangle our way around and I felt like the queries on them for fetching are much easier to parse (much, much easier in some cases).

Tested:

  • Local upgrades / swaps / seat changes / and cancellations for plans
  • Double checked the plan reference maps in stage / prod with their associated stripe values in their console ✅

Links to relevant tickets

Closes codecov/engineering-team#3321

Notes to Reviewer

Anything to note to the team? Any tips on how to review, or where to start?

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@ajay-sentry ajay-sentry changed the title remove all old plan representation and stripe id references, fix tests ref: Remove references to plan and stripe consts Feb 5, 2025
list(stripe_plan_dict.values()).index(plan_id)
]
marketing_plan_name = Plan.objects.get(name=plan_name).marketing_name
marketing_plan_name = Plan.objects.get(stripe_id=plan_id).marketing_name
Copy link
Contributor Author

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

Copy link
Contributor

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

@@ -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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mocked out the stripe_ids for us here for easy referencing

@@ -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"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to change up the assertions a bit here to match

@@ -1,114 +0,0 @@
from datetime import datetime
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this command since it was a 1 time script and had some references in there that I didn't want to update

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 94.87179% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.03%. Comparing base (4ed721d) to head (849c411).
Report is 6 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
services/billing.py 91.30% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1130   +/-   ##
=======================================
  Coverage   96.02%   96.03%           
=======================================
  Files         837      837           
  Lines       19763    19761    -2     
=======================================
  Hits        18978    18978           
+ Misses        785      783    -2     
Flag Coverage Δ
unit 95.92% <94.87%> (+0.01%) ⬆️
unit-latest-uploader 95.92% <94.87%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link

codecov-notifications bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 94.87179% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
services/billing.py 91.30% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 94.87179% with 2 lines in your changes missing coverage. Please review.

Project coverage is 95.92%. Comparing base (4ed721d) to head (849c411).
Report is 6 commits behind head on main.

✅ All tests successful. No failed tests found.

Copy link
Contributor

github-actions bot commented Feb 5, 2025

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

"price_1Mj1mMGlVGuVgOrkC0ORc6iW": "users-sentryy",
"price_1OCM0gGlVGuVgOrkWDYEBtSL": "users-teamm",
"price_1OCM2cGlVGuVgOrkMWUFjPFz": "users-teamy",
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICE

extra=dict(owner_id=owner.ownerid),
)
return

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much better ☺️

@@ -202,7 +201,6 @@ def test_inline_orgwide_add_token_permission_no_token_and_user_in_enterprise_clo
self,
):
owner = OwnerFactory(plan=DEFAULT_FREE_PLAN)
assert owner.plan not in ENTERPRISE_CLOUD_USER_PLAN_REPRESENTATIONS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I removed this assertion because the plan is defaulted to the free plan the line before, didn't really make sense to me

@@ -404,6 +413,14 @@ def _modify_subscription_schedule(
current_plan = subscription_item["plan"]["id"]
current_quantity = subscription_item["quantity"]

plan = Plan.objects.filter(name=desired_plan["value"]).first()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would add some tests to both of these if possible

Copy link

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2738 1 2737 6
View the top 1 failed tests by shortest run time
services/tests/test_billing.py::StripeServiceTests::test_modify_subscription_no_plan_found
Stack Traces | 0.04s run time
self = <MagicMock name='error' id='140269164617728'>
args = ('Plan invalid plan not found',), kwargs = {'extra': {'owner_id': 1854}}
msg = 'Expected \'error\' to be called once. Called 2 times.\nCalls: [call(\'Internal error in sentry_sdk\', exc_info=(<clas...tream"), <traceback object at 0x7f92f4785a40>)),\n call(\'Plan invalid plan not found\', extra={\'owner_id\': 1854})].'

    def assert_called_once_with(self, /, *args, **kwargs):
        """assert that the mock was called exactly once and that that call was
        with the specified arguments."""
        if not self.call_count == 1:
            msg = ("Expected '%s' to be called once. Called %s times.%s"
                   % (self._mock_name or 'mock',
                      self.call_count,
                      self._calls_repr()))
>           raise AssertionError(msg)
E           AssertionError: Expected 'error' to be called once. Called 2 times.
E           Calls: [call('Internal error in sentry_sdk', exc_info=(<class 'django.http.request.RawPostDataException'>, RawPostDataException("You cannot access body after reading from request's data stream"), <traceback object at 0x7f92f4785a40>)),
E            call('Plan invalid plan not found', extra={'owner_id': 1854})].

.../local/lib/python3.12/unittest/mock.py:960: AssertionError

During handling of the above exception, another exception occurred:

self = <services.tests.test_billing.StripeServiceTests testMethod=test_modify_subscription_no_plan_found>
log_error_mock = <MagicMock name='error' id='140269164617728'>

    @patch("logging.Logger.error")
    def test_modify_subscription_no_plan_found(
        self,
        log_error_mock,
    ):
        original_plan = PlanName.CODECOV_PRO_MONTHLY.value
        original_user_count = 10
        owner = OwnerFactory(
            plan=original_plan,
            plan_user_count=original_user_count,
            stripe_subscription_id="33043sdf",
        )
    
        desired_plan_name = "invalid plan"
        desired_user_count = 10
        desired_plan = {"value": desired_plan_name, "quantity": desired_user_count}
        self.stripe.modify_subscription(owner, desired_plan)
    
        owner.refresh_from_db()
        assert owner.plan == original_plan
        assert owner.plan_user_count == original_user_count
>       log_error_mock.assert_called_once_with(
            f"Plan {desired_plan_name} not found",
            extra=dict(owner_id=owner.ownerid),
        )
E       AssertionError: Expected 'error' to be called once. Called 2 times.
E       Calls: [call('Internal error in sentry_sdk', exc_info=(<class 'django.http.request.RawPostDataException'>, RawPostDataException("You cannot access body after reading from request's data stream"), <traceback object at 0x7f92f4785a40>)),
E        call('Plan invalid plan not found', extra={'owner_id': 1854})].

services/tests/test_billing.py:718: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

@ajay-sentry ajay-sentry added this pull request to the merge queue Feb 10, 2025
Merged via the queue into main with commit 66e1efd Feb 10, 2025
28 of 32 checks passed
@ajay-sentry ajay-sentry deleted the Ajay/remove-references-to-old-plan-representations branch February 10, 2025 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove references to plan / stripe consts in API
3 participants