Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop writing UploadLevelTotals #671

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
15 changes: 0 additions & 15 deletions database/tests/factories/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 1 addition & 32 deletions services/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
ReportDetails,
ReportLevelTotals,
RepositoryFlag,
UploadLevelTotals,
)
from helpers.environment import Environment, get_current_env
from helpers.exceptions import (
Expand Down Expand Up @@ -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:
Expand All @@ -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"
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
115 changes: 0 additions & 115 deletions services/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
ReportLevelTotalsFactory,
RepositoryFlagFactory,
UploadFactory,
UploadLevelTotalsFactory,
)
from helpers.exceptions import RepositoryWithoutValidBotError
from services.archive import ArchiveService
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -606,73 +578,25 @@ 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()

upload4 = UploadFactory(
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()

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