示例#1
0
def test_delete_outdated_data(freezer, caplog):
    # --- make batch 1 of visits (to be deleted):
    freezer.move_to("2020-10-01T12:00")
    artm.make_user_rooms_seats_visits(seat_last="r1s5", visitsN=25)
    assert arm.Visit.objects.count() == 2 * 25
    # --- make batch 2 of visits (status_3g just to be deleted):
    freezer.move_to("2020-10-30T11:00")
    artm.make_user_rooms_seats_visits(seat_last="r1s4", visitsN=1)
    assert arm.Visit.objects.count() == 2 * (25 + 1)
    # --- make batch 3 of visits (status_3g just still to be kept):
    freezer.move_to("2020-10-30T13:00")
    artm.make_user_rooms_seats_visits(seat_last="r1s4", visitsN=1)
    assert arm.Visit.objects.count() == 2 * (25 + 1 + 1)
    # --- make later batch 4:
    freezer.move_to("2020-11-01T12:00")
    artm.make_user_rooms_seats_visits(seat_last="r2s2", visitsN=33)
    assert arm.Room.objects.count() == 2 * (1 + 1 + 1 + 1)
    assert arm.Visit.objects.count() == 2 * (25 + 1 + 1 + 33)
    # --- delete batch 1 and check:
    freezer.move_to("2020-11-01T12:01")
    # delete batch 1, delete status_3g from batch 2, keep everything else:
    delete_outdated_data.Command().handle()
    assert arm.Visit.objects.count() == 2 * (1 + 1 + 33)
    assert arm.Visit.objects.filter(status_3g=arm.G_UNKNOWN).count() == 2 * 1
    msg = [rec.msg for rec in caplog.records]
    assert "deleting 50 " in msg[0]
    assert "(of 120 existing)" in msg[0]
    assert "cleansing 2 " in msg[1]
    assert "(of 70 existing)" in msg[1]
示例#2
0
def test_collect_visitgroups():
    artm.make_user_rooms_seats_visits("r2s2", visitsN=4)
    targetvisit = arm.Visit.objects.filter(
        pk=arm.Visit.objects.first().pk)  # type: ignore
    vrows = are._as_vgrouprows(are.collect_visitgroups(targetvisit))
    result = set()
    for vr in vrows:
        vrowstr = f"{vr.familyname}: {vr.room}.{vr.seat}{vr.distance}"  # type: ignore
        result.add(vrowstr)
    should = set([
        "Visitor0: room1.r1s1  0.0m",
        "Visitor1: room1.r1s2  1.4m",
        "Visitor2: room1.r2s1  1.4m",
        "Visitor3: room1.r2s2  2.0m",
    ])
    assert result == should
示例#3
0
def test_delete_outdated_data(freezer, caplog):
    # --- make batch 1 of visits:
    freezer.move_to("2020-10-01")
    artm.make_user_rooms_seats_visits(seat_last="r1s5", visitsN=25)
    assert arm.Visit.objects.count() == 2 * 25
    # --- make later batch 2:
    freezer.move_to("2020-11-01")
    artm.make_user_rooms_seats_visits(seat_last="r2s2", visitsN=33)
    assert arm.Room.objects.count() == 2 + 2
    assert arm.Visit.objects.count() == 2 * (25 + 33)
    # --- delete batch 1 and check:
    delete_outdated_data.Command().handle()  # should delete batch 1
    assert arm.Visit.objects.count() == 2 * 33
    msg = caplog.records[0].msg
    assert "deleting 50 " in msg
    assert "(of 116 existing)" in msg
示例#4
0
def test_collect_visitgroups():
    artm.make_user_rooms_seats_visits("r2s2", visitsN=4)
    targetvisit = arm.Visit.objects.filter(
        pk=arm.Visit.objects.first().pk)  # type: ignore
    vrows = are._as_vgrouprows(are.collect_visitgroups(targetvisit))
    assert ("geimpft" in vrows[0].status_3g
            if settings.USE_STATUS_3G_FIELD  # type: ignore
            else "unbekannt" in vrows[0].status_3g)  # type: ignore
    result = set()
    for vr in vrows:
        vrowstr = f"{vr.familyname}: {vr.room}.{vr.seat} {vr.distance}"  # type: ignore
        result.add(vrowstr)
    should = set([  # see artm for row_dist/seat_dist
        "Visitor0: room1.r1s1   0.0m",
        "Visitor1: room1.r1s2   0.7m",
        "Visitor2: room1.r2s1   1.2m",
        "Visitor3: room1.r2s2   1.4m",
    ])
    assert result == should