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

Commit f26a4e4

Browse files
committed
Use shared report_service and test factories
This switches most of the code using the `report_builder` service to use that same code imported from `shared` (except some functions specific to `api`). Similarly, the `core.tests.factories` were also duplicated in shared, so this switches over to those factories, deleting them from `api`.
1 parent e14d14d commit f26a4e4

File tree

228 files changed

+856
-1432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+856
-1432
lines changed

api/internal/commit/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import logging
22

3+
import shared.reports.api_report_service as report_service
34
from rest_framework import serializers
45
from shared.reports.types import TOTALS_MAP
56

6-
import services.report as report_service
77
from api.internal.owner.serializers import OwnerSerializer
88
from api.shared.commit.serializers import CommitTotalsSerializer
99
from core.models import Commit

api/internal/tests/test_charts.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pytz import UTC
1414
from rest_framework.exceptions import ValidationError
1515
from rest_framework.reverse import reverse
16+
from shared.django_apps.core.tests.factories import OwnerFactory, RepositoryFactory
1617

1718
from api.internal.chart.filters import apply_default_filters, apply_simple_filters
1819
from api.internal.chart.helpers import (
@@ -23,7 +24,6 @@
2324
)
2425
from codecov.tests.base_test import InternalAPITest
2526
from core.models import Commit
26-
from core.tests.factories import OwnerFactory, RepositoryFactory
2727
from utils.test_utils import Client
2828

