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

update has_seats_left on plan service to work properly with self-hosted and DEC #748

Merged
merged 2 commits into from
Aug 13, 2024

Conversation

nora-codecov
Copy link
Contributor

Purpose/Motivation

We calculate seats differently for self-hosted and DEC, this updates the has_seats_left on PlanService to work correctly for self-hosted and DEC.

Links to relevant tickets

https://github.com/codecov/internal-issues/issues/679

What does this PR do?

The function was comparing the total seat count to the number of active users for the Org. With self-hosted and DEC, it will now compare total seat count to the number of unique users across all Orgs.

@nora-codecov nora-codecov requested a review from a team August 13, 2024 01:20
@nora-codecov nora-codecov requested a review from a team as a code owner August 13, 2024 01:20
@codecov-notifications
Copy link

codecov-notifications bot commented Aug 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.06%. Comparing base (163d8cb) to head (0fffb1e).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@               Coverage Diff                @@
##               main       #748        +/-   ##
================================================
+ Coverage   96.05000   96.06000   +0.01000     
================================================
  Files           814        814                
  Lines         18493      18509        +16     
================================================
+ Hits          17764      17780        +16     
  Misses          729        729                
Flag Coverage Δ
unit 91.79% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 91.79% <100.00%> (+<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.

def can_activate_owner(owner: Owner) -> bool:
"""
Returns true iff there are available seats left for activation.
Returns true if there are available seats left for activation.
Copy link
Contributor

Choose a reason for hiding this comment

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

weird how all of these had 2 "f"s lol
Maybe they meant if and only if?

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 is that a shorthand I don't know about either?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

microsoft says it's if and only if but iff only works with 2 statements right? so i think typo

return await sync_to_async(activated_owner_query)()


def activated_owner_query() -> QuerySet:
Copy link
Contributor

Choose a reason for hiding this comment

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

should we be worried about perf at all with this fn? genuinely curious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes 🙃
I gated it behind a license check - so it will only run if the license is valid

Copy link
Contributor

@ajay-sentry ajay-sentry left a comment

Choose a reason for hiding this comment

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

logic looks good, a couple questions

@@ -83,9 +91,15 @@ def license_seats() -> int:
return license.number_allowed_users or 0


async def enterprise_has_seats_left() -> bool:
owners = await activated_owners_async()
Copy link
Contributor

@ajay-sentry ajay-sentry Aug 13, 2024

Choose a reason for hiding this comment

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

Are we able to do the owners.count() here directly on the query set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it throws error if I don't make the count() sync_to_async as well, the tradeoff is that I get to use the same activated_owner_query that is used elsewhere, but i have to do this additional async step

Copy link

Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time.

❌ Failed Test Results:

Completed 2274 tests with 1 failed, 2267 passed and 6 skipped.

View the full list of failed tests

pytest

  • Class name: services.tests.test_self_hosted.SelfHostedTestCase
    Test name: test_license_seats

    self = <services.tests.test_self_hosted.SelfHostedTestCase testMethod=test_license_seats>
    get_current_license = <MagicMock name='get_current_license' id='140209953671936'>

    @patch("services.self_hosted.get_current_license")
    def test_license_seats(self, get_current_license):
    get_current_license.return_value = LicenseInformation(number_allowed_users=123)
    > assert license_seats() == 123
    E assert 0 == 123
    E + where 0 = license_seats()

    services/tests/test_self_hosted.py:91: AssertionError

1 similar comment
@codecov-qa
Copy link

codecov-qa bot commented Aug 13, 2024

Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time.

❌ Failed Test Results:

Completed 2274 tests with 1 failed, 2267 passed and 6 skipped.

View the full list of failed tests

pytest

  • Class name: services.tests.test_self_hosted.SelfHostedTestCase
    Test name: test_license_seats

    self = <services.tests.test_self_hosted.SelfHostedTestCase testMethod=test_license_seats>
    get_current_license = <MagicMock name='get_current_license' id='140209953671936'>

    @patch("services.self_hosted.get_current_license")
    def test_license_seats(self, get_current_license):
    get_current_license.return_value = LicenseInformation(number_allowed_users=123)
    > assert license_seats() == 123
    E assert 0 == 123
    E + where 0 = license_seats()

    services/tests/test_self_hosted.py:91: AssertionError

@nora-codecov nora-codecov added this pull request to the merge queue Aug 13, 2024
Merged via the queue into main with commit 68b2fc7 Aug 13, 2024
17 of 18 checks passed
@nora-codecov nora-codecov deleted the nora/bug branch August 13, 2024 20:59
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.

2 participants