aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests/harvest_state.py
blob: 8b7deba66a2b57adfa84e2ea501fc6bd1d24f902 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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) == 5

    for d in list(hs.to_process):
        hs.complete(d)

    assert hs.next_span() is None

    hs = HarvestState(
        start_date=datetime.date(2000,1,1),
        end_date=datetime.date(2000,1,3),
    )
    assert len(hs.to_process) == 3
    hs = HarvestState(
        start_date=datetime.date(2000,1,29),
        end_date=datetime.date(2000,2,2),
    )
    assert len(hs.to_process) == 5

    hs = HarvestState(catchup_days=0)
    assert hs.next_span() is None
    hs.enqueue_period(
        start_date=datetime.date(2000,1,1),
        end_date=datetime.date(2000,1,3),
    )
    assert len(hs.to_process) == 3
    hs.update('{"completed-date": "2000-01-02"}')
    assert len(hs.to_process) == 2