-
Notifications
You must be signed in to change notification settings - Fork 10
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
Fix plan_activated_users count for an installation #132
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
34f7582
Fix test_activate_user_failure_for_enterprise_pr_billing_no_seats
joseph-sentry 664b633
Fix get_installation_plan_activated_users when there is the same user…
joseph-sentry d56aa54
address feedback
joseph-sentry 6c00d0f
improve tests so that non-overlap is more than license accepts
joseph-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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import pytest | ||
|
||
from database.tests.factories import OwnerFactory | ||
from services.activation import activate_user | ||
from services.activation import activate_user, get_installation_plan_activated_users | ||
from services.license import _get_now, is_enterprise | ||
|
||
|
||
|
@@ -62,7 +62,6 @@ def test_activate_user_success_for_users_free( | |
def test_activate_user_success_for_enterprise_pr_billing( | ||
self, request, dbsession, mocker, mock_configuration, with_sql_functions | ||
): | ||
|
||
mocker.patch("services.license.is_enterprise", return_value=True) | ||
mocker.patch("services.license._get_now", return_value=datetime(2020, 4, 2)) | ||
|
||
|
@@ -89,11 +88,60 @@ def test_activate_user_success_for_enterprise_pr_billing( | |
dbsession.commit() | ||
assert user.ownerid in org.plan_activated_users | ||
|
||
def test_activate_user_success_user_org_overlap( | ||
self, request, dbsession, mock_configuration, mocker, with_sql_functions | ||
): | ||
mocker.patch("services.license.is_enterprise", return_value=True) | ||
mocker.patch("services.license._get_now", return_value=datetime(2020, 4, 2)) | ||
|
||
# Create two orgs to ensure our seat availability checking works across | ||
# multiple organizations. | ||
org = OwnerFactory.create( | ||
service="github", | ||
oauth_token=None, | ||
plan_activated_users=list(range(1, 6)), | ||
plan_auto_activate=True, | ||
) | ||
dbsession.add(org) | ||
dbsession.flush() | ||
|
||
org_second = OwnerFactory.create( | ||
service="github", | ||
oauth_token=None, | ||
plan_activated_users=list(range(2, 8)), | ||
plan_auto_activate=True, | ||
) | ||
dbsession.add(org_second) | ||
dbsession.flush() | ||
|
||
assert get_installation_plan_activated_users(dbsession)[0][0] == 7 | ||
|
||
# {'company': 'Test Company', 'expires': '2021-01-01 00:00:00', 'url': 'https://codecov.mysite.com', 'trial': False, 'users': 10, 'repos': None, 'pr_billing': True} | ||
encrypted_license = "wxWEJyYgIcFpi6nBSyKQZQeaQ9Eqpo3SXyUomAqQOzOFjdYB3A8fFM1rm+kOt2ehy9w95AzrQqrqfxi9HJIb2zLOMOB9tSy52OykVCzFtKPBNsXU/y5pQKOfV7iI3w9CHFh3tDwSwgjg8UsMXwQPOhrpvl2GdHpwEhFdaM2O3vY7iElFgZfk5D9E7qEnp+WysQwHKxDeKLI7jWCnBCBJLDjBJRSz0H7AfU55RQDqtTrnR+rsLDHOzJ80/VxwVYhb" | ||
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. How many seats does this license allows for? 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. added a comment to the code |
||
mock_configuration.params["setup"]["enterprise_license"] = encrypted_license | ||
mock_configuration.params["setup"]["codecov_url"] = "https://codecov.mysite.com" | ||
|
||
user = OwnerFactory.create_from_test_request(request) | ||
dbsession.add(org_second) | ||
dbsession.add(user) | ||
dbsession.flush() | ||
|
||
was_activated = activate_user(dbsession, org_second.ownerid, user.ownerid) | ||
assert was_activated is True | ||
dbsession.commit() | ||
|
||
was_activated = activate_user(dbsession, org.ownerid, user.ownerid) | ||
assert was_activated is True | ||
dbsession.commit() | ||
|
||
assert get_installation_plan_activated_users(dbsession)[0][0] == 8 | ||
|
||
def test_activate_user_failure_for_enterprise_pr_billing_no_seats( | ||
self, request, dbsession, mock_configuration, mocker, with_sql_functions | ||
): | ||
mocker.patch("services.license.is_enterprise", return_value=True) | ||
mocker.patch("services.license._get_now", return_value=datetime(2020, 4, 2)) | ||
|
||
mocker.patch("helpers.environment.is_enterprise", return_value=True) | ||
# Create two orgs to ensure our seat availability checking works across | ||
# multiple organizations. | ||
org = OwnerFactory.create( | ||
|
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.
I'm not sure I understand this test case.
I looks like you are creating 2 orgs with 5 seats taken each. Idk how many total seats this installation (self-hosted) can have. But it seems that all owners of the 2 orgs are distinct (e.g. with different IDs)
So the total count of seats used is 10, and you create a new owner to prove that we can extend that.
Is that the idea?
(assuming I'm correct - which I might very well not be)
What I'd like to see:
get_installation_plan_activated_users
explicitly to see what users are activated (before and after creating the new user)