Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 7216f13

Browse files
committed
81 failing tests, realized should start with shared
1 parent ccc2534 commit 7216f13

File tree

6 files changed

+127
-38
lines changed

6 files changed

+127
-38
lines changed

database/tests/factories/core.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import factory
66
from factory import Factory
7-
from shared.plan.constants import PlanName
7+
from shared.django_apps.codecov_auth.models import Plan, Tier
8+
from shared.plan.constants import PlanName, TierName
89

910
from database import enums, models
1011
from services.encryption import encryptor
@@ -298,3 +299,32 @@ class Meta:
298299

299300
key = ""
300301
value = ""
302+
303+
304+
class TierFactory(Factory):
305+
class Meta:
306+
model = Tier
307+
308+
tier_name = TierName.BASIC.value
309+
bundle_analysis = False
310+
test_analytics = False
311+
flaky_test_detection = False
312+
project_coverage = False
313+
private_repo_support = False
314+
315+
316+
class PlanFactory(Factory):
317+
class Meta:
318+
model = Plan
319+
320+
tier = factory.SubFactory(TierFactory)
321+
base_unit_price = 0
322+
benefits = factory.LazyFunction(lambda: ["Benefit 1", "Benefit 2", "Benefit 3"])
323+
billing_rate = None
324+
is_active = True
325+
marketing_name = factory.Faker("catch_phrase")
326+
max_seats = 1
327+
monthly_uploads_limit = None
328+
name = PlanName.BASIC_PLAN_NAME.value
329+
paid_plan = False
330+
stripe_id = None

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
https://github.com/codecov/test-results-parser/archive/190bbc8a911099749928e13d5fe57f6027ca1e74.tar.gz#egg=test-results-parser
2-
https://github.com/codecov/shared/archive/191837f5e35f5efc410e670aac7e50e0d09e43e1.tar.gz#egg=shared
2+
https://github.com/codecov/shared/archive/52fdc2d14fa21d4c476d3264b021e42390b30c5f.tar.gz#egg=shared
33
https://github.com/codecov/timestring/archive/d37ceacc5954dff3b5bd2f887936a98a668dda42.tar.gz#egg=timestring
44
asgiref>=3.7.2
55
analytics-python==1.3.0b1

requirements.txt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
# This file was autogenerated by uv via the following command:
2-
# uv pip compile requirements.in -o requirements.txt
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.12
3+
# by the following command:
4+
#
5+
# pip-compile requirements.in
6+
#
37
amqp==5.2.0
48
# via kombu
59
analytics-python==1.3.0b1
@@ -73,7 +77,7 @@ codecov-ribs==0.1.18
7377
# shared
7478
colour==0.1.5
7579
# via shared
76-
coverage==7.5.0
80+
coverage[toml]==7.5.0
7781
# via
7882
# -r requirements.in
7983
# pytest-cov
@@ -111,7 +115,7 @@ filelock==3.12.4
111115
# via virtualenv
112116
freezegun==1.5.0
113117
# via pytest-freezegun
114-
google-api-core==2.23.0
118+
google-api-core[grpc]==2.23.0
115119
# via
116120
# google-cloud-bigquery
117121
# google-cloud-bigquery-storage
@@ -151,7 +155,7 @@ google-resumable-media==2.7.2
151155
# via
152156
# google-cloud-bigquery
153157
# google-cloud-storage
154-
googleapis-common-protos==1.66.0
158+
googleapis-common-protos[grpc]==1.66.0
155159
# via
156160
# google-api-core
157161
# grpc-google-iam-v1
@@ -363,19 +367,17 @@ requests==2.32.3
363367
# stripe
364368
respx==0.20.2
365369
# via -r requirements.in
366-
rfc3986==1.4.0
370+
rfc3986[idna2008]==1.4.0
367371
# via httpx
368372
rsa==4.7.2
369373
# via google-auth
370374
s3transfer==0.10.1
371375
# via boto3
372-
sentry-sdk==2.13.0
376+
sentry-sdk[celery]==2.13.0
373377
# via
374378
# -r requirements.in
375379
# shared
376-
setuptools==75.7.0
377-
# via nodeenv
378-
shared @ https://github.com/codecov/shared/archive/191837f5e35f5efc410e670aac7e50e0d09e43e1.tar.gz#egg=shared
380+
shared @ https://github.com/codecov/shared/archive/52fdc2d14fa21d4c476d3264b021e42390b30c5f.tar.gz
379381
# via -r requirements.in
380382
six==1.16.0
381383
# via
@@ -405,13 +407,13 @@ statsd==3.3.0
405407
# via -r requirements.in
406408
stripe==11.4.1
407409
# via -r requirements.in
408-
test-results-parser @ https://github.com/codecov/test-results-parser/archive/190bbc8a911099749928e13d5fe57f6027ca1e74.tar.gz#egg=test-results-parser
410+
test-results-parser @ https://github.com/codecov/test-results-parser/archive/190bbc8a911099749928e13d5fe57f6027ca1e74.tar.gz
409411
# via -r requirements.in
410412
text-unidecode==1.3
411413
# via faker
412414
time-machine==2.14.1
413415
# via -r requirements.in
414-
timestring @ https://github.com/codecov/timestring/archive/d37ceacc5954dff3b5bd2f887936a98a668dda42.tar.gz#egg=timestring
416+
timestring @ https://github.com/codecov/timestring/archive/d37ceacc5954dff3b5bd2f887936a98a668dda42.tar.gz
415417
# via -r requirements.in
416418
tqdm==4.66.1
417419
# via openai
@@ -455,3 +457,6 @@ zstandard==0.23.0
455457
# via
456458
# -r requirements.in
457459
# shared
460+
461+
# The following packages are considered to be unsafe in a requirements file:
462+
# setuptools

