diff --git a/services/notification/notifiers/comment/conditions.py b/services/notification/notifiers/comment/conditions.py index 98ae7eb79..5633b9de2 100644 --- a/services/notification/notifiers/comment/conditions.py +++ b/services/notification/notifiers/comment/conditions.py @@ -154,7 +154,10 @@ async def _check_coverage_drop(comparison: ComparisonProxy) -> bool: project_status_config = read_yaml_field( comparison.comparison.current_yaml, ("coverage", "status", "project"), {} ) - threshold = Decimal(project_status_config.get("threshold", 0)) + threshold = 0 + if isinstance(project_status_config, dict): + # Project status can also be a bool value, so check is needed + threshold = Decimal(project_status_config.get("threshold", 0)) target_coverage = Decimal( comparison.project_coverage_base.report.totals.coverage ).quantize(Decimal("0.00000")) diff --git a/services/notification/notifiers/tests/unit/test_comment_conditions.py b/services/notification/notifiers/tests/unit/test_comment_conditions.py index 920c56127..393f64650 100644 --- a/services/notification/notifiers/tests/unit/test_comment_conditions.py +++ b/services/notification/notifiers/tests/unit/test_comment_conditions.py @@ -5,8 +5,10 @@ CoverageCommentRequiredChanges, CoverageCommentRequiredChangesANDGroup, ) +from shared.yaml import UserYaml from database.models.core import Repository +from services.comparison import ComparisonProxy from services.notification.notifiers.comment import CommentNotifier from services.notification.notifiers.comment.conditions import HasEnoughRequiredChanges @@ -216,3 +218,42 @@ async def test_uncovered_patch( ) == expected ) + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "comparison_name, yaml, expected", + [ + pytest.param("sample_comparison", {}, False, id="positive_change"), + pytest.param( + "sample_comparison_negative_change", + {}, + True, + id="negative_change_no_extra_config", + ), + pytest.param( + "sample_comparison_negative_change", + {"coverage": {"status": {"project": True}}}, + True, + id="negative_change_bool_config", + ), + pytest.param( + "sample_comparison_negative_change", + {"coverage": {"status": {"project": {"threshold": 10}}}}, + False, + id="negative_change_high_threshold", + ), + ], +) +async def test_coverage_drop_with_different_project_configs( + comparison_name, yaml, expected, request +): + comparison: ComparisonProxy = request.getfixturevalue(comparison_name) + comparison.comparison.current_yaml = UserYaml(yaml) + notifier = _get_notifier( + comparison.head.commit.repository, + [CoverageCommentRequiredChanges.coverage_drop.value], + ) + assert ( + await HasEnoughRequiredChanges.check_condition(notifier, comparison) == expected + )