Skip to content

Commit

Permalink
[fix] Remove coverage offset check for comparison reports (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvinnakota-codecov authored Aug 29, 2024
1 parent 4a389f0 commit cb88548
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 101 deletions.
43 changes: 0 additions & 43 deletions api/internal/tests/views/test_compare_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,46 +466,3 @@ def test_pull_request_pseudo_comparison_can_update_base_report(

assert response.status_code == status.HTTP_200_OK
assert response.data["files"] == self.expected_files

@patch("redis.Redis.get", lambda self, key: None)
@patch("redis.Redis.set", lambda self, key, val, ex: None)
@patch(
"services.comparison.PullRequestComparison.pseudo_diff_adjusts_tracked_lines",
new_callable=PropertyMock,
)
@patch(
"services.comparison.PullRequestComparison.allow_coverage_offsets",
new_callable=PropertyMock,
)
@patch(
"services.comparison.PullRequestComparison.update_base_report_with_pseudo_diff"
)
def test_pull_request_pseudo_comparison_returns_error_if_coverage_offsets_not_allowed(
self,
update_base_report_mock,
allow_coverage_offsets_mock,
pseudo_diff_adjusts_tracked_lines_mock,
adapter_mock,
base_report_mock,
head_report_mock,
):
adapter_mock.return_value = self.mocked_compare_adapter
base_report_mock.return_value = self.base_report
head_report_mock.return_value = self.head_report

pseudo_diff_adjusts_tracked_lines_mock.return_value = True
allow_coverage_offsets_mock.return_value = False

response = self._get_comparison(
query_params={
"pullid": PullFactory(
base=self.base.commitid,
head=self.head.commitid,
compared_to=self.base.commitid,
pullid=2,
repository=self.repo,
).pullid
}
)

assert response.status_code == status.HTTP_400_BAD_REQUEST
43 changes: 0 additions & 43 deletions api/public/v2/tests/test_api_compare_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,49 +667,6 @@ def test_pull_request_pseudo_comparison_can_update_base_report(
assert response.status_code == status.HTTP_200_OK
assert response.data["files"] == self.expected_files

@patch("redis.Redis.get", lambda self, key: None)
@patch("redis.Redis.set", lambda self, key, val, ex: None)
@patch(
"services.comparison.PullRequestComparison.pseudo_diff_adjusts_tracked_lines",
new_callable=PropertyMock,
)
@patch(
"services.comparison.PullRequestComparison.allow_coverage_offsets",
new_callable=PropertyMock,
)
@patch(
"services.comparison.PullRequestComparison.update_base_report_with_pseudo_diff"
)
def test_pull_request_pseudo_comparison_returns_error_if_coverage_offsets_not_allowed(
self,
update_base_report_mock,
allow_coverage_offsets_mock,
pseudo_diff_adjusts_tracked_lines_mock,
adapter_mock,
base_report_mock,
head_report_mock,
):
adapter_mock.return_value = self.mocked_compare_adapter
base_report_mock.return_value = self.base_report
head_report_mock.return_value = self.head_report

pseudo_diff_adjusts_tracked_lines_mock.return_value = True
allow_coverage_offsets_mock.return_value = False

response = self._get_comparison(
query_params={
"pullid": PullFactory(
base=self.base.commitid,
head=self.head.commitid,
compared_to=self.base.commitid,
pullid=2,
repository=self.repo,
).pullid
}
)

assert response.status_code == status.HTTP_400_BAD_REQUEST

def test_flags_comparison(self, adapter_mock, base_report_mock, head_report_mock):
adapter_mock.return_value = self.mocked_compare_adapter
base_report_mock.return_value = self.base_report
Expand Down
17 changes: 2 additions & 15 deletions api/shared/compare/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,10 @@ def retrieve(self, request, *args, **kwargs):
comparison = self.get_object()

# Some checks here for pseudo-comparisons. Basically, when pseudo-comparing,
# we sometimes might need to tweak the base report if the user allows us to
# in their yaml, or raise an error if not.
# we sometimes might need to tweak the base report
if isinstance(comparison, PullRequestComparison):
if (
comparison.pseudo_diff_adjusts_tracked_lines
and comparison.allow_coverage_offsets
):
if comparison.pseudo_diff_adjusts_tracked_lines:
comparison.update_base_report_with_pseudo_diff()
elif comparison.pseudo_diff_adjusts_tracked_lines:
return Response(
data={
"detail": "Changes found in between %.7s...%.7s (pseudo...base) "
"which prevent comparing this pull request."
% (comparison.pull.compared_to, comparison.pull.base)
},
status=400,
)
serializer = self.get_serializer(comparison)

try:
Expand Down

0 comments on commit cb88548

Please sign in to comment.