services/notification/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from celery.exceptions import CeleryError, SoftTimeLimitExceeded
1212
from shared.config import get_config
13+
from shared.django_apps.codecov_auth.models import Plan
1314
from shared.helpers.yaml import default_if_true
1415
from shared.plan.constants import TierName
1516
from shared.torngit.base import TorngitBaseAdapter
@@ -66,11 +67,10 @@ def __init__(
6667
def _should_use_status_notifier(self, status_type: StatusType) -> bool:
6768
owner: Owner = self.repository.owner
6869

70+
plan = Plan.objects.get(name=owner.plan)
71+
6972
if (
70-
owner.plan
71-
in Plan.objects.filter(tier=TierName.TEAM.value).values_list(
72-
"name", flat=True
73-
)
73+
plan.tier.tier_name == TierName.TEAM.value
7474
and status_type != StatusType.PATCH.value
7575
):
7676
return False
@@ -86,11 +86,10 @@ def _should_use_checks_notifier(self, status_type: StatusType) -> bool:
8686
if owner.service not in ["github", "github_enterprise"]:
8787
return False
8888

89+
plan = Plan.objects.get(name=owner.plan)
90+
8991
if (
90-
owner.plan
91-
in Plan.objects.filter(tier=TierName.TEAM.value).values_list(
92-
"name", flat=True
93-
)
92+
plan.tier.tier_name == TierName.TEAM.value
9493
and status_type != StatusType.PATCH.value
9594
):
9695
return False

services/notification/tests/unit/test_notification_service.py

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
22
from asyncio import CancelledError
33
from asyncio import TimeoutError as AsyncioTimeoutError
4+
from unittest.mock import patch
45

56
import mock
67
import pytest
78
from celery.exceptions import SoftTimeLimitExceeded
8-
from shared.plan.constants import PlanName
9+
from shared.plan.constants import PlanName, TierName
910
from shared.reports.resources import Report, ReportFile, ReportLine
1011
from shared.torngit.status import Status
1112
from shared.yaml import UserYaml
@@ -16,6 +17,7 @@
1617
GithubAppInstallation,
1718
)
1819
from database.tests.factories import CommitFactory, PullFactory, RepositoryFactory
20+
from database.tests.factories.core import PlanFactory, TierFactory
1921
from services.comparison import ComparisonProxy
2022
from services.comparison.types import Comparison, EnrichedPull, FullCommit
2123
from services.notification import NotificationService
@@ -103,9 +105,13 @@ def test_should_use_checks_notifier_yaml_field_false(self, dbsession):
103105
),
104106
],
105107
)
108+
@patch("services.notification.Plan.objects.get")
106109
def test_should_use_checks_notifier_deprecated_flow(
107-
self, repo_data, outcome, dbsession
110+
self, plan_objects_get, repo_data, outcome, dbsession
108111
):
112+
plan = PlanFactory.create()
113+
plan_objects_get.return_value = plan
114+
109115
repository = RepositoryFactory.create(**repo_data)
110116
current_yaml = {"github_checks": True}
111117
assert repository.owner.github_app_installations == []
@@ -115,7 +121,12 @@ def test_should_use_checks_notifier_deprecated_flow(
115121
== outcome
116122
)
117123

