Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion database/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

)
plan_seat_count = Column(types.SmallInteger, nullable=False, default=1)
free_seat_count = Column(types.SmallInteger, nullable=False, default=0)
Expand Down
32 changes: 31 additions & 1 deletion database/tests/factories/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
)
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:
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",
[
Expand All @@ -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
):
Expand Down Expand Up @@ -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
):
Expand All @@ -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
):
Expand Down Expand Up @@ -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",
[
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions services/bundle_analysis/notify/tests/test_notify_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions services/bundle_analysis/tests/test_bundle_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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:
Expand Down Expand Up @@ -57,6 +58,7 @@ def hook_mock_pull(mocker, mock_pull):
mocker.patch(usage, return_value=mock_pull)


@pytest.mark.django_db
@pytest.mark.parametrize(
"bundle_changes, bundle_routes_changes, percent_change, user_config, expected_message",
[
Expand Down Expand Up @@ -396,6 +398,7 @@ def test_bundle_analysis_notify(
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)
Expand Down Expand Up @@ -517,6 +520,7 @@ def test_bundle_analysis_notify(
)


@pytest.mark.django_db
@pytest.mark.asyncio
async def test_bundle_analysis_save_measurements_report_size(
dbsession, mocker, mock_storage
Expand Down
2 changes: 0 additions & 2 deletions services/comparison/tests/unit/overlay/test_critical_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ def test_find_impacted_endpoints(
}
mock_storage.write_file("bucket", url, sample_open_telemetry_collected_as_str)
a = CriticalPathOverlay(sample_comparison, None)
print(sample_comparison.head.report.files)
print(sample_comparison.head.report.files)
res = a.find_impacted_endpoints()
assert res == [
{
Expand Down
23 changes: 16 additions & 7 deletions services/notification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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: (
Expand Down
2 changes: 0 additions & 2 deletions services/notification/notifiers/tests/unit/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_build_payload_without_attachments(
"author_name": "Codecov",
"text": text,
}
print(result["text"])
assert result == expected_result

def test_build_payload_with_attachments(
Expand Down Expand Up @@ -83,7 +82,6 @@ def test_build_payload_with_message(
"author_name": "Codecov",
"text": "This is a sample",
}
print(result["text"])
assert result == expected_result

def test_build_payload_without_pull(
Expand Down
Loading
Loading