From d0fb6ee1f688b4f7ad9ad99f4ba5a3d506948be4 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Mon, 2 Sep 2024 13:53:26 +0200 Subject: [PATCH] Stop writing `UploadLevelTotals` I believe these are completely unused. They were still being created/updated though. --- database/tests/factories/core.py | 15 ---- services/report/__init__.py | 33 +-------- services/tests/test_report.py | 115 ------------------------------- 3 files changed, 1 insertion(+), 162 deletions(-) diff --git a/database/tests/factories/core.py b/database/tests/factories/core.py index a70b36c07..88dd46696 100644 --- a/database/tests/factories/core.py +++ b/database/tests/factories/core.py @@ -233,21 +233,6 @@ class Meta: created_at = datetime.now() -class UploadLevelTotalsFactory(Factory): - class Meta: - model = models.UploadLevelTotals - - upload = factory.SubFactory(UploadFactory) - branches = 0 - coverage = 0.00 - hits = 0 - lines = 0 - methods = 0 - misses = 0 - partials = 0 - files = 0 - - class RepositoryFlagFactory(Factory): class Meta: model = models.RepositoryFlag diff --git a/services/report/__init__.py b/services/report/__init__.py index 106435d22..64878a5ed 100644 --- a/services/report/__init__.py +++ b/services/report/__init__.py @@ -34,7 +34,6 @@ ReportDetails, ReportLevelTotals, RepositoryFlag, - UploadLevelTotals, ) from helpers.environment import Environment, get_current_env from helpers.exceptions import ( @@ -1076,12 +1075,6 @@ def build_report_from_raw_content( def update_upload_with_processing_result( self, upload_obj: Upload, processing_result: ProcessingResult ): - rounding: str = read_yaml_field( - self.current_yaml, ("coverage", "round"), "nearest" - ) - precision: int = read_yaml_field( - self.current_yaml, ("coverage", "precision"), 2 - ) db_session = upload_obj.get_db_session() session = processing_result.session if processing_result.error is None: @@ -1095,24 +1088,6 @@ def update_upload_with_processing_result( upload_obj.state_id = UploadState.PROCESSED.db_id upload_obj.state = "processed" upload_obj.order_number = session.id - upload_totals = upload_obj.totals - if upload_totals is None: - upload_totals = UploadLevelTotals( - upload_id=upload_obj.id, - branches=0, - coverage=0, - hits=0, - lines=0, - methods=0, - misses=0, - partials=0, - files=0, - ) - db_session.add(upload_totals) - if session.totals is not None: - upload_totals.update_from_totals( - session.totals, precision=precision, rounding=rounding - ) else: error = processing_result.error upload_obj.state = "error" @@ -1123,7 +1098,7 @@ def update_upload_with_processing_result( error_params=error.params, ) db_session.add(error_obj) - db_session.flush() + db_session.flush() @sentry_sdk.trace def save_report(self, commit: Commit, report: Report, report_code=None): @@ -1252,12 +1227,6 @@ def save_full_report( db_session.add(upload) db_session.flush() self._attach_flags_to_upload(upload, session.flags if session.flags else []) - if session.totals is not None: - upload_totals = UploadLevelTotals(upload_id=upload.id_) - db_session.add(upload_totals) - upload_totals.update_from_totals( - session.totals, precision=precision, rounding=rounding - ) return res @sentry_sdk.trace diff --git a/services/tests/test_report.py b/services/tests/test_report.py index a3a1793cc..4a098e519 100644 --- a/services/tests/test_report.py +++ b/services/tests/test_report.py @@ -18,7 +18,6 @@ ReportLevelTotalsFactory, RepositoryFlagFactory, UploadFactory, - UploadLevelTotalsFactory, ) from helpers.exceptions import RepositoryWithoutValidBotError from services.archive import ArchiveService @@ -477,18 +476,6 @@ def test_build_report_from_commit(self, dbsession, mock_storage): upload = UploadFactory(report=report, order_number=0, upload_type="upload") dbsession.add(upload) - upload_totals = UploadLevelTotalsFactory( - upload=upload, - files=3, - lines=20, - hits=17, - misses=3, - partials=0, - coverage=85.0, - branches=0, - methods=0, - ) - dbsession.add(upload_totals) dbsession.commit() dbsession.flush() @@ -524,21 +511,6 @@ def test_build_report_from_commit(self, dbsession, mock_storage): assert len(report.sessions) == 1 assert report.sessions[0].flags == [] assert report.sessions[0].session_type == SessionType.uploaded - assert report.sessions[0].totals == ReportTotals( - files=3, - lines=20, - hits=17, - misses=3, - partials=0, - coverage=Decimal("85.00"), - branches=0, - methods=0, - messages=0, - sessions=0, - complexity=0, - complexity_total=0, - diff=0, - ) # make sure report is still serializable ReportService({}).save_report(commit, report) @@ -606,54 +578,18 @@ def test_build_report_from_commit_with_flags(self, dbsession, mock_storage): report=report, flags=[flag1], order_number=0, upload_type="upload" ) dbsession.add(upload1) - upload_totals1 = UploadLevelTotalsFactory( - upload=upload1, - files=3, - lines=20, - hits=17, - misses=3, - partials=0, - coverage=85.0, - branches=0, - methods=0, - ) - dbsession.add(upload_totals1) dbsession.commit() upload2 = UploadFactory( report=report, flags=[flag1], order_number=1, upload_type="carriedforward" ) dbsession.add(upload2) - upload_totals2 = UploadLevelTotalsFactory( - upload=upload2, - files=3, - lines=20, - hits=20, - misses=0, - partials=0, - coverage=100.0, - branches=0, - methods=0, - ) - dbsession.add(upload_totals2) dbsession.commit() upload3 = UploadFactory( report=report, flags=[flag2], order_number=2, upload_type="carriedforward" ) dbsession.add(upload3) - upload_totals3 = UploadLevelTotalsFactory( - upload=upload3, - files=3, - lines=20, - hits=20, - misses=0, - partials=0, - coverage=100.0, - branches=0, - methods=0, - ) - dbsession.add(upload_totals3) dbsession.commit() dbsession.flush() @@ -661,18 +597,6 @@ def test_build_report_from_commit_with_flags(self, dbsession, mock_storage): report=report, flags=[flag3], order_number=3, upload_type="upload" ) dbsession.add(upload4) - upload_totals4 = UploadLevelTotalsFactory( - upload=upload4, - files=3, - lines=20, - hits=20, - misses=0, - partials=0, - coverage=100.0, - branches=0, - methods=0, - ) - dbsession.add(upload_totals4) dbsession.commit() dbsession.flush() @@ -719,39 +643,9 @@ def test_build_report_from_commit_with_flags(self, dbsession, mock_storage): assert len(report.sessions) == 2 assert report.sessions[0].flags == ["unit"] assert report.sessions[0].session_type == SessionType.uploaded - assert report.sessions[0].totals == ReportTotals( - files=3, - lines=20, - hits=17, - misses=3, - partials=0, - coverage=Decimal("85.00"), - branches=0, - methods=0, - messages=0, - sessions=0, - complexity=0, - complexity_total=0, - diff=0, - ) assert 1 not in report.sessions # CF w/ equivalent direct upload assert report.sessions[2].flags == ["integration"] assert report.sessions[2].session_type == SessionType.carriedforward - assert report.sessions[2].totals == ReportTotals( - files=3, - lines=20, - hits=20, - misses=0, - partials=0, - coverage=Decimal("100.00"), - branches=0, - methods=0, - messages=0, - sessions=0, - complexity=0, - complexity_total=0, - diff=0, - ) assert 3 not in report.sessions # labels flag w/ empty label set # make sure report is still serializable @@ -3576,15 +3470,6 @@ def test_save_full_report( assert len(first_upload.flags) == 1 assert first_upload.flags[0].repository == commit.repository assert first_upload.flags[0].flag_name == "unit" - assert first_upload.totals is not None - assert first_upload.totals.branches == 0 - assert first_upload.totals.coverage == Decimal("0.0") - assert first_upload.totals.hits == 0 - assert first_upload.totals.lines == 10 - assert first_upload.totals.methods == 0 - assert first_upload.totals.misses == 0 - assert first_upload.totals.partials == 0 - assert first_upload.totals.files == 2 assert first_upload.upload_extras == {} assert first_upload.upload_type == "uploaded" assert second_upload.build_code == "poli"