118-
def test_should_use_checks_notifier_ghapp_all_repos_covered(self, dbsession):
124+
@patch("services.notification.Plan.objects.get")
125+
def test_should_use_checks_notifier_ghapp_all_repos_covered(
126+
self, plan_objects_get, dbsession
127+
):
128+
plan = PlanFactory.create()
129+
plan_objects_get.return_value = plan
119130
repository = RepositoryFactory.create(owner__service="github")
120131
ghapp_installation = GithubAppInstallation(
121132
name=GITHUB_APP_INSTALLATION_DEFAULT_NAME,
@@ -133,9 +144,19 @@ def test_should_use_checks_notifier_ghapp_all_repos_covered(self, dbsession):
133144
== True
134145
)
135146

136-
def test_use_checks_notifier_for_team_plan(self, dbsession):
147+
@patch("services.notification.Plan.objects.get")
148+
def test_use_checks_notifier_for_team_plan(
149+
self,
150+
plan_objects_get,
151+
dbsession,
152+
):
153+
tier = TierFactory.create(
154+
tier_name=TierName.TEAM.value,
155+
)
156+
plan = PlanFactory.create(tier=tier, name=PlanName.TEAM_MONTHLY.value)
157+
plan_objects_get.return_value = plan
137158
repository = RepositoryFactory.create(
138-
owner__service="github", owner__plan=PlanName.TEAM_MONTHLY.value
159+
owner__service="github", owner__plan=plan.name
139160
)
140161
ghapp_installation = GithubAppInstallation(
141162
name=GITHUB_APP_INSTALLATION_DEFAULT_NAME,
@@ -161,9 +182,16 @@ def test_use_checks_notifier_for_team_plan(self, dbsession):
161182
== True
162183
)
163184

164-
def test_use_status_notifier_for_team_plan(self, dbsession):
185+
@patch("services.notification.Plan.objects.get")
186+
def test_use_status_notifier_for_team_plan(self, plan_objects_get, dbsession):
187+
tier = TierFactory.create(
188+
tier_name=TierName.TEAM.value,
189+
)
190+
plan = PlanFactory.create(tier=tier, name=PlanName.TEAM_MONTHLY.value)
191+
plan_objects_get.return_value = plan
192+
165193
repository = RepositoryFactory.create(
166-
owner__service="github", owner__plan=PlanName.TEAM_MONTHLY.value
194+
owner__service="github", owner__plan=plan.name
167195
)
168196
ghapp_installation = GithubAppInstallation(
169197
name=GITHUB_APP_INSTALLATION_DEFAULT_NAME,
@@ -189,9 +217,15 @@ def test_use_status_notifier_for_team_plan(self, dbsession):
189217
== True
190218
)
191219

