예제 #1
0
def test_observation_granularity():
    ct = ContactTracer(start_time=START_TIME)
    t1 = START_TIME + timedelta(minutes=20)
    t2 = START_TIME + timedelta(hours=6)
    ct.add_observation(EPHID1, t1)
    ct.add_observation(EPHID2, t2)

    # Verify that internal representation has batch granularity
    for time in ct.observations:
        assert time % SECONDS_PER_BATCH == 0
예제 #2
0
def test_contact_tracing_retention():
    ct = ContactTracer(start_time=START_TIME)
    t1 = START_TIME + timedelta(minutes=20)
    t2 = START_TIME + timedelta(hours=6)
    ct.add_observation(EPHID1, t1)
    ct.add_observation(EPHID2, t2)
    recorded_times = ct.observations.keys()

    for _ in range(config.RETENTION_PERIOD + 1):
        ct.next_day()

    for time in recorded_times:
        assert time not in ct.observations
예제 #3
0
def test_observation_granularity_after_update():
    ct = ContactTracer(start_time=START_TIME)
    t1 = START_TIME + timedelta(minutes=20)
    t2 = START_TIME + timedelta(hours=6)
    t3 = START_TIME + timedelta(days=1, hours=6)
    ct.add_observation(EPHID1, t1)
    ct.add_observation(EPHID2, t2)
    ct.next_day()
    ct.add_observation(EPHID2, t3)

    t4 = int((START_TIME + timedelta(days=1, hours=10)).timestamp())
    release_time = (t4 // SECONDS_PER_BATCH) * SECONDS_PER_BATCH
    batch = TracingDataBatch([], release_time=release_time)
    ct.housekeeping_after_batch(batch)

    # All observations should now be at day granularity
    for time in ct.observations:
        assert time % config.SECONDS_PER_DAY == 0