2929
fake = faker.Faker()
@@ -56,7 +56,7 @@ def generate_random_totals(
5656
def setup_commits(
5757
repo,
5858
num_commits,
59-
branch="master",
59+
branch="main",
6060
start_date=None,
6161
meets_default_filters=True,
6262
**kwargs,
@@ -251,7 +251,7 @@ def test_apply_simple_filters(self):
251251
end_date = datetime.now()
252252
data = {
253253
"owner_username": self.org1.username,
254-
"branch": "master",
254+
"branch": "main",
255255
"start_date": start_date.isoformat(),
256256
"end_date": end_date.isoformat(),
257257
"repositories": [self.repo1_org1.name, self.repo2_org1.name],
@@ -318,7 +318,7 @@ def test_apply_simple_filters_branch_filtering(self):
318318
for commit in queryset:
319319
assert (
320320
commit.repository.name == self.repo1_org1.name
321-
and commit.branch == "master"
321+
and commit.branch == "main"
322322
) or (
323323
commit.repository.name == branch_test.name and commit.branch == "main"
324324
)
@@ -860,7 +860,7 @@ def setUp(self):
860860

861861
def test_no_permissions(self, mocked_get_permissions):
862862
data = {
863-
"branch": "master",
863+
"branch": "main",
864864
"start_date": timezone.now() - timedelta(7),
865865
"end_date": timezone.now(),
866866
"grouping_unit": "commit",
@@ -879,7 +879,7 @@ def test_no_permissions(self, mocked_get_permissions):
879879
@pytest.mark.skip(reason="flaky, skipping until re write")
880880
def test_get_commits_no_time_grouping(self, mocked_get_permissions):
881881
data = {
882-
"branch": "master",
882+
"branch": "main",
883883
"start_date": timezone.now() - timedelta(7),
884884
"end_date": timezone.now(),
885885
"grouping_unit": "commit",
@@ -897,7 +897,7 @@ def test_get_commits_no_time_grouping(self, mocked_get_permissions):
897897

898898
def test_get_commits_with_time_grouping(self, mocked_get_permissions):
899899
data = {
900-
"branch": "master",
900+
"branch": "main",
901901
"start_date": timezone.now() - timedelta(7),
902902
"end_date": timezone.now(),
903903
"grouping_unit": "day",
@@ -917,7 +917,7 @@ def test_get_commits_with_time_grouping(self, mocked_get_permissions):
917917

918918
def test_get_commits_with_coverage_change(self, mocked_get_permissions):
919919
data = {
920-
"branch": "master",
920+
"branch": "main",
921921
"start_date": timezone.now() - timedelta(7),
922922
"end_date": timezone.now(),
923923
"grouping_unit": "day",

api/internal/tests/test_feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import pytest
44
from django.urls import reverse
55
from rest_framework.test import APITestCase
6+
from shared.django_apps.core.tests.factories import OwnerFactory
67
from shared.django_apps.rollouts.models import (
78
FeatureFlag,
89
FeatureFlagVariant,
910
RolloutUniverse,
1011
)
1112

12-
from codecov_auth.tests.factories import OwnerFactory
1313
from utils.test_utils import Client
1414

1515

api/internal/tests/test_pagination.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from rest_framework.reverse import reverse
22
from rest_framework.test import APITestCase
3+
from shared.django_apps.core.tests.factories import OwnerFactory
34

4-
from codecov_auth.tests.factories import OwnerFactory
55
from utils.test_utils import Client
66

77

api/internal/tests/test_permissions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
from django.test import TestCase, override_settings
44
from rest_framework.exceptions import APIException
5+
from shared.django_apps.core.tests.factories import OwnerFactory, RepositoryFactory
56

67
from api.internal.tests.test_utils import (
78
GetAdminErrorProviderAdapter,
89
GetAdminProviderAdapter,
910
)
1011
from api.shared.permissions import RepositoryPermissionsService, UserIsAdminPermissions
11-
from codecov_auth.tests.factories import OwnerFactory
12-
from core.tests.factories import RepositoryFactory
1312

1413

1514
class MockedPermissionsAdapter:

api/internal/tests/test_repo_accessors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from unittest.mock import patch
22

33
from django.test import TestCase
4+
from shared.django_apps.core.tests.factories import OwnerFactory, RepositoryFactory
45
from shared.torngit.exceptions import TorngitClientError, TorngitClientGeneralError
56

67
from api.shared.repo.repository_accessors import RepoAccessors
7-
from codecov_auth.tests.factories import OwnerFactory
8-
from core.tests.factories import RepositoryFactory
98

109

1110
class RepositoryAccessorsTestCase(TestCase):

api/internal/tests/test_views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
from rest_framework import status
55
from rest_framework.reverse import reverse
6-
7-
from codecov.tests.base_test import InternalAPITest
8-
from codecov_auth.tests.factories import OwnerFactory
9-
from core.tests.factories import (
6+
from shared.django_apps.core.tests.factories import (
107
BranchFactory,
118
CommitFactory,
9+
OwnerFactory,
1210
PullFactory,
1311
RepositoryFactory,
1412
)
13+
14+
from codecov.tests.base_test import InternalAPITest
1515
from utils.test_utils import Client
1616

1717
get_permissions_method = (

api/internal/tests/unit/views/test_compare_flags_view.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
from unittest.mock import PropertyMock, patch
33

44
from rest_framework.reverse import reverse
5+
from shared.django_apps.core.tests.factories import (
6+
CommitWithReportFactory,
7+
PullFactory,
8+
RepositoryFactory,
9+
)
510
from shared.reports.types import ReportTotals
611

712
from codecov.tests.base_test import InternalAPITest
8-
from core.tests.factories import CommitWithReportFactory, PullFactory, RepositoryFactory
913

1014
current_file = Path(__file__)
1115

1216

1317
@patch("services.comparison.Comparison.git_comparison", new_callable=PropertyMock)
14-
@patch("services.archive.ArchiveService.read_chunks")
18+
@patch("shared.api_archive.archive.ArchiveService.read_chunks")
1519
@patch("shared.reports.filtered.FilteredReport.apply_diff")
1620
@patch(
1721
"api.shared.repo.repository_accessors.RepoAccessors.get_repo_permissions",
@@ -83,8 +87,7 @@ def test_compare_flags___success(
8387
)
8488

8589
assert response.status_code == 200
86-
87-
expected_result = [
90+
assert response.data == [
8891
{
8992
"name": "unittests",
9093
"base_report_totals": {
@@ -189,18 +192,6 @@ def test_compare_flags___success(
189192
},
190193
]
191194

192-
assert (
193-
response.data[0]["base_report_totals"]
194-
== expected_result[0]["base_report_totals"]
195-
)
196-
assert (
197-
response.data[0]["head_report_totals"]
198-
== expected_result[0]["head_report_totals"]
199-
)
200-
assert response.data[0] == expected_result[0]
201-
assert response.data[1] == expected_result[1]
202-
assert response.data == expected_result
203-
204195
def test_compare_flags_with_report_with_cff_and_non_cff(
205196
self, diff_totals_mock, read_chunks_mock, git_comparison_mock
206197
):
@@ -210,6 +201,12 @@ def test_compare_flags_with_report_with_cff_and_non_cff(
210201
parent_commit_id=self.parent_commit.commitid,
211202
repository=self.repo,
212203
)
204+
report = commit_with_custom_reports._report
205+
report["sessions"]["0"].update(
206+
st="carriedforward",
207+
se={"carriedforward_from": "56e05fced214c44a37759efa2dfc25a65d8ae98d"},
208+
)
209+
commit_with_custom_reports.save()
213210

214211
upload = (
215212
commit_with_custom_reports.reports.first()
@@ -222,14 +219,6 @@ def test_compare_flags_with_report_with_cff_and_non_cff(
222219
}
223220
upload.save()
224221

225-
upload = (
226-
commit_with_custom_reports.reports.first()
227-
.sessions.filter(flags__flag_name="integrations")
228-
.first()
229-
)
230-
upload.upload_type = "uploaded"
231-
upload.save()
232-
233222
head_chunks = open(
234223
current_file.parent.parent.parent
235224
/ f"samples/{commit_with_custom_reports.commitid}_chunks.txt",

api/internal/tests/unit/views/test_compare_view.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
from rest_framework import status
55
from rest_framework.reverse import reverse
6-
7-
from api.internal.commit.serializers import CommitTotalsSerializer
8-
from codecov.tests.base_test import InternalAPITest
9-
from codecov_auth.tests.factories import OwnerFactory
10-
from core.tests.factories import (
6+
from shared.django_apps.core.tests.factories import (
117
BranchFactory,
128
CommitWithReportFactory,
9+
OwnerFactory,
1310
PullFactory,
1411
RepositoryFactory,
1512
)
1613

14+
from api.internal.commit.serializers import CommitTotalsSerializer
15+
from codecov.tests.base_test import InternalAPITest
16+
1717

1818
def build_commits(client):
1919
"""
@@ -46,7 +46,7 @@ def build_commits(client):
4646
return repo, commit_base, commit_head
4747

4848

49-
@patch("services.archive.ArchiveService.read_chunks", lambda obj, sha: "")
49+
@patch("shared.api_archive.archive.ArchiveService.read_chunks", lambda obj, sha: "")
5050
@patch(
5151
"api.shared.repo.repository_accessors.RepoAccessors.get_repo_permissions",
5252
lambda self, repo, user: (True, True),

api/internal/tests/views/test_account_viewset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
from shared.django_apps.codecov_auth.tests.factories import (
1212
AccountFactory,
1313
InvoiceBillingFactory,
14+
OwnerFactory,
15+
UserFactory,
1416
)
1517
from stripe import StripeError
1618

1719
from api.internal.tests.test_utils import GetAdminProviderAdapter
1820
from codecov_auth.models import Service
19-
from codecov_auth.tests.factories import OwnerFactory, UserFactory
2021
from plan.constants import PlanName, TrialStatus
2122
from utils.test_utils import APIClient
2223

0 commit comments

Comments
 (0)