192-
def test_use_status_notifier_for_non_team_plan(self, dbsession):
220+
@patch("services.notification.Plan.objects.get")
221+
def test_use_status_notifier_for_non_team_plan(self, plan_objects_get, dbsession):
222+
tier = TierFactory.create(
223+
tier_name=TierName.PRO.value,
224+
)
225+
plan = PlanFactory.create(tier=tier, name=PlanName.CODECOV_PRO_MONTHLY.value)
226+
plan_objects_get.return_value = plan
193227
repository = RepositoryFactory.create(
194-
owner__service="github", owner__plan=PlanName.CODECOV_PRO_MONTHLY.value
228+
owner__service="github", owner__plan=plan.name
195229
)
196230
ghapp_installation = GithubAppInstallation(
197231
name=GITHUB_APP_INSTALLATION_DEFAULT_NAME,
@@ -221,9 +255,12 @@ def test_use_status_notifier_for_non_team_plan(self, dbsession):
221255
"gh_installation_name",
222256
[GITHUB_APP_INSTALLATION_DEFAULT_NAME, "notifications-app"],
223257
)
258+
@patch("services.notification.Plan.objects.get")
224259
def test_should_use_checks_notifier_ghapp_some_repos_covered(
225-
self, dbsession, gh_installation_name
260+
self, plan_objects_get, dbsession, gh_installation_name
226261
):
262+
plan = PlanFactory.create()
263+
plan_objects_get.return_value = plan
227264
repository = RepositoryFactory.create(owner__service="github")
228265
other_repo_same_owner = RepositoryFactory.create(owner=repository.owner)
229266
ghapp_installation = GithubAppInstallation(
@@ -281,9 +318,12 @@ def test_get_notifiers_instances_only_third_party(
281318
assert instance.site_settings == ["slack.com"]
282319
assert instance.current_yaml == current_yaml
283320

321+
@patch("services.notification.Plan.objects.get")
284322
def test_get_notifiers_instances_checks(
285-
self, dbsession, mock_configuration, mocker
323+
self, plan_objects_get, dbsession, mock_configuration, mocker
286324
):
325+
plan = PlanFactory.create()
326+
plan_objects_get.return_value = plan
287327
repository = RepositoryFactory.create(
288328
owner__integration_id=123,
289329
owner__service="github",
@@ -310,9 +350,12 @@ def test_get_notifiers_instances_checks(
310350
"codecov-slack-app",
311351
]
312352

353+
@patch("services.notification.Plan.objects.get")
313354
def test_get_notifiers_instances_slack_app_false(
314-
self, dbsession, mock_configuration, mocker
355+
self, plan_objects_get, dbsession, mock_configuration, mocker
315356
):
357+
plan = PlanFactory.create()
358+
plan_objects_get.return_value = plan
316359
mocker.patch("services.notification.get_config", return_value=False)
317360
repository = RepositoryFactory.create(
318361
owner__integration_id=123,
@@ -343,9 +386,17 @@ def test_get_notifiers_instances_slack_app_false(
343386
"gh_installation_name",
344387
[GITHUB_APP_INSTALLATION_DEFAULT_NAME, "notifications-app"],
345388
)
389+
@patch("services.notification.Plan.objects.get")
346390
def test_get_notifiers_instances_checks_percentage_whitelist(
347-
self, dbsession, mock_configuration, mocker, gh_installation_name
391+
self,
392+
plan_objects_get,
393+
dbsession,
394+
mock_configuration,
395+
mocker,
396+
gh_installation_name,
348397
):
398+
plan = PlanFactory.create()
399+
plan_objects_get.return_value = plan
349400
repository = RepositoryFactory.create(
350401
owner__integration_id=123,
351402
owner__service="github",

services/test_results.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from hashlib import sha256
44
from typing import Sequence
55

6-
from shared.plan.constants import FREE_PLAN_REPRESENTATIONS, TEAM_PLAN_REPRESENTATIONS
6+
from shared.django_apps.codecov_auth.models import Plan
7+
from shared.plan.constants import TierName
78
from shared.yaml import UserYaml
89
from sqlalchemy import desc, distinct, func
910
from sqlalchemy.orm import joinedload
@@ -395,10 +396,13 @@ def get_test_summary_for_commit(
395396

396397

397398
def not_private_and_free_or_team(repo: Repository):
399+
plan = Plan.objects.get(name=repo.owner.plan)
398400
return not (
399401
repo.private
400-
and repo.owner.plan
401-
in {**FREE_PLAN_REPRESENTATIONS, **TEAM_PLAN_REPRESENTATIONS}
402+
and (
403+
plan.tier.tier_name != TierName.FREE.value
404+
and plan.tier.tier_name != TierName.TEAM.value
405+
)
402406
)
403407

404408

0 commit comments

Comments
 (0)