From 65bdebea35f2ab3c9c8b0f8a8b0a9a577a36bee2 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 19 Nov 2018 20:57:19 -0800 Subject: better DOI registrar harvesters --- python/tests/harvest_state.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 python/tests/harvest_state.py (limited to 'python/tests') diff --git a/python/tests/harvest_state.py b/python/tests/harvest_state.py new file mode 100644 index 00000000..85cd2c99 --- /dev/null +++ b/python/tests/harvest_state.py @@ -0,0 +1,40 @@ + +import json +import pytest +import datetime +from fatcat_tools.harvest import * + + +def test_harvest_state(): + + today = datetime.datetime.utcnow().date() + + hs = HarvestState(catchup_days=5) + assert max(hs.to_process) < today + assert len(hs.to_process) is 5 + + for d in list(hs.to_process): + hs.complete(d) + + assert hs.next() is None + + hs = HarvestState( + start_date=datetime.date(2000,1,1), + end_date=datetime.date(2000,1,3), + ) + assert len(hs.to_process) is 3 + hs = HarvestState( + start_date=datetime.date(2000,1,29), + end_date=datetime.date(2000,2,2), + ) + assert len(hs.to_process) is 5 + + hs = HarvestState(catchup_days=0) + assert hs.next() is None + hs.enqueue_period( + start_date=datetime.date(2000,1,1), + end_date=datetime.date(2000,1,3), + ) + assert len(hs.to_process) is 3 + hs.update('{"completed-date": "2000-01-02"}') + assert len(hs.to_process) is 2 -- cgit v1.2.3