diff --git a/database/models/core.py b/database/models/core.py index 3fdfa2c89..9ca77ca0b 100644 --- a/database/models/core.py +++ b/database/models/core.py @@ -60,7 +60,9 @@ class Account(CodecovBaseModel, MixinBaseClassNoExternalID): name = Column(types.String(100), nullable=False, unique=True) is_active = Column(types.Boolean, nullable=False, default=True) plan = Column( - types.String(50), nullable=False, default=PlanName.BASIC_PLAN_NAME.value + types.String(50), + nullable=False, + default=PlanName.BASIC_PLAN_NAME.value, # TODO: UPDATE WITH NEW FREE PLAN NAME ) plan_seat_count = Column(types.SmallInteger, nullable=False, default=1) free_seat_count = Column(types.SmallInteger, nullable=False, default=0) diff --git a/database/tests/factories/core.py b/database/tests/factories/core.py index 6c9dafea1..1efefc28e 100644 --- a/database/tests/factories/core.py +++ b/database/tests/factories/core.py @@ -4,7 +4,8 @@ import factory from factory import Factory -from shared.plan.constants import PlanName +from shared.django_apps.codecov_auth.models import Plan, Tier +from shared.plan.constants import PlanName, TierName from database import enums, models from services.encryption import encryptor @@ -300,6 +301,35 @@ class Meta: value = "" +class TierFactory(Factory): + class Meta: + model = Tier + + tier_name = TierName.BASIC.value + bundle_analysis = False + test_analytics = False + flaky_test_detection = False + project_coverage = False + private_repo_support = False + + +class PlanFactory(Factory): + class Meta: + model = Plan + + tier = factory.SubFactory(TierFactory) + base_unit_price = 0 + benefits = factory.LazyFunction(lambda: ["Benefit 1", "Benefit 2", "Benefit 3"]) + billing_rate = None + is_active = True + marketing_name = factory.Faker("catch_phrase") + max_seats = 1 + monthly_uploads_limit = None + name = PlanName.BASIC_PLAN_NAME.value + paid_plan = False + stripe_id = None + + class UploadErrorFactory(Factory): class Meta: model = models.UploadError diff --git a/requirements.in b/requirements.in index cc9cad5e2..8904a70cc 100644 --- a/requirements.in +++ b/requirements.in @@ -1,5 +1,5 @@ https://github.com/codecov/test-results-parser/archive/190bbc8a911099749928e13d5fe57f6027ca1e74.tar.gz#egg=test-results-parser -https://github.com/codecov/shared/archive/ce6e1e9198b046af850606e8fe3633d9a25fea98.tar.gz#egg=shared +https://github.com/codecov/shared/archive/74c0888070699b69a4da73f54be502ad05fde7b6.tar.gz#egg=shared https://github.com/codecov/timestring/archive/d37ceacc5954dff3b5bd2f887936a98a668dda42.tar.gz#egg=timestring asgiref>=3.7.2 analytics-python==1.3.0b1 diff --git a/requirements.txt b/requirements.txt index ef16c85e0..687834108 100644 --- a/requirements.txt +++ b/requirements.txt @@ -377,7 +377,7 @@ sentry-sdk==2.13.0 # shared setuptools==75.7.0 # via nodeenv -shared @ https://github.com/codecov/shared/archive/ce6e1e9198b046af850606e8fe3633d9a25fea98.tar.gz#egg=shared +shared @ https://github.com/codecov/shared/archive/74c0888070699b69a4da73f54be502ad05fde7b6.tar.gz#egg=shared # via -r requirements.in six==1.16.0 # via diff --git a/services/bundle_analysis/notify/contexts/tests/test_comment_context.py b/services/bundle_analysis/notify/contexts/tests/test_comment_context.py index eb77b2415..67247e09d 100644 --- a/services/bundle_analysis/notify/contexts/tests/test_comment_context.py +++ b/services/bundle_analysis/notify/contexts/tests/test_comment_context.py @@ -22,6 +22,7 @@ ) from services.repository import EnrichedPull from services.seats import SeatActivationInfo, ShouldActivateSeat +from tests.helpers import mock_all_plans_and_tiers class TestBundleAnalysisPRCommentNotificationContext: @@ -272,7 +273,9 @@ def test_evaluate_should_use_upgrade_message( builder.evaluate_should_use_upgrade_message() assert builder._notification_context.should_use_upgrade_comment == expected + @pytest.mark.django_db def test_build_context(self, dbsession, mocker, mock_storage): + mock_all_plans_and_tiers() head_commit, base_commit = get_commit_pair(dbsession) repository = head_commit.repository head_commit_report, base_commit_report = get_report_pair( @@ -305,7 +308,9 @@ def test_build_context(self, dbsession, mocker, mock_storage): == head_commit_report.external_id ) + @pytest.mark.django_db def test_initialize_from_context(self, dbsession, mocker): + mock_all_plans_and_tiers() head_commit, base_commit = get_commit_pair(dbsession) user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG) builder = BundleAnalysisPRCommentContextBuilder().initialize( diff --git a/services/bundle_analysis/notify/contexts/tests/test_commit_status_context.py b/services/bundle_analysis/notify/contexts/tests/test_commit_status_context.py index afb5be30c..dc9dd06ee 100644 --- a/services/bundle_analysis/notify/contexts/tests/test_commit_status_context.py +++ b/services/bundle_analysis/notify/contexts/tests/test_commit_status_context.py @@ -25,6 +25,7 @@ from services.bundle_analysis.notify.types import NotificationUserConfig from services.repository import EnrichedPull from services.seats import SeatActivationInfo, ShouldActivateSeat +from tests.helpers import mock_all_plans_and_tiers class TestBundleAnalysisPRCommentNotificationContext: @@ -217,7 +218,9 @@ def test_load_commit_status_level( context = builder.get_result() assert context.commit_status_level == expected + @pytest.mark.django_db def test_build_context(self, dbsession, mocker, mock_storage): + mock_all_plans_and_tiers() head_commit, base_commit = get_commit_pair(dbsession) repository = head_commit.repository head_commit_report, base_commit_report = get_report_pair( @@ -259,7 +262,9 @@ def test_build_context(self, dbsession, mocker, mock_storage): assert context.cache_ttl == 600 assert context.commit_status_url is not None + @pytest.mark.django_db def test_initialize_from_context(self, dbsession, mocker): + mock_all_plans_and_tiers() head_commit, base_commit = get_commit_pair(dbsession) user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG) builder = CommitStatusNotificationContextBuilder().initialize( diff --git a/services/bundle_analysis/notify/messages/tests/test_comment.py b/services/bundle_analysis/notify/messages/tests/test_comment.py index bc60bc08b..8a54a54da 100644 --- a/services/bundle_analysis/notify/messages/tests/test_comment.py +++ b/services/bundle_analysis/notify/messages/tests/test_comment.py @@ -26,10 +26,13 @@ ) from services.bundle_analysis.notify.types import NotificationUserConfig from services.notification.notifiers.base import NotificationResult +from tests.helpers import mock_all_plans_and_tiers class TestCommentMesage: + @pytest.mark.django_db def test_build_message_from_samples(self, dbsession, mocker, mock_storage): + mock_all_plans_and_tiers() head_commit, base_commit = get_commit_pair(dbsession) repository = head_commit.repository head_commit_report, base_commit_report = get_report_pair( diff --git a/services/bundle_analysis/notify/messages/tests/test_commit_status.py b/services/bundle_analysis/notify/messages/tests/test_commit_status.py index 3df389fbc..e1799b5a7 100644 --- a/services/bundle_analysis/notify/messages/tests/test_commit_status.py +++ b/services/bundle_analysis/notify/messages/tests/test_commit_status.py @@ -24,6 +24,7 @@ ) from services.notification.notifiers.base import NotificationResult from services.seats import SeatActivationInfo, ShouldActivateSeat +from tests.helpers import mock_all_plans_and_tiers class FakeRedis(object): @@ -55,6 +56,10 @@ def mock_cache(mocker): class TestCommitStatusMessage: + @pytest.fixture(autouse=True) + def setup(self): + mock_all_plans_and_tiers() + @pytest.mark.parametrize( "user_config, expected", [ @@ -81,6 +86,7 @@ class TestCommitStatusMessage: ), ], ) + @pytest.mark.django_db def test_build_message_from_samples_negative_changes( self, user_config, expected, dbsession, mocker, mock_storage ): @@ -133,6 +139,7 @@ def test_build_message_from_samples_negative_changes( ), ], ) + @pytest.mark.django_db def test_build_message_from_samples( self, user_config, expected, dbsession, mocker, mock_storage ): @@ -159,6 +166,7 @@ def test_build_message_from_samples( message = CommitStatusMessageStrategy().build_message(context) assert message == expected + @pytest.mark.django_db def _setup_send_message_tests( self, dbsession, mocker, torngit_ghapp_data, mock_storage ): @@ -207,6 +215,7 @@ def _setup_send_message_tests( "Passed with Warnings - Bundle change: 95.64% (Threshold: 5.0%)", ) + @pytest.mark.django_db @pytest.mark.parametrize( "torngit_ghapp_data", [ @@ -246,6 +255,7 @@ def test_send_message_success( # Side effect of sending message is updating the cache assert mock_cache.get_backend().get(strategy._cache_key(context)) == message + @pytest.mark.django_db def test_send_message_fail(self, dbsession, mocker, mock_storage): fake_repo_provider, context, message = self._setup_send_message_tests( dbsession, mocker, None, mock_storage @@ -259,6 +269,7 @@ def test_send_message_fail(self, dbsession, mocker, mock_storage): explanation="TorngitClientError", ) + @pytest.mark.django_db def test_skip_payload_unchanged(self, dbsession, mocker, mock_storage, mock_cache): fake_repo_provider, context, message = self._setup_send_message_tests( dbsession, mocker, None, mock_storage diff --git a/services/bundle_analysis/notify/tests/test_notify_service.py b/services/bundle_analysis/notify/tests/test_notify_service.py index 0a9299768..6a1155e11 100644 --- a/services/bundle_analysis/notify/tests/test_notify_service.py +++ b/services/bundle_analysis/notify/tests/test_notify_service.py @@ -29,6 +29,7 @@ ) from services.bundle_analysis.notify.types import NotificationType from services.notification.notifiers.base import NotificationResult +from tests.helpers import mock_all_plans_and_tiers def override_comment_builder_and_message_strategy(mocker): @@ -114,7 +115,9 @@ def test_build_base_context(self, mocker, dbsession, mock_storage): assert base_context.commit_report == head_commit_report assert base_context.bundle_analysis_report.session_count() == 19 + @pytest.mark.django_db def test_create_context_success(self, dbsession, mock_storage, mocker): + mock_all_plans_and_tiers() current_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG) head_commit, base_commit = get_commit_pair(dbsession) head_commit_report, base_commit_report = get_report_pair( diff --git a/services/bundle_analysis/tests/test_bundle_analysis.py b/services/bundle_analysis/tests/test_bundle_analysis.py index 29d45bd84..d98349c1f 100644 --- a/services/bundle_analysis/tests/test_bundle_analysis.py +++ b/services/bundle_analysis/tests/test_bundle_analysis.py @@ -30,6 +30,7 @@ ) from services.repository import EnrichedPull from services.urls import get_bundle_analysis_pull_url +from tests.helpers import mock_all_plans_and_tiers class MockBundleReport: @@ -690,6 +691,7 @@ async def test_bundle_analysis_save_measurements_error(dbsession, mocker, mock_s ), ], ) +@pytest.mark.django_db def test_bundle_analysis_notify_bundle_summary( bundle_changes: list[BundleChange], percent_change: float, @@ -700,6 +702,7 @@ def test_bundle_analysis_notify_bundle_summary( mock_storage, mock_repo_provider, ): + mock_all_plans_and_tiers() hook_mock_repo_provider(mocker, mock_repo_provider) base_commit = CommitFactory() dbsession.add(base_commit) @@ -1483,6 +1486,7 @@ def contributing_modules(self, pr_changed_files): ), ], ) +@pytest.mark.django_db def test_bundle_analysis_notify_individual_bundle_data( bundle_changes: list[BundleChange], route_changes: Dict[str, List[RouteChange]], @@ -1493,6 +1497,7 @@ def test_bundle_analysis_notify_individual_bundle_data( mock_storage, mock_repo_provider, ): + mock_all_plans_and_tiers() percent_change = 5.56 user_config = { **PATCH_CENTRIC_DEFAULT_CONFIG, diff --git a/services/notification/__init__.py b/services/notification/__init__.py index 0afcebabb..10134d72e 100644 --- a/services/notification/__init__.py +++ b/services/notification/__init__.py @@ -10,8 +10,9 @@ from celery.exceptions import CeleryError, SoftTimeLimitExceeded from shared.config import get_config +from shared.django_apps.codecov_auth.models import Plan from shared.helpers.yaml import default_if_true -from shared.plan.constants import TEAM_PLAN_REPRESENTATIONS +from shared.plan.constants import TierName from shared.torngit.base import TorngitBaseAdapter from shared.yaml import UserYaml @@ -68,9 +69,13 @@ def __init__( def _should_use_status_notifier(self, status_type: StatusType) -> bool: owner: Owner = self.repository.owner - if owner.plan in TEAM_PLAN_REPRESENTATIONS: - if status_type != StatusType.PATCH.value: - return False + plan = Plan.objects.select_related("tier").get(name=owner.plan) + + if ( + plan.tier.tier_name == TierName.TEAM.value + and status_type != StatusType.PATCH.value + ): + return False return True @@ -83,9 +88,13 @@ def _should_use_checks_notifier(self, status_type: StatusType) -> bool: if owner.service not in ["github", "github_enterprise"]: return False - if owner.plan in TEAM_PLAN_REPRESENTATIONS: - if status_type != StatusType.PATCH.value: - return False + plan = Plan.objects.select_related("tier").get(name=owner.plan) + + if ( + plan.tier.tier_name == TierName.TEAM.value + and status_type != StatusType.PATCH.value + ): + return False app_installation_filter = filter( lambda obj: ( diff --git a/services/notification/notifiers/tests/integration/test_comment.py b/services/notification/notifiers/tests/integration/test_comment.py index 01126ae03..f6c7b90fe 100644 --- a/services/notification/notifiers/tests/integration/test_comment.py +++ b/services/notification/notifiers/tests/integration/test_comment.py @@ -8,6 +8,7 @@ from services.comparison.types import Comparison, EnrichedPull, FullCommit from services.decoration import Decoration from services.notification.notifiers.comment import CommentNotifier +from tests.helpers import mock_all_plans_and_tiers @pytest.fixture @@ -335,6 +336,11 @@ def sample_comparison_for_limited_upload( @pytest.mark.usefixtures("is_not_first_pull") class TestCommentNotifierIntegration(object): + @pytest.fixture(autouse=True) + def setup(self): + mock_all_plans_and_tiers() + + @pytest.mark.django_db def test_notify(self, sample_comparison, codecov_vcr, mock_configuration): sample_comparison.context = ComparisonContext( all_tests_passed=True, test_results_error=None @@ -407,6 +413,7 @@ def test_notify(self, sample_comparison, codecov_vcr, mock_configuration): assert result.data_sent == {"commentid": None, "message": message, "pullid": 9} assert result.data_received == {"id": 1699669247} + @pytest.mark.django_db def test_notify_test_results_error( self, sample_comparison, codecov_vcr, mock_configuration ): @@ -482,6 +489,7 @@ def test_notify_test_results_error( assert result.data_sent == {"commentid": None, "message": message, "pullid": 9} assert result.data_received == {"id": 1699669247} + @pytest.mark.django_db def test_notify_upgrade( self, dbsession, sample_comparison_for_upgrade, codecov_vcr, mock_configuration ): @@ -516,6 +524,7 @@ def test_notify_upgrade( } assert result.data_received == {"id": 1361234119} + @pytest.mark.django_db def test_notify_upload_limited( self, dbsession, @@ -559,6 +568,7 @@ def test_notify_upload_limited( } assert result.data_received == {"id": 1111984446} + @pytest.mark.django_db def test_notify_gitlab( self, sample_comparison_gitlab, codecov_vcr, mock_configuration ): @@ -625,6 +635,7 @@ def test_notify_gitlab( assert result.data_sent == {"commentid": None, "message": message, "pullid": 5} assert result.data_received == {"id": 1457135397} + @pytest.mark.django_db def test_notify_new_layout( self, sample_comparison, codecov_vcr, mock_configuration ): @@ -695,6 +706,7 @@ def test_notify_new_layout( assert result.data_sent == {"commentid": None, "message": message, "pullid": 9} assert result.data_received == {"id": 1699669290} + @pytest.mark.django_db def test_notify_with_components( self, sample_comparison, codecov_vcr, mock_configuration ): diff --git a/services/notification/notifiers/tests/unit/test_checks.py b/services/notification/notifiers/tests/unit/test_checks.py index b39bae918..f02fa9910 100644 --- a/services/notification/notifiers/tests/unit/test_checks.py +++ b/services/notification/notifiers/tests/unit/test_checks.py @@ -25,6 +25,7 @@ CUSTOM_TARGET_TEXT_VALUE, ) from services.notification.notifiers.status import PatchStatusNotifier +from tests.helpers import mock_all_plans_and_tiers @pytest.fixture @@ -742,9 +743,11 @@ def test_build_upgrade_payload( result = notifier.build_payload(sample_comparison) assert expected_result == result + @pytest.mark.django_db def test_build_default_payload( self, sample_comparison, mock_repo_provider, mock_configuration ): + mock_all_plans_and_tiers() mock_configuration.params["setup"]["codecov_dashboard_url"] = "test.example.br" notifier = PatchChecksNotifier( repository=sample_comparison.head.commit.repository, @@ -1555,9 +1558,11 @@ def test_build_passing_empty_upload_payload( result = notifier.build_payload(sample_comparison) assert expected_result == result + @pytest.mark.django_db def test_build_default_payload( self, sample_comparison, mock_repo_provider, mock_configuration ): + mock_all_plans_and_tiers() mock_configuration.params["setup"]["codecov_dashboard_url"] = "test.example.br" notifier = ProjectChecksNotifier( repository=sample_comparison.head.commit.repository, @@ -1604,9 +1609,11 @@ def test_build_default_payload( ].split("\n") assert expected_result == result + @pytest.mark.django_db def test_build_default_payload_with_flags( self, sample_comparison, mock_repo_provider, mock_configuration ): + mock_all_plans_and_tiers() mock_configuration.params["setup"]["codecov_dashboard_url"] = "test.example.br" notifier = ProjectChecksNotifier( repository=sample_comparison.head.commit.repository, @@ -1653,9 +1660,11 @@ def test_build_default_payload_with_flags( ].split("\n") assert expected_result == result + @pytest.mark.django_db def test_build_default_payload_with_flags_and_footer( self, sample_comparison, mock_repo_provider, mock_configuration ): + mock_all_plans_and_tiers() test_name = "test_build_default_payload_with_flags_and_footer" mock_configuration.params["setup"]["codecov_dashboard_url"] = "test.example.br" notifier = ProjectChecksNotifier( diff --git a/services/notification/notifiers/tests/unit/test_comment.py b/services/notification/notifiers/tests/unit/test_comment.py index bac1fabf3..82cba814e 100644 --- a/services/notification/notifiers/tests/unit/test_comment.py +++ b/services/notification/notifiers/tests/unit/test_comment.py @@ -47,6 +47,7 @@ from services.notification.notifiers.tests.conftest import generate_sample_comparison from services.repository import EnrichedPull from services.yaml.reader import get_components_from_yaml +from tests.helpers import mock_all_plans_and_tiers @pytest.fixture @@ -228,6 +229,7 @@ def mock_repo_provider(mock_repo_provider): class TestCommentNotifierHelpers(object): + @pytest.mark.django_db def test_sort_by_importance(self): modified_change = Change( path="modified.py", @@ -308,6 +310,7 @@ def test_sort_by_importance(self): ] assert expected_result == res + @pytest.mark.django_db def test_format_number_to_str(self): assert "<0.1" == format_number_to_str( {"coverage": {"precision": 1}}, Decimal("0.001") @@ -319,6 +322,7 @@ def test_format_number_to_str(self): {"coverage": {"precision": 1, "round": "up"}}, Decimal("10.001") ) + @pytest.mark.django_db def test_diff_to_string_case_1(self): case_1 = ( "master", @@ -339,6 +343,7 @@ def test_diff_to_string_case_1(self): diff = diff_to_string({}, base_title, base_totals, head_title, head_totals) assert diff == expected_result + @pytest.mark.django_db def test_diff_to_string_case_2(self): case_2 = ( "master", @@ -361,6 +366,7 @@ def test_diff_to_string_case_2(self): diff = diff_to_string({}, base_title, base_totals, head_title, head_totals) assert diff == expected_result + @pytest.mark.django_db def test_diff_to_string_case_3(self): case_3 = ( "master", @@ -386,6 +392,7 @@ def test_diff_to_string_case_3(self): diff = diff_to_string({}, base_title, base_totals, head_title, head_totals) assert diff == expected_result + @pytest.mark.django_db def test_diff_to_string_case_4(self): case_4 = ( "master", @@ -408,6 +415,7 @@ def test_diff_to_string_case_4(self): diff = diff_to_string({}, base_title, base_totals, head_title, head_totals) assert diff == expected_result + @pytest.mark.django_db def test_diff_to_string_case_different_types(self): case_1 = ( "master", @@ -432,6 +440,11 @@ def test_diff_to_string_case_different_types(self): @pytest.mark.usefixtures("is_not_first_pull") class TestCommentNotifier(object): + @pytest.fixture(autouse=True) + def setup(self): + mock_all_plans_and_tiers() + + @pytest.mark.django_db def test_is_enabled_settings_individual_settings_false(self, dbsession): repository = RepositoryFactory.create() dbsession.add(repository) @@ -446,6 +459,7 @@ def test_is_enabled_settings_individual_settings_false(self, dbsession): ) assert not notifier.is_enabled() + @pytest.mark.django_db def test_is_enabled_settings_individual_settings_none(self, dbsession): repository = RepositoryFactory.create() dbsession.add(repository) @@ -460,6 +474,7 @@ def test_is_enabled_settings_individual_settings_none(self, dbsession): ) assert not notifier.is_enabled() + @pytest.mark.django_db def test_is_enabled_settings_individual_settings_true(self, dbsession): repository = RepositoryFactory.create() dbsession.add(repository) @@ -474,6 +489,7 @@ def test_is_enabled_settings_individual_settings_true(self, dbsession): ) assert not notifier.is_enabled() + @pytest.mark.django_db def test_is_enabled_settings_individual_settings_dict(self, dbsession): repository = RepositoryFactory.create() dbsession.add(repository) @@ -488,6 +504,7 @@ def test_is_enabled_settings_individual_settings_dict(self, dbsession): ) assert notifier.is_enabled() + @pytest.mark.django_db def test_create_message_files_section( self, dbsession, @@ -639,6 +656,7 @@ def test_create_message_files_section( for expected, res in zip(expected_result, res): assert expected == res + @pytest.mark.django_db def test_create_message_files_section_with_critical_files( self, dbsession, @@ -803,6 +821,7 @@ def test_create_message_files_section_with_critical_files( mocked_search_files_for_critical_changes.call_count == 3 ) # called 2 times by FilesSectionWriter and 1 time by NewFilesSectionWriter + @pytest.mark.django_db def test_create_message_with_github_app_comment( self, dbsession, @@ -834,6 +853,7 @@ def test_create_message_with_github_app_comment( "check_value", return_value=True, ) + @pytest.mark.django_db def test_build_message( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -909,6 +929,7 @@ def test_build_message( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_flags_empty_coverage( self, dbsession, @@ -954,6 +975,7 @@ def test_build_message_flags_empty_coverage( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_more_sections( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -1038,6 +1060,7 @@ def test_build_message_more_sections( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_upgrade_message( self, request, @@ -1075,6 +1098,7 @@ def test_build_upgrade_message( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_limited_upload_message( self, request, @@ -1115,6 +1139,7 @@ def test_build_limited_upload_message( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_passing_empty_upload( self, request, @@ -1148,6 +1173,7 @@ def test_build_passing_empty_upload( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_failing_empty_upload( self, request, @@ -1182,6 +1208,7 @@ def test_build_failing_empty_upload( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_processing_upload( self, request, @@ -1214,6 +1241,7 @@ def test_processing_upload( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_upgrade_message_enterprise( self, request, @@ -1257,6 +1285,7 @@ def test_build_upgrade_message_enterprise( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_hide_complexity( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -1331,6 +1360,7 @@ def test_build_message_hide_complexity( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_no_base_report( self, dbsession, @@ -1406,6 +1436,7 @@ def test_build_message_no_base_report( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_no_base_commit( self, dbsession, @@ -1481,6 +1512,7 @@ def test_build_message_no_base_commit( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_no_change( self, dbsession, @@ -1560,6 +1592,7 @@ def test_build_message_no_change( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_negative_change( self, dbsession, @@ -1634,6 +1667,7 @@ def test_build_message_negative_change( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_negative_change_tricky_rounding( self, dbsession, @@ -1701,6 +1735,7 @@ def test_build_message_negative_change_tricky_rounding( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_negative_change_tricky_rounding_newheader( self, dbsession, @@ -1755,6 +1790,7 @@ def test_build_message_negative_change_tricky_rounding_newheader( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_show_carriedforward_flags_no_cf_coverage( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -1830,6 +1866,7 @@ def test_build_message_show_carriedforward_flags_no_cf_coverage( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_with_without_flags( self, dbsession, @@ -1960,6 +1997,7 @@ def test_build_message_with_without_flags( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_show_carriedforward_flags_has_cf_coverage( self, dbsession, @@ -2033,6 +2071,7 @@ def test_build_message_show_carriedforward_flags_has_cf_coverage( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_hide_carriedforward_flags_has_cf_coverage( self, dbsession, @@ -2104,6 +2143,7 @@ def test_build_message_hide_carriedforward_flags_has_cf_coverage( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_default_layout( self, dbsession, @@ -2135,6 +2175,7 @@ def test_build_message_default_layout( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_send_actual_notification_spammy( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2161,6 +2202,7 @@ def test_send_actual_notification_spammy( assert not mock_repo_provider.edit_comment.called assert not mock_repo_provider.delete_comment.called + @pytest.mark.django_db def test_build_message_no_flags( self, dbsession, @@ -2242,6 +2284,7 @@ def test_build_message_no_flags( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_send_actual_notification_new_no_permissions( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2271,6 +2314,7 @@ def test_send_actual_notification_new_no_permissions( assert not mock_repo_provider.post_comment.called assert not mock_repo_provider.edit_comment.called + @pytest.mark.django_db def test_send_actual_notification_new( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2298,6 +2342,7 @@ def test_send_actual_notification_new( assert not mock_repo_provider.edit_comment.called mock_repo_provider.delete_comment.assert_called_with(98, "12345") + @pytest.mark.django_db def test_send_actual_notification_new_no_permissions_post( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2329,6 +2374,7 @@ def test_send_actual_notification_new_no_permissions_post( assert not mock_repo_provider.delete_comment.called assert not mock_repo_provider.edit_comment.called + @pytest.mark.django_db def test_send_actual_notification_new_deleted_comment( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2358,6 +2404,7 @@ def test_send_actual_notification_new_deleted_comment( assert not mock_repo_provider.edit_comment.called mock_repo_provider.delete_comment.assert_called_with(98, "12345") + @pytest.mark.django_db def test_send_actual_notification_once_deleted_comment( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2387,6 +2434,7 @@ def test_send_actual_notification_once_deleted_comment( mock_repo_provider.edit_comment.assert_called_with(98, "12345", "message") assert not mock_repo_provider.delete_comment.called + @pytest.mark.django_db def test_send_actual_notification_once_non_existing_comment( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2416,6 +2464,7 @@ def test_send_actual_notification_once_non_existing_comment( assert not mock_repo_provider.delete_comment.called assert not mock_repo_provider.edit_comment.called + @pytest.mark.django_db def test_send_actual_notification_once( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2443,6 +2492,7 @@ def test_send_actual_notification_once( mock_repo_provider.edit_comment.assert_called_with(98, "12345", "message") assert not mock_repo_provider.delete_comment.called + @pytest.mark.django_db def test_send_actual_notification_once_no_permissions( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2472,6 +2522,7 @@ def test_send_actual_notification_once_no_permissions( mock_repo_provider.edit_comment.assert_called_with(98, "12345", "message") assert not mock_repo_provider.delete_comment.called + @pytest.mark.django_db def test_send_actual_notification_default( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2499,6 +2550,7 @@ def test_send_actual_notification_default( mock_repo_provider.edit_comment.assert_called_with(98, "12345", "message") assert not mock_repo_provider.delete_comment.called + @pytest.mark.django_db def test_send_actual_notification_default_no_permissions_edit( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2528,6 +2580,7 @@ def test_send_actual_notification_default_no_permissions_edit( mock_repo_provider.edit_comment.assert_called_with(98, "12345", "message") assert not mock_repo_provider.delete_comment.called + @pytest.mark.django_db def test_send_actual_notification_default_no_permissions_twice( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2559,6 +2612,7 @@ def test_send_actual_notification_default_no_permissions_twice( mock_repo_provider.edit_comment.assert_called_with(98, "12345", "message") assert not mock_repo_provider.delete_comment.called + @pytest.mark.django_db def test_send_actual_notification_default_comment_not_found( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -2588,6 +2642,7 @@ def test_send_actual_notification_default_comment_not_found( mock_repo_provider.post_comment.assert_called_with(98, "message") assert not mock_repo_provider.delete_comment.called + @pytest.mark.django_db def test_notify_no_pull_request(self, dbsession, sample_comparison_without_pull): notifier = CommentNotifier( repository=sample_comparison_without_pull.head.commit.repository, @@ -2607,6 +2662,7 @@ def test_notify_no_pull_request(self, dbsession, sample_comparison_without_pull) assert result.data_sent is None assert result.data_received is None + @pytest.mark.django_db def test_notify_pull_head_doesnt_match(self, dbsession, sample_comparison): sample_comparison.pull.head = "aaaaaaaaaa" dbsession.flush() @@ -2628,6 +2684,7 @@ def test_notify_pull_head_doesnt_match(self, dbsession, sample_comparison): assert result.data_sent is None assert result.data_received is None + @pytest.mark.django_db def test_notify_pull_request_not_in_provider( self, dbsession, sample_comparison_database_pull_without_provider ): @@ -2649,6 +2706,7 @@ def test_notify_pull_request_not_in_provider( assert result.data_sent is None assert result.data_received is None + @pytest.mark.django_db def test_notify_server_unreachable(self, mocker, dbsession, sample_comparison): mocked_send_actual_notification = mocker.patch.object( CommentNotifier, @@ -2680,6 +2738,7 @@ def test_notify_server_unreachable(self, mocker, dbsession, sample_comparison): } assert result.data_received is None + @pytest.mark.django_db def test_store_results(self, dbsession, sample_comparison): notifier = CommentNotifier( repository=sample_comparison.head.commit.repository, @@ -2706,6 +2765,7 @@ def test_store_results(self, dbsession, sample_comparison): dbsession.refresh(sample_comparison.pull) assert sample_comparison.pull.commentid == "578263422" + @pytest.mark.django_db def test_store_results_deleted_comment(self, dbsession, sample_comparison): sample_comparison.pull.commentid = 12 dbsession.flush() @@ -2734,6 +2794,7 @@ def test_store_results_deleted_comment(self, dbsession, sample_comparison): dbsession.refresh(sample_comparison.pull) assert sample_comparison.pull.commentid is None + @pytest.mark.django_db def test_store_results_no_succesfull_result(self, dbsession, sample_comparison): notifier = CommentNotifier( repository=sample_comparison.head.commit.repository, @@ -2760,6 +2821,7 @@ def test_store_results_no_succesfull_result(self, dbsession, sample_comparison): dbsession.refresh(sample_comparison.pull) assert sample_comparison.pull.commentid is None + @pytest.mark.django_db def test_notify_unable_to_fetch_info(self, dbsession, mocker, sample_comparison): mocked_build_message = mocker.patch.object( CommentNotifier, @@ -2784,6 +2846,7 @@ def test_notify_unable_to_fetch_info(self, dbsession, mocker, sample_comparison) assert result.data_sent is None assert result.data_received is None + @pytest.mark.django_db def test_notify_not_enough_builds(self, dbsession, sample_comparison): notifier = CommentNotifier( repository=sample_comparison.head.commit.repository, @@ -2804,6 +2867,7 @@ def test_notify_not_enough_builds(self, dbsession, sample_comparison): assert result.data_sent is None assert result.data_received is None + @pytest.mark.django_db @pytest.mark.asyncio @pytest.mark.parametrize("pull_state", ["open", "closed"]) async def test_notify_with_enough_builds( @@ -2850,6 +2914,7 @@ async def test_notify_with_enough_builds( } assert result.data_received is None + @pytest.mark.django_db def test_notify_exact_same_report_diff_unrelated_report( self, sample_comparison_no_change, mock_repo_provider ): @@ -2911,6 +2976,7 @@ def test_notify_exact_same_report_diff_unrelated_report( assert res.data_sent is None assert res.data_received is None + @pytest.mark.django_db def test_notify_exact_same_report_diff_unrelated_report_update_comment( self, sample_comparison_no_change, mock_repo_provider ): @@ -2972,6 +3038,7 @@ def test_notify_exact_same_report_diff_unrelated_report_update_comment( assert res.notification_successful is True mock_repo_provider.edit_comment.assert_called() + @pytest.mark.django_db def test_message_hide_details_github( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -3006,6 +3073,7 @@ def test_message_hide_details_github( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_message_announcements_only( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -3043,6 +3111,7 @@ def test_message_announcements_only( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_message_hide_details_bitbucket( self, dbsession, mock_configuration, mock_repo_provider, sample_comparison ): @@ -3992,6 +4061,11 @@ def test_footer_section_writer_with_project_cov_hidden(self, mocker): @pytest.mark.usefixtures("is_not_first_pull") class TestCommentNotifierInNewLayout(object): + @pytest.fixture(autouse=True) + def mock_all_plans_and_tiers(self): + mock_all_plans_and_tiers() + + @pytest.mark.django_db def test_create_message_files_section_with_critical_files_new_layout( self, dbsession, @@ -4156,6 +4230,7 @@ def test_create_message_files_section_with_critical_files_new_layout( mocked_search_files_for_critical_changes.call_count == 3 ) # called 2 times by FilesSectionWriter and 1 time by NewFilesSectionWriter + @pytest.mark.django_db def test_build_message_no_base_commit_new_layout( self, dbsession, @@ -4225,6 +4300,7 @@ def test_build_message_no_base_commit_new_layout( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_no_base_report_new_layout( self, dbsession, @@ -4298,6 +4374,7 @@ def test_build_message_no_base_report_new_layout( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_no_project_coverage( self, dbsession, @@ -4339,6 +4416,7 @@ def test_build_message_no_project_coverage( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_no_project_coverage_files( self, dbsession, @@ -4386,6 +4464,7 @@ def test_build_message_no_project_coverage_files( for exp, res in zip(expected_result, result): assert exp == res + @pytest.mark.django_db def test_build_message_no_project_coverage_condensed_yaml_configs( self, dbsession, @@ -4427,6 +4506,7 @@ def test_build_message_no_project_coverage_condensed_yaml_configs( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_head_and_pull_head_differ_new_layout( self, dbsession, @@ -4497,6 +4577,7 @@ def test_build_message_head_and_pull_head_differ_new_layout( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_head_and_pull_head_differ_with_components( self, dbsession, @@ -4579,6 +4660,7 @@ def test_build_message_head_and_pull_head_differ_with_components( assert exp == res assert result == expected_result + @pytest.mark.django_db def test_build_message_team_plan_customer_missing_lines( self, dbsession, @@ -4629,6 +4711,7 @@ def test_build_message_team_plan_customer_missing_lines( @patch.object( SHOW_IMPACT_ANALYSIS_DEPRECATION_MSG, "check_value", return_value=True ) + @pytest.mark.django_db def test_build_message_team_plan_customer_all_lines_covered( self, dbsession, @@ -4671,6 +4754,7 @@ def test_build_message_team_plan_customer_all_lines_covered( ] assert result == expected_result + @pytest.mark.django_db def test_build_message_team_plan_customer_all_lines_covered_test_results_error( self, dbsession, @@ -4713,6 +4797,7 @@ def test_build_message_team_plan_customer_all_lines_covered_test_results_error( ] assert result == expected_result + @pytest.mark.django_db def test_build_message_team_plan_customer_all_lines_covered_no_third_line( self, dbsession, @@ -4753,6 +4838,7 @@ def test_build_message_team_plan_customer_all_lines_covered_no_third_line( ] assert result == expected_result + @pytest.mark.django_db def test_build_message_no_patch_or_proj_change( self, dbsession, diff --git a/services/notification/tests/unit/test_notification_service.py b/services/notification/tests/unit/test_notification_service.py index d54efce2e..053648b21 100644 --- a/services/notification/tests/unit/test_notification_service.py +++ b/services/notification/tests/unit/test_notification_service.py @@ -35,6 +35,7 @@ CUSTOM_TARGET_TEXT_PROJECT_KEY, CUSTOM_TARGET_TEXT_VALUE, ) +from tests.helpers import mock_all_plans_and_tiers @pytest.fixture @@ -78,6 +79,11 @@ def sample_comparison(dbsession, request): class TestNotificationService(object): + @pytest.fixture(autouse=True) + def mock_all_plans_and_tiers_fixture(self): + mock_all_plans_and_tiers() + + @pytest.mark.django_db def test_should_use_checks_notifier_yaml_field_false(self, dbsession): repository = RepositoryFactory.create() current_yaml = {"github_checks": False} @@ -124,6 +130,7 @@ def test_should_use_checks_notifier_yaml_field_false(self, dbsession): ), ], ) + @pytest.mark.django_db def test_should_use_checks_notifier_deprecated_flow( self, repo_data, outcome, dbsession ): @@ -136,6 +143,7 @@ def test_should_use_checks_notifier_deprecated_flow( == outcome ) + @pytest.mark.django_db def test_should_use_checks_notifier_ghapp_all_repos_covered(self, dbsession): repository = RepositoryFactory.create(owner__service="github") ghapp_installation = GithubAppInstallation( @@ -154,7 +162,11 @@ def test_should_use_checks_notifier_ghapp_all_repos_covered(self, dbsession): == True ) - def test_use_checks_notifier_for_team_plan(self, dbsession): + @pytest.mark.django_db + def test_use_checks_notifier_for_team_plan( + self, + dbsession, + ): repository = RepositoryFactory.create( owner__service="github", owner__plan=PlanName.TEAM_MONTHLY.value ) @@ -182,6 +194,7 @@ def test_use_checks_notifier_for_team_plan(self, dbsession): == True ) + @pytest.mark.django_db def test_use_status_notifier_for_team_plan(self, dbsession): repository = RepositoryFactory.create( owner__service="github", owner__plan=PlanName.TEAM_MONTHLY.value @@ -210,6 +223,7 @@ def test_use_status_notifier_for_team_plan(self, dbsession): == True ) + @pytest.mark.django_db def test_use_status_notifier_for_non_team_plan(self, dbsession): repository = RepositoryFactory.create( owner__service="github", owner__plan=PlanName.CODECOV_PRO_MONTHLY.value @@ -242,6 +256,7 @@ def test_use_status_notifier_for_non_team_plan(self, dbsession): "gh_installation_name", [GITHUB_APP_INSTALLATION_DEFAULT_NAME, "notifications-app"], ) + @pytest.mark.django_db def test_should_use_checks_notifier_ghapp_some_repos_covered( self, dbsession, gh_installation_name ): @@ -275,6 +290,7 @@ def test_should_use_checks_notifier_ghapp_some_repos_covered( == False ) + @pytest.mark.django_db def test_get_notifiers_instances_only_third_party( self, dbsession, mock_configuration ): @@ -302,6 +318,7 @@ def test_get_notifiers_instances_only_third_party( assert instance.site_settings == ["slack.com"] assert instance.current_yaml == current_yaml + @pytest.mark.django_db def test_get_notifiers_instances_checks( self, dbsession, mock_configuration, mocker ): @@ -338,6 +355,7 @@ def test_get_notifiers_instances_checks( "codecov_slack_app", ] + @pytest.mark.django_db def test_get_notifiers_instances_slack_app_false( self, dbsession, mock_configuration, mocker ): @@ -371,8 +389,13 @@ def test_get_notifiers_instances_slack_app_false( "gh_installation_name", [GITHUB_APP_INSTALLATION_DEFAULT_NAME, "notifications-app"], ) + @pytest.mark.django_db def test_get_notifiers_instances_checks_percentage_whitelist( - self, dbsession, mock_configuration, mocker, gh_installation_name + self, + dbsession, + mock_configuration, + mocker, + gh_installation_name, ): repository = RepositoryFactory.create( owner__integration_id=123, @@ -422,6 +445,7 @@ def test_get_notifiers_instances_checks_percentage_whitelist( "gh_installation_name", [GITHUB_APP_INSTALLATION_DEFAULT_NAME, "notifications-app"], ) + @pytest.mark.django_db def test_get_notifiers_instances_comment( self, dbsession, mock_configuration, mocker, gh_installation_name ): @@ -445,6 +469,7 @@ def test_get_notifiers_instances_comment( assert len(instances) == 1 assert instances[0].repository_service == gh_installation_name + @pytest.mark.django_db def test_notify_general_exception(self, mocker, dbsession, sample_comparison): current_yaml = {} commit = sample_comparison.head.commit @@ -503,6 +528,7 @@ def test_notify_general_exception(self, mocker, dbsession, sample_comparison): res = notifications_service.notify(sample_comparison) assert expected_result == res + @pytest.mark.django_db def test_notify_data_sent_None(self, mocker, dbsession, sample_comparison): current_yaml = {} commit = sample_comparison.head.commit @@ -567,6 +593,7 @@ def test_notify_data_sent_None(self, mocker, dbsession, sample_comparison): res = notifications_service.notify(sample_comparison) assert expected_result == res + @pytest.mark.django_db def test_notify_individual_notifier_timeout(self, mocker, sample_comparison): current_yaml = {} commit = sample_comparison.head.commit @@ -589,6 +616,7 @@ def test_notify_individual_notifier_timeout(self, mocker, sample_comparison): "title": "fake_notifier", } + @pytest.mark.django_db def test_notify_individual_checks_project_notifier( self, mocker, sample_comparison, mock_repo_provider, mock_configuration ): @@ -642,6 +670,7 @@ def test_notify_individual_checks_project_notifier( ), } + @pytest.mark.django_db def test_notify_individual_checks_patch_and_project_notifier_included_helper_text( self, mocker, @@ -846,6 +875,7 @@ def test_notify_individual_checks_patch_and_project_notifier_included_helper_tex in r["result"].data_sent["message"] ) + @pytest.mark.django_db def test_notify_individual_notifier_timeout_notification_created( self, mocker, dbsession, sample_comparison ): @@ -880,6 +910,7 @@ def test_notify_individual_notifier_timeout_notification_created( assert pull_commit_notification.decoration_type == notifier.decoration_type assert pull_commit_notification.state == NotificationState.error + @pytest.mark.django_db def test_notify_individual_notifier_notification_created_then_updated( self, mocker, dbsession, sample_comparison ): @@ -929,6 +960,7 @@ def test_notify_individual_notifier_notification_created_then_updated( dbsession.commit() assert pull_commit_notification.state == NotificationState.success + @pytest.mark.django_db def test_notify_individual_notifier_cancellation(self, mocker, sample_comparison): current_yaml = {} commit = sample_comparison.head.commit @@ -947,6 +979,7 @@ def test_notify_individual_notifier_cancellation(self, mocker, sample_comparison notifier, sample_comparison ) + @pytest.mark.django_db def test_notify_timeout_exception(self, mocker, dbsession, sample_comparison): current_yaml = {} commit = sample_comparison.head.commit @@ -1023,6 +1056,7 @@ def test_notify_timeout_exception(self, mocker, dbsession, sample_comparison): Notification.status_patch, ) + @pytest.mark.django_db def test_not_licensed_enterprise(self, mocker, dbsession, sample_comparison): mocker.patch("services.notification.is_properly_licensed", return_value=False) mock_notify_individual_notifier = mocker.patch.object( @@ -1038,6 +1072,7 @@ def test_not_licensed_enterprise(self, mocker, dbsession, sample_comparison): assert expected_result == res assert not mock_notify_individual_notifier.called + @pytest.mark.django_db def test_get_statuses(self, mocker, dbsession, sample_comparison): current_yaml = { "coverage": {"status": {"project": True, "patch": True, "changes": True}}, @@ -1070,6 +1105,7 @@ def test_get_statuses(self, mocker, dbsession, sample_comparison): res = list(notifications_service.get_statuses(["unit", "banana", "strawberry"])) assert expected_result == res + @pytest.mark.django_db def test_get_component_statuses(self, mocker, dbsession, sample_comparison): current_yaml = { "component_management": { diff --git a/services/report/tests/unit/test_sessions.py b/services/report/tests/unit/test_sessions.py index 922f586ce..b7489ea74 100644 --- a/services/report/tests/unit/test_sessions.py +++ b/services/report/tests/unit/test_sessions.py @@ -66,7 +66,6 @@ def sample_first_report(self): second_file = EditableReportFile("second_file.py") first_report.append(first_file) first_report.append(second_file) - # print(self.convert_report_to_better_readable(first_report)["archive"]) assert self.convert_report_to_better_readable(first_report)["archive"] == { "first_file.py": [ ( @@ -761,7 +760,6 @@ def test_adjust_sessions_partial_cf_only_full_deletion_due_to_lost_labels( sample_first_report, second_report, ["enterprise"], current_yaml ) == SessionAdjustmentResult([0], []) res = self.convert_report_to_better_readable(sample_first_report) - # print(res["report"]["sessions"]) assert res["report"]["sessions"] == { "1": { "t": None, diff --git a/services/test_results.py b/services/test_results.py index 384deb1cd..e176dc1a4 100644 --- a/services/test_results.py +++ b/services/test_results.py @@ -3,7 +3,8 @@ from hashlib import sha256 from typing import Sequence -from shared.plan.constants import FREE_PLAN_REPRESENTATIONS, TEAM_PLAN_REPRESENTATIONS +from shared.django_apps.codecov_auth.models import Plan +from shared.plan.constants import TierName from shared.yaml import UserYaml from sqlalchemy import desc, distinct, func from sqlalchemy.orm import joinedload @@ -449,10 +450,12 @@ def get_test_summary_for_commit( def not_private_and_free_or_team(repo: Repository): + plan = Plan.objects.select_related("tier").get(name=repo.owner.plan) + return not ( repo.private - and repo.owner.plan - in {**FREE_PLAN_REPRESENTATIONS, **TEAM_PLAN_REPRESENTATIONS} + and plan + and plan.tier.tier_name in {TierName.BASIC.value, TierName.TEAM.value} ) @@ -464,6 +467,7 @@ def should_do_flaky_detection(repo: Repository, commit_yaml: UserYaml) -> bool: identifier=repo.repoid, default=True ) has_valid_plan_repo_or_owner = not_private_and_free_or_team(repo) + return has_flaky_configured and (feature_enabled or has_valid_plan_repo_or_owner) diff --git a/services/tests/test_billing.py b/services/tests/test_billing.py index f4fe367f5..7a20a2b0b 100644 --- a/services/tests/test_billing.py +++ b/services/tests/test_billing.py @@ -1,8 +1,10 @@ +import pytest from django.test import override_settings from shared.plan.constants import PlanName from shared.plan.service import PlanService from database.tests.factories import OwnerFactory +from tests.helpers import mock_all_plans_and_tiers class TestBillingServiceTestCase(object): @@ -10,6 +12,11 @@ class TestBillingServiceTestCase(object): BillingService is deprecated - use PlanService instead. """ + @pytest.fixture(autouse=True) + def setup(self): + mock_all_plans_and_tiers() + + @pytest.mark.django_db def test_pr_author_plan_check(self, request, dbsession, with_sql_functions): owner = OwnerFactory.create(service="github", plan="users-pr-inappm") dbsession.add(owner) @@ -17,6 +24,7 @@ def test_pr_author_plan_check(self, request, dbsession, with_sql_functions): plan = PlanService(owner) assert plan.is_pr_billing_plan + @pytest.mark.django_db @override_settings(IS_ENTERPRISE=True) def test_pr_author_enterprise_plan_check( self, request, dbsession, mock_configuration, with_sql_functions @@ -35,6 +43,7 @@ def test_pr_author_enterprise_plan_check( assert plan.is_pr_billing_plan + @pytest.mark.django_db def test_plan_not_pr_author(self, request, dbsession, with_sql_functions): owner = OwnerFactory.create( service="github", plan=PlanName.CODECOV_PRO_MONTHLY_LEGACY.value @@ -46,6 +55,7 @@ def test_plan_not_pr_author(self, request, dbsession, with_sql_functions): assert not plan.is_pr_billing_plan + @pytest.mark.django_db @override_settings(IS_ENTERPRISE=True) def test_pr_author_enterprise_plan_check_non_pr_plan( self, request, dbsession, mocker, mock_configuration, with_sql_functions diff --git a/services/tests/test_decoration.py b/services/tests/test_decoration.py index daef67d9e..1bd980896 100644 --- a/services/tests/test_decoration.py +++ b/services/tests/test_decoration.py @@ -35,6 +35,7 @@ determine_uploads_used, ) from services.repository import EnrichedPull +from tests.helpers import mock_all_plans_and_tiers @pytest.fixture @@ -211,6 +212,10 @@ def gitlab_enriched_pull_root(dbsession, gitlab_root_group): class TestDecorationServiceTestCase(object): + @pytest.fixture(autouse=True) + def setup(self): + mock_all_plans_and_tiers() + @pytest.mark.django_db def test_decoration_type_basic_plan_upload_limit( self, enriched_pull, dbsession, mocker @@ -452,6 +457,7 @@ def test_uploads_used_with_expired_trial(self, mocker): assert uploads_used == 2 + @pytest.mark.django_db def test_get_decoration_type_no_pull(self, mocker): decoration_details = determine_decoration_details(None) @@ -459,6 +465,7 @@ def test_get_decoration_type_no_pull(self, mocker): assert decoration_details.reason == "No pull" assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db def test_get_decoration_type_no_provider_pull(self, mocker, enriched_pull): enriched_pull.provider_pull = None @@ -471,6 +478,7 @@ def test_get_decoration_type_no_provider_pull(self, mocker, enriched_pull): ) assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db def test_get_decoration_type_public_repo(self, dbsession, mocker, enriched_pull): enriched_pull.database_pull.repository.private = False dbsession.flush() @@ -481,6 +489,7 @@ def test_get_decoration_type_public_repo(self, dbsession, mocker, enriched_pull) assert decoration_details.reason == "Public repo" assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db def test_get_decoration_type_not_pr_plan(self, dbsession, mocker, enriched_pull): enriched_pull.database_pull.repository.owner.plan = "users-inappm" dbsession.flush() @@ -491,12 +500,14 @@ def test_get_decoration_type_not_pr_plan(self, dbsession, mocker, enriched_pull) assert decoration_details.reason == "Org not on PR plan" assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db + # what is a users plan? def test_get_decoration_type_for_users_plan(self, dbsession): repository = RepositoryFactory.create( owner__username="drazisil-org", owner__service="github", owner__unencrypted_oauth_token="testtfasdfasdflxuu2kfer2ef23", - owner__plan="users", + owner__plan=PlanName.BASIC_PLAN_NAME.value, private=True, ) dbsession.add(repository) @@ -558,6 +569,7 @@ def test_get_decoration_type_for_users_plan(self, dbsession): not in enriched_pull_whitelisted.database_pull.repository.owner.plan_activated_users ) + @pytest.mark.django_db def test_get_decoration_type_pr_author_not_in_db(self, mocker, enriched_pull): enriched_pull.provider_pull["author"]["id"] = "190" @@ -567,6 +579,7 @@ def test_get_decoration_type_pr_author_not_in_db(self, mocker, enriched_pull): assert decoration_details.reason == "PR author not found in database" assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db def test_get_decoration_type_pr_author_manual_activation_required( self, dbsession, mocker, enriched_pull, with_sql_functions ): @@ -593,6 +606,7 @@ def test_get_decoration_type_pr_author_manual_activation_required( not in enriched_pull.database_pull.repository.owner.plan_activated_users ) + @pytest.mark.django_db @pytest.mark.parametrize( "is_bot,param,value", [ @@ -612,6 +626,7 @@ def test_is_bot_account(self, is_bot, param, value): pr_author.service_id = value assert _is_bot_account(pr_author) == is_bot + @pytest.mark.django_db def test_get_decoration_type_bot(self, dbsession, mocker, enriched_pull): pr_author = OwnerFactory.create( service="github", @@ -632,6 +647,7 @@ def test_get_decoration_type_bot(self, dbsession, mocker, enriched_pull): ) assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db def test_get_decoration_type_pr_author_already_active( self, dbsession, mocker, enriched_pull ): @@ -656,6 +672,7 @@ def test_get_decoration_type_pr_author_already_active( assert decoration_details.reason == "User is currently activated" assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db def test_get_decoration_type_should_attempt_pr_author_auto_activation( self, dbsession, mocker, enriched_pull ): @@ -688,6 +705,7 @@ def test_get_decoration_type_should_attempt_pr_author_auto_activation( not in enriched_pull.database_pull.repository.owner.plan_activated_users ) + @pytest.mark.django_db def test_get_decoration_type_should_attempt_pr_author_auto_activation_users_free( self, dbsession, mocker, enriched_pull ): @@ -721,6 +739,7 @@ def test_get_decoration_type_should_attempt_pr_author_auto_activation_users_free not in enriched_pull.database_pull.repository.owner.plan_activated_users ) + @pytest.mark.django_db def test_get_decoration_type_passing_empty_upload( self, dbsession, mocker, enriched_pull ): @@ -733,6 +752,7 @@ def test_get_decoration_type_passing_empty_upload( assert decoration_details.reason == "Non testable files got changed." assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db def test_get_decoration_type_failing_empty_upload( self, dbsession, mocker, enriched_pull ): @@ -745,6 +765,7 @@ def test_get_decoration_type_failing_empty_upload( assert decoration_details.reason == "Testable files got changed." assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db def test_get_decoration_type_processing_upload( self, dbsession, mocker, enriched_pull ): @@ -759,6 +780,11 @@ def test_get_decoration_type_processing_upload( class TestDecorationServiceGitLabTestCase(object): + @pytest.fixture(autouse=True) + def setup(self): + mock_all_plans_and_tiers() + + @pytest.mark.django_db def test_get_decoration_type_not_pr_plan_gitlab_subgroup( self, dbsession, @@ -776,6 +802,7 @@ def test_get_decoration_type_not_pr_plan_gitlab_subgroup( assert decoration_details.reason == "Org not on PR plan" assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db def test_get_decoration_type_pr_author_not_in_db_gitlab_subgroup( self, mocker, @@ -791,6 +818,7 @@ def test_get_decoration_type_pr_author_not_in_db_gitlab_subgroup( assert decoration_details.reason == "PR author not found in database" assert decoration_details.should_attempt_author_auto_activation is False + @pytest.mark.django_db def test_get_decoration_type_pr_author_manual_activation_required_gitlab_subgroup( self, dbsession, @@ -836,6 +864,7 @@ def test_get_decoration_type_pr_author_manual_activation_required_gitlab_subgrou # activation hasn't happened yet assert pr_author.ownerid not in gitlab_root_group.plan_activated_users + @pytest.mark.django_db def test_get_decoration_type_pr_author_already_active_subgroup( self, dbsession, @@ -864,6 +893,7 @@ def test_get_decoration_type_pr_author_already_active_subgroup( assert decoration_details.activation_org_ownerid is None assert decoration_details.activation_author_ownerid is None + @pytest.mark.django_db def test_get_decoration_type_should_attempt_pr_author_auto_activation( self, dbsession, @@ -895,6 +925,7 @@ def test_get_decoration_type_should_attempt_pr_author_auto_activation( # activation hasn't happened yet assert pr_author.ownerid not in gitlab_root_group.plan_activated_users + @pytest.mark.django_db def test_get_decoration_type_owner_activated_users_null( self, dbsession, mocker, enriched_pull ): @@ -956,6 +987,7 @@ def test_uploads_used_with_expired_trial(self, mocker, dbsession): assert uploads_used == 0 + @pytest.mark.django_db def test_author_is_activated_on_subgroup_not_root( self, dbsession, gitlab_root_group, gitlab_enriched_pull_subgroup ): diff --git a/services/tests/test_seats.py b/services/tests/test_seats.py index 8b1eb851a..bfc10e4c1 100644 --- a/services/tests/test_seats.py +++ b/services/tests/test_seats.py @@ -1,8 +1,10 @@ +import pytest from shared.billing import BillingPlan from database.tests.factories import OwnerFactory, PullFactory from services.repository import EnrichedPull from services.seats import ShouldActivateSeat, determine_seat_activation +from tests.helpers import mock_all_plans_and_tiers def test_seat_provider_none(dbsession): @@ -41,7 +43,9 @@ def test_seat_repo_public(dbsession): assert activate_seat_info.reason == "public_repo" +@pytest.mark.django_db def test_seat_billing_plan(dbsession): + mock_all_plans_and_tiers() pull = PullFactory() dbsession.add(pull) dbsession.flush() @@ -60,7 +64,9 @@ def test_seat_billing_plan(dbsession): assert activate_seat_info.reason == "no_pr_billing_plan" +@pytest.mark.django_db def test_seat_no_author(dbsession): + mock_all_plans_and_tiers() pull = PullFactory() dbsession.add(pull) dbsession.flush() @@ -79,7 +85,9 @@ def test_seat_no_author(dbsession): assert activate_seat_info.reason == "no_pr_author" +@pytest.mark.django_db def test_seat_author_in_org(dbsession): + mock_all_plans_and_tiers() pull = PullFactory() dbsession.add(pull) dbsession.flush() @@ -106,7 +114,9 @@ def test_seat_author_in_org(dbsession): assert activate_seat_info.reason == "author_in_plan_activated_users" +@pytest.mark.django_db def test_seat_author_not_in_org(dbsession): + mock_all_plans_and_tiers() pull = PullFactory() dbsession.add(pull) dbsession.flush() @@ -130,7 +140,9 @@ def test_seat_author_not_in_org(dbsession): assert activate_seat_info.reason == "manual_activate" +@pytest.mark.django_db def test_seat_author_auto_activate(dbsession): + mock_all_plans_and_tiers() pull = PullFactory() dbsession.add(pull) dbsession.flush() diff --git a/services/tests/test_test_results.py b/services/tests/test_test_results.py index 405a315a5..e7b322233 100644 --- a/services/tests/test_test_results.py +++ b/services/tests/test_test_results.py @@ -23,6 +23,7 @@ ) from services.urls import services_short_dict from services.yaml import UserYaml +from tests.helpers import mock_all_plans_and_tiers def mock_repo_service(): @@ -250,6 +251,7 @@ def test_notify_fail_no_pull( assert notification_result == NotifierResult.NO_PULL +@pytest.mark.django_db @pytest.mark.parametrize( "config,feature_flag,private,plan,ex_result", [ @@ -264,6 +266,7 @@ def test_notify_fail_no_pull( def test_should_do_flake_detection( dbsession, mocker, config, feature_flag, private, plan, ex_result ): + mock_all_plans_and_tiers() owner = OwnerFactory(plan=plan) repo = RepositoryFactory(private=private, owner=owner) dbsession.add(repo) diff --git a/tasks/tests/integration/test_notify_task.py b/tasks/tests/integration/test_notify_task.py index 6840b03c1..79a79203d 100644 --- a/tasks/tests/integration/test_notify_task.py +++ b/tasks/tests/integration/test_notify_task.py @@ -13,6 +13,7 @@ from services.notification.notifiers.base import NotificationResult from services.repository import EnrichedPull from tasks.notify import NotifyTask +from tests.helpers import mock_all_plans_and_tiers sample_token = "ghp_test6ldgmyaglf73gcnbi0kprz7dyjz6nzgn" @@ -28,7 +29,12 @@ def is_not_first_pull(mocker): @pytest.mark.integration class TestNotifyTask(object): + @pytest.fixture(autouse=True) + def setup(self): + mock_all_plans_and_tiers() + @patch("requests.post") + @pytest.mark.django_db def test_simple_call_no_notifiers( self, mock_requests_post, @@ -155,6 +161,7 @@ def test_simple_call_no_notifiers( } @patch("requests.post") + @pytest.mark.django_db def test_simple_call_only_status_notifiers( self, mock_post_request, @@ -358,6 +365,7 @@ def test_simple_call_only_status_notifiers( } @patch("requests.post") + @pytest.mark.django_db def test_simple_call_only_status_notifiers_no_pull_request( self, mock_post_request, @@ -584,6 +592,7 @@ def test_simple_call_only_status_notifiers_no_pull_request( assert result == expected_result @patch("requests.post") + @pytest.mark.django_db def test_simple_call_only_status_notifiers_with_pull_request( self, mock_post_request, @@ -1272,6 +1281,7 @@ def test_simple_call_status_and_notifiers( pull = dbsession.query(Pull).filter_by(pullid=9, repoid=commit.repoid).first() assert pull.commentid == "1699669573" + @pytest.mark.django_db def test_notifier_call_no_head_commit_report( self, dbsession, mocker, codecov_vcr, mock_storage, mock_configuration ): @@ -1327,6 +1337,7 @@ def test_notifier_call_no_head_commit_report( } assert result == expected_result + @pytest.mark.django_db @patch("requests.post") def test_notifier_call_no_head_commit_report_empty_upload( self, diff --git a/tasks/tests/unit/test_new_user_activated.py b/tasks/tests/unit/test_new_user_activated.py index 4d7becf0d..3bd3fdeb2 100644 --- a/tasks/tests/unit/test_new_user_activated.py +++ b/tasks/tests/unit/test_new_user_activated.py @@ -11,6 +11,7 @@ RepositoryFactory, ) from tasks.new_user_activated import NewUserActivatedTask +from tests.helpers import mock_all_plans_and_tiers @pytest.fixture @@ -44,6 +45,11 @@ def pull(dbsession): class TestNewUserActivatedTaskUnit(object): + @pytest.fixture(autouse=True) + def mock_all_plans_and_tiers(self): + mock_all_plans_and_tiers() + + @pytest.mark.django_db def test_get_pulls_authored_by_user_none(self, dbsession, pull): org_ownerid = pull.repository.ownerid user_ownerid_with_no_pulls = 12312412 @@ -52,6 +58,7 @@ def test_get_pulls_authored_by_user_none(self, dbsession, pull): ) assert res == [] + @pytest.mark.django_db def test_get_pulls_authored_by_user(self, dbsession, pull): pull_by_other_author = PullFactory.create( repository=pull.repository, @@ -72,6 +79,7 @@ def test_get_pulls_authored_by_user(self, dbsession, pull): assert authored_pull.state == "open" assert authored_pull.author.ownerid == user_ownerid + @pytest.mark.django_db def test_is_org_on_pr_plan_gitlab_subgroup(self, dbsession, with_sql_functions): root_group = OwnerFactory.create( username="root_group", @@ -94,6 +102,7 @@ def test_is_org_on_pr_plan_gitlab_subgroup(self, dbsession, with_sql_functions): res = NewUserActivatedTask().is_org_on_pr_plan(dbsession, subgroup.ownerid) assert res is True + @pytest.mark.django_db def test_org_not_found(self, mocker, dbsession): unknown_org_ownerid = 404123 user_ownerid = 123 @@ -106,6 +115,7 @@ def test_org_not_found(self, mocker, dbsession): "reason": "org not on pr author billing plan", } + @pytest.mark.django_db def test_org_not_on_pr_plan(self, mocker, dbsession, pull): pull.repository.owner.plan = "users-inappm" dbsession.flush() @@ -118,6 +128,7 @@ def test_org_not_on_pr_plan(self, mocker, dbsession, pull): "reason": "org not on pr author billing plan", } + @pytest.mark.django_db def test_no_commit_notifications_found(self, mocker, dbsession, pull): mocked_possibly_resend_notifications = mocker.patch( "tasks.new_user_activated.NewUserActivatedTask.possibly_resend_notifications" @@ -132,6 +143,7 @@ def test_no_commit_notifications_found(self, mocker, dbsession, pull): } assert not mocked_possibly_resend_notifications.called + @pytest.mark.django_db def test_no_head_commit_on_pull(self, mocker, dbsession, pull): pull.head = None mocked_possibly_resend_notifications = mocker.patch( @@ -147,6 +159,7 @@ def test_no_head_commit_on_pull(self, mocker, dbsession, pull): } assert not mocked_possibly_resend_notifications.called + @pytest.mark.django_db def test_commit_notifications_all_standard(self, mocker, dbsession, pull): pull_head_commit = pull.get_head_commit() cn1 = CommitNotificationFactory.create( @@ -174,6 +187,7 @@ def test_commit_notifications_all_standard(self, mocker, dbsession, pull): "reason": "no pulls/pull notifications met criteria", } + @pytest.mark.django_db def test_commit_notifications_resend_single_pull(self, mocker, dbsession, pull): pull_head_commit = pull.get_head_commit() cn1 = CommitNotificationFactory.create( diff --git a/tasks/tests/unit/test_sync_pull.py b/tasks/tests/unit/test_sync_pull.py index 9492854ed..13dca0661 100644 --- a/tasks/tests/unit/test_sync_pull.py +++ b/tasks/tests/unit/test_sync_pull.py @@ -16,6 +16,7 @@ from services.repository import EnrichedPull from services.yaml import UserYaml from tasks.sync_pull import PullSyncTask +from tests.helpers import mock_all_plans_and_tiers here = Path(__file__) @@ -60,6 +61,7 @@ def pull(dbsession, repository, base_commit, head_commit) -> Pull: "tests_exist", [True, False], ) +@pytest.mark.django_db def test_update_pull_commits_merged( dbsession, mocker, @@ -69,6 +71,7 @@ def test_update_pull_commits_merged( base_commit, pull, ): + mock_all_plans_and_tiers() mock_feature = mocker.patch("services.test_results.FLAKY_TEST_DETECTION") mock_feature.check_value.return_value = True @@ -512,7 +515,9 @@ def test_trigger_ai_pr_review( @pytest.mark.parametrize("flake_detection", [False, True]) +@pytest.mark.django_db def test_trigger_process_flakes(dbsession, mocker, flake_detection, repository): + mock_all_plans_and_tiers() current_yaml = UserYaml.from_dict(dict()) mock_feature = mocker.patch("services.test_results.FLAKY_TEST_DETECTION") mock_feature.check_value.return_value = True diff --git a/tasks/tests/unit/test_ta_finisher_task.py b/tasks/tests/unit/test_ta_finisher_task.py index e4464bdee..cb4e12c21 100644 --- a/tasks/tests/unit/test_ta_finisher_task.py +++ b/tasks/tests/unit/test_ta_finisher_task.py @@ -21,6 +21,7 @@ from services.urls import services_short_dict from tasks.ta_finisher import TAFinisherTask from tasks.ta_processor import TAProcessorTask +from tests.helpers import mock_all_plans_and_tiers here = Path(__file__) @@ -98,6 +99,7 @@ def generate_junit_xml( @travel("2025-01-01T00:00:00Z", tick=False) +@pytest.mark.django_db def test_test_analytics( dbsession, mocker, @@ -106,6 +108,7 @@ def test_test_analytics( snapshot, mock_repo_provider_comments, ): + mock_all_plans_and_tiers() url = "literally/whatever" testruns = [ diff --git a/tasks/tests/unit/test_test_results_finisher.py b/tasks/tests/unit/test_test_results_finisher.py index fa32e5366..b7921a964 100644 --- a/tasks/tests/unit/test_test_results_finisher.py +++ b/tasks/tests/unit/test_test_results_finisher.py @@ -26,6 +26,7 @@ from services.test_results import generate_test_id from services.urls import get_members_url from tasks.test_results_finisher import TestResultsFinisherTask +from tests.helpers import mock_all_plans_and_tiers here = Path(__file__) @@ -336,8 +337,12 @@ def test_results_setup_no_instances(mocker, dbsession): class TestUploadTestFinisherTask(object): + @pytest.fixture(autouse=True) + def setup(self): + mock_all_plans_and_tiers() + @pytest.mark.integration - @pytest.mark.django_db(databases={"default"}) + @pytest.mark.django_db def test_upload_finisher_task_call( self, mocker, @@ -458,6 +463,7 @@ def test_upload_finisher_task_call( ) @pytest.mark.integration + @pytest.mark.django_db def test_upload_finisher_task_call_no_failures( self, mocker, @@ -515,6 +521,7 @@ def test_upload_finisher_task_call_no_failures( assert expected_result == result + @pytest.mark.django_db @pytest.mark.integration def test_upload_finisher_task_call_no_success( self, @@ -576,6 +583,7 @@ def test_upload_finisher_task_call_no_success( ) @pytest.mark.integration + @pytest.mark.django_db def test_upload_finisher_task_call_upgrade_comment( self, mocker, @@ -648,6 +656,7 @@ def test_upload_finisher_task_call_upgrade_comment( ) @pytest.mark.integration + @pytest.mark.django_db def test_upload_finisher_task_call_existing_comment( self, mocker, @@ -773,6 +782,7 @@ def test_upload_finisher_task_call_existing_comment( assert expected_result == result @pytest.mark.integration + @pytest.mark.django_db def test_upload_finisher_task_call_comment_fails( self, mocker, @@ -822,6 +832,7 @@ def test_upload_finisher_task_call_comment_fails( "fail_count,count,recent_passes_count", [(2, 15, 13), (50, 150, 10)] ) @pytest.mark.integration + @pytest.mark.django_db def test_upload_finisher_task_call_with_flaky( self, mocker, @@ -932,6 +943,7 @@ def test_upload_finisher_task_call_with_flaky( ) @pytest.mark.integration + @pytest.mark.django_db def test_upload_finisher_task_call_main_branch( self, mocker, @@ -988,7 +1000,7 @@ def test_upload_finisher_task_call_main_branch( ) @pytest.mark.integration - @pytest.mark.django_db(databases={"default"}) + @pytest.mark.django_db def test_upload_finisher_task_call_computed_name( self, mocker, @@ -1105,6 +1117,7 @@ def test_upload_finisher_task_call_computed_name( ) @pytest.mark.integration + @pytest.mark.django_db @pytest.mark.parametrize("plan", ["users-basic", "users-pr-inappm"]) def test_upload_finisher_task_call_main_with_plan( self, diff --git a/tests/helpers.py b/tests/helpers.py new file mode 100644 index 000000000..56d82d6b8 --- /dev/null +++ b/tests/helpers.py @@ -0,0 +1,176 @@ +from shared.django_apps.codecov_auth.models import BillingRate +from shared.django_apps.codecov_auth.tests.factories import PlanFactory, TierFactory +from shared.plan.constants import PlanName, PlanPrice, TierName + + +def mock_all_plans_and_tiers(): + trial_tier = TierFactory(tier_name=TierName.TRIAL.value) + PlanFactory( + tier=trial_tier, + name=PlanName.TRIAL_PLAN_NAME.value, + paid_plan=False, + marketing_name="Developer", + benefits=[ + "Configurable # of users", + "Unlimited public repositories", + "Unlimited private repositories", + "Priority Support", + ], + ) + + basic_tier = TierFactory(tier_name=TierName.BASIC.value) + PlanFactory( + name=PlanName.BASIC_PLAN_NAME.value, + tier=basic_tier, + marketing_name="Developer", + benefits=[ + "Up to 1 user", + "Unlimited public repositories", + "Unlimited private repositories", + ], + monthly_uploads_limit=250, + ) + PlanFactory( + name=PlanName.FREE_PLAN_NAME.value, + tier=basic_tier, + marketing_name="Developer", + benefits=[ + "Up to 1 user", + "Unlimited public repositories", + "Unlimited private repositories", + ], + ) + + pro_tier = TierFactory(tier_name=TierName.PRO.value) + PlanFactory( + name=PlanName.CODECOV_PRO_MONTHLY.value, + tier=pro_tier, + marketing_name="Pro", + benefits=[ + "Configurable # of users", + "Unlimited public repositories", + "Unlimited private repositories", + "Priority Support", + ], + billing_rate=BillingRate.MONTHLY.value, + base_unit_price=PlanPrice.MONTHLY.value, + paid_plan=True, + ) + PlanFactory( + name=PlanName.CODECOV_PRO_YEARLY.value, + tier=pro_tier, + marketing_name="Pro", + benefits=[ + "Configurable # of users", + "Unlimited public repositories", + "Unlimited private repositories", + "Priority Support", + ], + billing_rate=BillingRate.ANNUALLY.value, + base_unit_price=PlanPrice.YEARLY.value, + paid_plan=True, + ) + PlanFactory( + name=PlanName.CODECOV_PRO_MONTHLY_LEGACY.value, + tier=pro_tier, + marketing_name="Pro", + benefits=[ + "Configurable # of users", + "Unlimited public repositories", + "Unlimited private repositories", + "Priority Support", + ], + ) + PlanFactory( + name=PlanName.CODECOV_PRO_YEARLY_LEGACY.value, + tier=pro_tier, + marketing_name="Pro", + benefits=[ + "Configurable # of users", + "Unlimited public repositories", + "Unlimited private repositories", + "Priority Support", + ], + ) + + team_tier = TierFactory(tier_name=TierName.TEAM.value) + PlanFactory( + name=PlanName.TEAM_MONTHLY.value, + tier=team_tier, + marketing_name="Team", + benefits=[ + "Up to 10 users", + "Unlimited repositories", + "2500 private repo uploads", + "Patch coverage analysis", + ], + billing_rate=BillingRate.MONTHLY.value, + base_unit_price=PlanPrice.TEAM_MONTHLY.value, + monthly_uploads_limit=2500, + paid_plan=True, + ) + PlanFactory( + name=PlanName.TEAM_YEARLY.value, + tier=team_tier, + marketing_name="Team", + benefits=[ + "Up to 10 users", + "Unlimited repositories", + "2500 private repo uploads", + "Patch coverage analysis", + ], + billing_rate=BillingRate.ANNUALLY.value, + base_unit_price=PlanPrice.TEAM_YEARLY.value, + monthly_uploads_limit=2500, + paid_plan=True, + ) + + sentry_tier = TierFactory(tier_name=TierName.SENTRY.value) + PlanFactory( + name=PlanName.SENTRY_MONTHLY.value, + tier=sentry_tier, + marketing_name="Sentry Pro", + billing_rate=BillingRate.MONTHLY.value, + base_unit_price=PlanPrice.MONTHLY.value, + paid_plan=True, + benefits=[ + "Includes 5 seats", + "$12 per additional seat", + "Unlimited public repositories", + "Unlimited private repositories", + "Priority Support", + ], + ) + PlanFactory( + name=PlanName.SENTRY_YEARLY.value, + tier=sentry_tier, + marketing_name="Sentry Pro", + billing_rate=BillingRate.ANNUALLY.value, + base_unit_price=PlanPrice.YEARLY.value, + paid_plan=True, + benefits=[ + "Includes 5 seats", + "$10 per additional seat", + "Unlimited public repositories", + "Unlimited private repositories", + "Priority Support", + ], + ) + + enterprise_tier = TierFactory(tier_name=TierName.ENTERPRISE.value) + PlanFactory( + name=PlanName.ENTERPRISE_CLOUD_MONTHLY.value, + tier=enterprise_tier, + marketing_name="Enterprise", + billing_rate=BillingRate.MONTHLY.value, + base_unit_price=PlanPrice.MONTHLY.value, + paid_plan=True, + ) + PlanFactory( + name=PlanName.ENTERPRISE_CLOUD_YEARLY.value, + tier=enterprise_tier, + marketing_name="Enterprise", + billing_rate=BillingRate.ANNUALLY.value, + base_unit_price=PlanPrice.YEARLY.value, + paid_plan=True, + )