From f5141af44051dbfa291d7d519bb5446c3532f953 Mon Sep 17 00:00:00 2001 From: jmkerr <49833159+jmkerr@users.noreply.github.com> Date: Tue, 1 Oct 2019 15:26:39 +0200 Subject: [PATCH] Fix & improve test_report_current() - Mock time so that the test result does not depend on the time of day. - Replaced all local times with UTC. --- tests/test_watson.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/test_watson.py b/tests/test_watson.py index f28e53c2..632560fb 100644 --- a/tests/test_watson.py +++ b/tests/test_watson.py @@ -795,29 +795,29 @@ def test_report(watson): watson.report(arrow.now(), arrow.now(), tags=["A"], ignore_tags=["A"]) -def test_report_current(config_dir): +def test_report_current(mock, config_dir): + mock.patch('arrow.utcnow', return_value=arrow.get(5000)) + watson = Watson( - current={'project': 'foo', 'start': arrow.now().shift(hours=-1)}, + current={'project': 'foo', 'start': 4000}, config_dir=config_dir ) - _ = watson.report( - arrow.now(), arrow.now(), current=True, projects=['foo'] - ) - report = watson.report( - arrow.now(), arrow.now(), current=True, projects=['foo'] - ) + for _ in range(2): + report = watson.report( + arrow.utcnow(), arrow.utcnow(), current=True, projects=['foo'] + ) assert len(report['projects']) == 1 assert report['projects'][0]['name'] == 'foo' - assert report['projects'][0]['time'] == pytest.approx(3600, rel=1e-2) + assert report['projects'][0]['time'] == pytest.approx(1000) report = watson.report( - arrow.now(), arrow.now(), current=False, projects=['foo'] + arrow.utcnow(), arrow.utcnow(), current=False, projects=['foo'] ) assert len(report['projects']) == 0 report = watson.report( - arrow.now(), arrow.now(), projects=['foo'] + arrow.utcnow(), arrow.utcnow(), projects=['foo'] ) assert len(report['projects']) == 0