-
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
Worker: Migrate to Plan / Tier Tables #1007
Merged
Merged
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1be033f
worker plan updates to use new plan model
ajay-sentry a272a6a
Merge branch 'main' into Ajay/milestone-3-migration
ajay-sentry ccc2534
Merge branch 'main' into Ajay/milestone-3-migration
ajay-sentry 7216f13
81 failing tests, realized should start with shared
ajay-sentry b22b6e0
Merge branch 'main' into Ajay/milestone-3-migration
RulaKhaled aaffe2d
resolve all unit tests
RulaKhaled fe2f21e
resolve all unit tests
RulaKhaled 0a938c6
get rid of prints
ajay-sentry 9fdf81c
prefetch tier when needed
ajay-sentry f1eb632
Merge branch 'main' into Ajay/milestone-3-migration
RulaKhaled 70f7dea
Merge branch 'main' into Ajay/milestone-3-migration
ajay-sentry cdc672e
update to not use @patch(services.notification.Plan.objects.get)
RulaKhaled 481d3a9
update with more tests
RulaKhaled da4ed81
update with shared version
RulaKhaled 2002db3
Merge branch 'main' into Ajay/milestone-3-migration
RulaKhaled 1c43bb0
Merge branch 'main' into Ajay/milestone-3-migration
ajay-sentry 801ad17
testing stage
ajay-sentry 111e942
fix tests
ajay-sentry 0aa6e04
fix these other tests
ajay-sentry 759bc66
update with new shared version
RulaKhaled 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
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import os | ||
from asyncio import CancelledError | ||
from asyncio import TimeoutError as AsyncioTimeoutError | ||
from unittest.mock import patch | ||
|
||
import mock | ||
import pytest | ||
from celery.exceptions import SoftTimeLimitExceeded | ||
from shared.plan.constants import PlanName | ||
from shared.plan.constants import PlanName, TierName | ||
from shared.reports.resources import Report, ReportFile, ReportLine | ||
from shared.torngit.status import Status | ||
from shared.yaml import UserYaml | ||
|
@@ -16,6 +17,7 @@ | |
GithubAppInstallation, | ||
) | ||
from database.tests.factories import CommitFactory, PullFactory, RepositoryFactory | ||
from database.tests.factories.core import PlanFactory, TierFactory | ||
from services.comparison import ComparisonProxy | ||
from services.comparison.types import Comparison, EnrichedPull, FullCommit | ||
from services.notification import NotificationService | ||
|
@@ -103,9 +105,13 @@ def test_should_use_checks_notifier_yaml_field_false(self, dbsession): | |
), | ||
], | ||
) | ||
@patch("services.notification.Plan.objects.get") | ||
def test_should_use_checks_notifier_deprecated_flow( | ||
self, repo_data, outcome, dbsession | ||
self, plan_objects_get, repo_data, outcome, dbsession | ||
): | ||
plan = PlanFactory.create() | ||
plan_objects_get.return_value = 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. I have some questions, and see some problems with this:
I believe that also in production, we should not mix these two ORMs, as that can potentially cause deadlocks. |
||
|
||
repository = RepositoryFactory.create(**repo_data) | ||
current_yaml = {"github_checks": True} | ||
assert repository.owner.github_app_installations == [] | ||
|
@@ -115,7 +121,12 @@ def test_should_use_checks_notifier_deprecated_flow( | |
== outcome | ||
) | ||
|
||
def test_should_use_checks_notifier_ghapp_all_repos_covered(self, dbsession): | ||
@patch("services.notification.Plan.objects.get") | ||
def test_should_use_checks_notifier_ghapp_all_repos_covered( | ||
self, plan_objects_get, dbsession | ||
): | ||
plan = PlanFactory.create() | ||
plan_objects_get.return_value = plan | ||
repository = RepositoryFactory.create(owner__service="github") | ||
ghapp_installation = GithubAppInstallation( | ||
name=GITHUB_APP_INSTALLATION_DEFAULT_NAME, | ||
|
@@ -133,9 +144,19 @@ def test_should_use_checks_notifier_ghapp_all_repos_covered(self, dbsession): | |
== True | ||
) | ||
|
||
def test_use_checks_notifier_for_team_plan(self, dbsession): | ||
@patch("services.notification.Plan.objects.get") | ||
def test_use_checks_notifier_for_team_plan( | ||
self, | ||
plan_objects_get, | ||
dbsession, | ||
): | ||
tier = TierFactory.create( | ||
tier_name=TierName.TEAM.value, | ||
) | ||
plan = PlanFactory.create(tier=tier, name=PlanName.TEAM_MONTHLY.value) | ||
plan_objects_get.return_value = plan | ||
repository = RepositoryFactory.create( | ||
owner__service="github", owner__plan=PlanName.TEAM_MONTHLY.value | ||
owner__service="github", owner__plan=plan.name | ||
) | ||
ghapp_installation = GithubAppInstallation( | ||
name=GITHUB_APP_INSTALLATION_DEFAULT_NAME, | ||
|
@@ -161,9 +182,16 @@ def test_use_checks_notifier_for_team_plan(self, dbsession): | |
== True | ||
) | ||
|
||
def test_use_status_notifier_for_team_plan(self, dbsession): | ||
@patch("services.notification.Plan.objects.get") | ||
def test_use_status_notifier_for_team_plan(self, plan_objects_get, dbsession): | ||
tier = TierFactory.create( | ||
tier_name=TierName.TEAM.value, | ||
) | ||
plan = PlanFactory.create(tier=tier, name=PlanName.TEAM_MONTHLY.value) | ||
plan_objects_get.return_value = plan | ||
|
||
repository = RepositoryFactory.create( | ||
owner__service="github", owner__plan=PlanName.TEAM_MONTHLY.value | ||
owner__service="github", owner__plan=plan.name | ||
) | ||
ghapp_installation = GithubAppInstallation( | ||
name=GITHUB_APP_INSTALLATION_DEFAULT_NAME, | ||
|
@@ -189,9 +217,15 @@ def test_use_status_notifier_for_team_plan(self, dbsession): | |
== True | ||
) | ||
|
||
def test_use_status_notifier_for_non_team_plan(self, dbsession): | ||
@patch("services.notification.Plan.objects.get") | ||
def test_use_status_notifier_for_non_team_plan(self, plan_objects_get, dbsession): | ||
tier = TierFactory.create( | ||
tier_name=TierName.PRO.value, | ||
) | ||
plan = PlanFactory.create(tier=tier, name=PlanName.CODECOV_PRO_MONTHLY.value) | ||
plan_objects_get.return_value = plan | ||
repository = RepositoryFactory.create( | ||
owner__service="github", owner__plan=PlanName.CODECOV_PRO_MONTHLY.value | ||
owner__service="github", owner__plan=plan.name | ||
) | ||
ghapp_installation = GithubAppInstallation( | ||
name=GITHUB_APP_INSTALLATION_DEFAULT_NAME, | ||
|
@@ -221,9 +255,12 @@ def test_use_status_notifier_for_non_team_plan(self, dbsession): | |
"gh_installation_name", | ||
[GITHUB_APP_INSTALLATION_DEFAULT_NAME, "notifications-app"], | ||
) | ||
@patch("services.notification.Plan.objects.get") | ||
def test_should_use_checks_notifier_ghapp_some_repos_covered( | ||
self, dbsession, gh_installation_name | ||
self, plan_objects_get, dbsession, gh_installation_name | ||
): | ||
plan = PlanFactory.create() | ||
plan_objects_get.return_value = plan | ||
repository = RepositoryFactory.create(owner__service="github") | ||
other_repo_same_owner = RepositoryFactory.create(owner=repository.owner) | ||
ghapp_installation = GithubAppInstallation( | ||
|
@@ -281,9 +318,12 @@ def test_get_notifiers_instances_only_third_party( | |
assert instance.site_settings == ["slack.com"] | ||
assert instance.current_yaml == current_yaml | ||
|
||
@patch("services.notification.Plan.objects.get") | ||
def test_get_notifiers_instances_checks( | ||
self, dbsession, mock_configuration, mocker | ||
self, plan_objects_get, dbsession, mock_configuration, mocker | ||
): | ||
plan = PlanFactory.create() | ||
plan_objects_get.return_value = plan | ||
repository = RepositoryFactory.create( | ||
owner__integration_id=123, | ||
owner__service="github", | ||
|
@@ -310,9 +350,12 @@ def test_get_notifiers_instances_checks( | |
"codecov-slack-app", | ||
] | ||
|
||
@patch("services.notification.Plan.objects.get") | ||
def test_get_notifiers_instances_slack_app_false( | ||
self, dbsession, mock_configuration, mocker | ||
self, plan_objects_get, dbsession, mock_configuration, mocker | ||
): | ||
plan = PlanFactory.create() | ||
plan_objects_get.return_value = plan | ||
mocker.patch("services.notification.get_config", return_value=False) | ||
repository = RepositoryFactory.create( | ||
owner__integration_id=123, | ||
|
@@ -343,9 +386,17 @@ def test_get_notifiers_instances_slack_app_false( | |
"gh_installation_name", | ||
[GITHUB_APP_INSTALLATION_DEFAULT_NAME, "notifications-app"], | ||
) | ||
@patch("services.notification.Plan.objects.get") | ||
def test_get_notifiers_instances_checks_percentage_whitelist( | ||
self, dbsession, mock_configuration, mocker, gh_installation_name | ||
self, | ||
plan_objects_get, | ||
dbsession, | ||
mock_configuration, | ||
mocker, | ||
gh_installation_name, | ||
): | ||
plan = PlanFactory.create() | ||
plan_objects_get.return_value = plan | ||
repository = RepositoryFactory.create( | ||
owner__integration_id=123, | ||
owner__service="github", | ||
|
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
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.
Good catch!