Skip to content

Commit

Permalink
Merge pull request #452 from rsnyman/fix-418
Browse files Browse the repository at this point in the history
Check if values are None and default to 0 if they are (fix #418)
  • Loading branch information
rsnyman authored Mar 31, 2023
2 parents 396994d + 69aeb57 commit 46210b3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
49 changes: 49 additions & 0 deletions backend/ibutsu_server/test/test_widgets_result_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from unittest.mock import MagicMock
from unittest.mock import Mock
from unittest.mock import patch

from ibutsu_server.db.models import Run
from ibutsu_server.widgets.result_summary import get_result_summary


@patch("ibutsu_server.widgets.result_summary.apply_filters")
@patch("ibutsu_server.widgets.result_summary.session")
def test_get_result_summary(mocked_session: Mock, mocked_apply_filters: Mock):
"""Test the get_result_summary() function"""
# GIVEN: Some mocked objects and data
mocked_apply_filters.side_effect = lambda query, filters, run: query
mocked_query = MagicMock()
mocked_query.all.return_value = [
# errors, skips, failures, tests, xfailures, xpasses
(0, 0, 0, 17, 0, 0),
(None, 0, 0, 3, 0, 0),
(0, 1, None, 7, 0, 0),
(1, None, 0, 1, 0, 0),
(2, 5, 3, 88, None, None),
(0, 0, 0, None, 0, 0),
]
mocked_session.query.return_value = mocked_query

# WHEN: get_result_summary() is called
summary = get_result_summary(
"prodTestSuite", "prod", "prodTestSuite", "d13d1301-a663-4b26-a9e5-77364e420c0c"
)

# THEN: We should get the correct summary back, and the correct calls should have been made
expected_filters = [
"source=prodTestSuite",
"env=prod",
"metadata.jenkins.job_name=prodTestSuite",
"project_id=d13d1301-a663-4b26-a9e5-77364e420c0c",
]
expected_summary = {
"error": 3,
"skipped": 6,
"failed": 3,
"passed": 104,
"total": 116,
"xfailed": 0,
"xpassed": 0,
}
assert summary == expected_summary
mocked_apply_filters.assert_called_once_with(mocked_query, expected_filters, Run)
10 changes: 8 additions & 2 deletions backend/ibutsu_server/widgets/result_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ def get_result_summary(source=None, env=None, job_name=None, project=None, addit

# parse the data
for error, skipped, failed, total, xfailed, xpassed in query_data:
error = error or 0
skipped = skipped or 0
failed = failed or 0
total = total or 0
xfailed = xfailed or 0
xpassed = xpassed or 0
summary["error"] += error
summary["skipped"] += skipped
summary["failed"] += failed
summary["total"] += total
summary["xfailed"] += xfailed or 0.0
summary["xpassed"] += xpassed or 0.0
summary["xfailed"] += xfailed
summary["xpassed"] += xpassed
summary["passed"] += total - (error + skipped + failed + xpassed + xfailed)

return summary

0 comments on commit 46210b3

Please sign in to comment.