From 2a997eabdb38dc775142407af5ff49feb1ff1089 Mon Sep 17 00:00:00 2001 From: lemon24 Date: Wed, 19 Jun 2024 22:54:20 +0300 Subject: [PATCH] Test set update interval up/down. #332 --- tests/test_reader.py | 53 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/tests/test_reader.py b/tests/test_reader.py index 974df72c..643d9109 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -1011,9 +1011,6 @@ def test_next_update_after(monkeypatch, now, interval, jitter, random, expected) assert next_update_after(now, interval, jitter) == expected -# FIXME: test_set_interval_up/_down - - def test_update_scheduled(reader, call_update_iter_method): reader._parser = parser = Parser() @@ -1094,6 +1091,56 @@ def test_update_scheduled_sweep(reader, scheduled, end, expected_counts): assert dict(counts) == expected_counts +def test_set_update_interval_up(reader): + reader._parser = parser = Parser() + feed = parser.feed(1) + reader.add_feed(feed) + + reader.set_tag(feed, '.reader.update', {'interval': 60}) + + reader._now = lambda: datetime(2010, 1, 1) + reader.update_feeds() + + reader.set_tag(feed, '.reader.update', {'interval': 240}) + + reader._now = lambda: datetime(2010, 1, 1, 0, 59) + assert len(list(reader.update_feeds_iter(scheduled=True))) == 0 + + reader._now = lambda: datetime(2010, 1, 1, 1) + assert len(list(reader.update_feeds_iter(scheduled=True))) == 1 + + reader._now = lambda: datetime(2010, 1, 1, 3, 59) + assert len(list(reader.update_feeds_iter(scheduled=True))) == 0 + + reader._now = lambda: datetime(2010, 1, 1, 4) + assert len(list(reader.update_feeds_iter(scheduled=True))) == 1 + + +def test_set_update_interval_down(reader): + reader._parser = parser = Parser() + feed = parser.feed(1) + reader.add_feed(feed) + + reader.set_tag(feed, '.reader.update', {'interval': 240}) + + reader._now = lambda: datetime(2010, 1, 1) + reader.update_feeds() + + reader.set_tag(feed, '.reader.update', {'interval': 60}) + + reader._now = lambda: datetime(2010, 1, 1, 3, 59) + assert len(list(reader.update_feeds_iter(scheduled=True))) == 0 + + reader._now = lambda: datetime(2010, 1, 1, 4) + assert len(list(reader.update_feeds_iter(scheduled=True))) == 1 + + reader._now = lambda: datetime(2010, 1, 1, 4, 59) + assert len(list(reader.update_feeds_iter(scheduled=True))) == 0 + + reader._now = lambda: datetime(2010, 1, 1, 5) + assert len(list(reader.update_feeds_iter(scheduled=True))) == 1 + + class FeedAction(Enum): none = object() update = object()