Skip to content

Commit

Permalink
Fix notifier counts for single checks (#152)
Browse files Browse the repository at this point in the history
For those checks that only have one check_ method, the current code didn't show up correctly the number of errors/warnings correctly.
  • Loading branch information
cletomartin authored Feb 14, 2023
1 parent 513ae76 commit 830597d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [1.24.1](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.24.1)

- [FIXED] Number of errors/warnings shown correctly for single checks.

# [1.24.0](https://github.com/ComplianceAsCode/auditree-framework/releases/tag/v1.24.0)

- [FIXED] Update pre-commit dependencies.
Expand Down
2 changes: 1 addition & 1 deletion compliance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.
"""Compliance automation package."""

__version__ = "1.24.0"
__version__ = "1.24.1"
22 changes: 6 additions & 16 deletions compliance/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ def messages(self):
test_obj = test_desc["test"].test
method_name = parse_test_id(test_id)["method"]

msg_method = "get_notification_message"
if len(test_obj.tests) > 1:
candidate = method_name.replace("test_", "msg_", 1)
if hasattr(test_obj, candidate):
msg_method = candidate

msg_method = "get_notification_message" # default notification method
candidate = method_name.replace("test_", "msg_", 1)
if hasattr(test_obj, candidate):
msg_method = candidate
# set body to None if the notification function hasn't been
# defined or if it returns None.
# use a predefined error message for error status.
Expand All @@ -96,19 +94,11 @@ def messages(self):
if msg and "subtitle" in msg and msg["subtitle"]:
title += f' - {msg["subtitle"]}'

failure_count = 0
if msg and test_obj.failures:
failure_count = test_obj.failures_count()

warning_count = 0
if msg and test_obj.warnings:
warning_count = test_obj.warnings_count()

msg = {
"title": title,
"body": body,
"failure_count": failure_count,
"warning_count": warning_count,
"failure_count": test_obj.failures_count(),
"warning_count": test_obj.warnings_count(),
}
yield test_id, test_desc, msg

Expand Down
2 changes: 1 addition & 1 deletion demo/demo_examples/checks/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_members_is_not_empty(self, org):
if not members:
self.add_failures(org, "There is nobody!")
elif len(members) < 5:
self.add_warnings(org, "There are people int there, but less than 5!")
self.add_warnings(org, "There are people in there, but less than 5!")

def get_reports(self):
"""Return GitHub report name."""
Expand Down
4 changes: 2 additions & 2 deletions doc-source/notifiers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ system is that each ``test_`` can generate a short notification that has the
following components:

**NOTE:** When configuring notifiers, you should be aware of the
possibilitythat notifications may contain sensitive information that can be
sent to less trusted stores like Slack or public git issue trackers. So be
possibility that notifications may contain sensitive information that can be
sent to less trusted stores like Slack or public git issue trackers. So be
mindful of check notification content as well as the nature of the forum
you intend to send these notifications to.

Expand Down
2 changes: 1 addition & 1 deletion test/t_compliance/t_controls/test_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_as_dict_immutability(self):
"""Ensure that control content cannot be changed through as_dict."""
with self.assertRaises(AttributeError) as ar:
self.cd.as_dict = {"foo": "bar"}
self.assertEqual(str(ar.exception), "can't set attribute")
self.assertTrue(str(ar.exception).startswith("can't set attribute"))
controls_copy = self.cd.as_dict
self.assertEqual(controls_copy, self.cd.as_dict)
controls_copy.update({"foo": "bar"})
Expand Down

0 comments on commit 830597d

Please sign in to comment.