diff --git a/src/robusta/core/sinks/sink_base.py b/src/robusta/core/sinks/sink_base.py index 28d012f77..6c5262f3c 100644 --- a/src/robusta/core/sinks/sink_base.py +++ b/src/robusta/core/sinks/sink_base.py @@ -165,7 +165,7 @@ def stop(self): def accepts(self, finding: Finding) -> bool: return ( finding.matches(self.params.match, self.params.scope) - and any(time_slice.is_active_now for time_slice in self.time_slices) + and any(time_slice.is_active_now() for time_slice in self.time_slices) ) @abstractmethod diff --git a/tests/test_sink_timing.py b/tests/test_sink_timing.py index b11bbe5e1..01e9313a0 100644 --- a/tests/test_sink_timing.py +++ b/tests/test_sink_timing.py @@ -1,6 +1,11 @@ +from unittest.mock import Mock + import pytest from freezegun import freeze_time +from robusta.core.reporting import Finding +from robusta.core.sinks.sink_base import SinkBase +from robusta.core.sinks.sink_base_params import ActivityParams from robusta.core.sinks.timing import TimeSlice @@ -32,3 +37,32 @@ def test_invalid_days(self): def test_invalid_time(self, time): with pytest.raises(ValueError): TimeSlice([], [time], "UTC") + + +class _TestSinkBase(SinkBase): + def write_finding(self, finding: Finding, platform_enabled: bool): + pass + + def create_summary_header(self): + pass + + def _build_time_slices_from_params(self, params: ActivityParams): + # We'll construct time_slices explicitly below in TestSinkBase.test_accepts + pass + + +class TestSinkBase: + @pytest.mark.parametrize( + "days,time_intervals,expected_result", + [ + (["mon", "tue"], [("10:10", "11:05"), ("13:05", "13:50")], False), + (["Sun", "Wed"], [("13:30", "14:00"), ("19:01", "21:30")], True), + ] + ) + def test_accepts(self, days, time_intervals, expected_result): + mock_registry = Mock(get_global_config=lambda: Mock()) + sink = _TestSinkBase(registry=mock_registry, sink_params=Mock()) + sink.time_slices = [TimeSlice(days, time_intervals, "UTC")] + mock_finding = Mock(matches=Mock(return_value=True)) + with freeze_time("2012-01-01 13:45"): # this is UTC time + assert sink.accepts(mock_finding) is expected_result