Beispiel #1
0
def test_fill_missing_snapshots():
    jack = Character('jack', realm=Realm('kiljaeden', Region('us')))
    jack.snapshots[2017] = {}
    jack.snapshots[2017][52] = Snapshot()
    jack.snapshots[2019] = {}
    jack.snapshots[2019][1] = Snapshot()
    jack.snapshots[2019][3] = Snapshot()

    jack.snapshots[2017][52].world_quests = 10
    jack.snapshots[2019][1].world_quests = 100
    jack.snapshots[2019][3].world_quests = 110

    jack.snapshots[2017][52].dungeons = 5
    jack.snapshots[2019][1].dungeons = 45
    jack.snapshots[2019][3].dungeons = 50

    jack.snapshots[2017][52].highest_mplus = 3
    # jack.snapshots[2019][1].highest_mplus = None
    jack.snapshots[2019][3].highest_mplus = 10

    _fill_missing_snapshots(jack)

    assert 2018 in jack.snapshots
    assert 52 == len(jack.snapshots[2018])

    for week,snapshot in jack.snapshots[2018].items():
        assert snapshot.world_quests == 10, "World Quests wrong on week {}".format(week)
        assert snapshot.dungeons == 5, "Dungeons wrong on week {}".format(week)
        assert snapshot.highest_mplus == None, "Mplus wrong on week {}".format(week)

    assert jack.snapshots[2019][2].world_quests == 100
    assert jack.snapshots[2019][2].dungeons == 45
    assert jack.snapshots[2019][2].highest_mplus == None
Beispiel #2
0
def test_add_snapshots_to_character(db_session):
    clegg = Character(name='clegg')
    s1 = Snapshot()
    s1.world_quests = 10
    s1.dungeons = 20
    clegg.snapshots[2019] = {}
    clegg.snapshots[2019][3] = s1

    db_session.add(clegg)

    assert s1 == db_session.query(Snapshot)\
                                .join(Week).filter_by(week=3)\
                                .join(Year).filter_by(year=2019)\
                                .join(Character).filter_by(name='clegg').first()
Beispiel #3
0
def test_get_snapshots_snapshot_invalid_leave_as_none():
    jack = Character('jack', realm=Realm('kiljaeden', Region('us')))
    jack.snapshots = { 2019 : { 32 : Snapshot() } }
    # Values that should not be None are None. totals, snapshot values, etc.
    now = datetime.datetime(2019, 8, 7)
    Utility.set_refresh_timestamp(now)

    _get_snapshots(jack)

    assert jack.world_quests_weekly == None
    assert jack.dungeons_weekly == None
Beispiel #4
0
def test_update_snapshot_fill_missing_not_on_existing_week(mocker):
    mock_fill_missing_snapshots = mocker.patch('altaudit.processing._fill_missing_snapshots')
    clegg = Character('clegg', realm=Realm('kiljaeden', Region('us')))
    now = datetime.datetime(2019, 8, 5)
    clegg.snapshots[2019] = { 31 : Snapshot() }

    Utility.set_refresh_timestamp(now)

    update_snapshots(clegg)

    mock_fill_missing_snapshots.assert_not_called()
Beispiel #5
0
def test_update_snapshot_fill_missing_on_new_week(mocker):
    mock_fill_missing_snapshots = mocker.patch('altaudit.processing._fill_missing_snapshots')
    clegg = Character('clegg', realm=Realm('kiljaeden', Region('us')))
    now = datetime.datetime(2019, 8, 5)
    clegg.snapshots[2019] = { 30 : Snapshot() }
    clegg.world_quests_total = 0
    clegg.dungeons_total = 0

    Utility.set_refresh_timestamp(now)

    update_snapshots(clegg)

    mock_fill_missing_snapshots.assert_called_once_with(clegg)
Beispiel #6
0
def test_get_snapshots_negative_dungeons():
    jack = Character('jack', realm=Realm('kiljaeden', Region('us')))
    jack.snapshots = { 2019 : { 32 : Snapshot() } }
    jack.snapshots[2019][32].world_quests = 300
    jack.snapshots[2019][32].dungeons = 20
    jack.world_quests_total = 320
    jack.dungeons_total = 18
    now = datetime.datetime(2019, 8, 7)
    Utility.set_refresh_timestamp(now)

    _get_snapshots(jack)

    assert jack.dungeons_weekly == 0
    assert jack.snapshots[2019][32].dungeons == 18
Beispiel #7
0
def test_snapshot_default_values(db_session):
    clegg = Character(name='clegg')

    db_session.add(clegg)
    db_session.commit()

    clegg.snapshots[2019] = {}
    clegg.snapshots[2019][3] = Snapshot()

    db_session.flush()
    snapshot = clegg.snapshots[2019][3]

    assert snapshot.world_quests == 0
    assert snapshot.dungeons == 0
    assert snapshot.highest_mplus == None
Beispiel #8
0
def test_update_snapshot_capture_existing_totals():
    clegg = Character('clegg', realm=Realm('kiljaeden', Region('us')))
    now = datetime.datetime(2019, 8, 5)
    clegg.world_quests_total = 300
    clegg.dungeons_total = 40
    clegg.mplus_weekly_highest = 13
    clegg.snapshots[2019] = { 30 : Snapshot() }

    Utility.set_refresh_timestamp(now)

    update_snapshots(clegg)

    assert clegg.snapshots[2019][31].world_quests == 300
    assert clegg.snapshots[2019][31].dungeons == 40
    assert clegg.snapshots[2019][31].highest_mplus == None
    assert clegg.snapshots[2019][30].highest_mplus == 13
Beispiel #9
0
def test_update_snapshot_no_overwrite_existing():
    clegg = Character('clegg', realm=Realm('kiljaeden', Region('us')))
    now = datetime.datetime(2019, 8, 5)
    clegg.snapshots[2019] = {}
    clegg.snapshots[2019][31] = Snapshot()
    clegg.snapshots[2019][31].world_quests = 5
    clegg.snapshots[2019][31].dungeons = 10
    clegg.snapshots[2019][31].highest_mplus = 13

    Utility.set_refresh_timestamp(now)

    update_snapshots(clegg)

    assert clegg.snapshots[2019][31].world_quests == 5
    assert clegg.snapshots[2019][31].dungeons == 10
    assert clegg.snapshots[2019][31].highest_mplus == 13
Beispiel #10
0
def test_no_duplicate_snapshots(db_session_integrityerror):
    clegg = Character('clegg')
    y = Year(2019, clegg)
    w = Week(2, y)
    s1 = Snapshot()
    s2 = Snapshot()
    s1.week = w
    s2.week = w

    db_session_integrityerror.add(s1)
    db_session_integrityerror.add(s2)
Beispiel #11
0
def test_get_historical_data():
    jack = Character('jack', realm=Realm('kiljaeden', Region('us')))
    jack.snapshots[2019] = {}
    jack.snapshots[2019][52] = Snapshot()
    jack.snapshots[2019][50] = Snapshot()
    jack.snapshots[2019][51] = Snapshot()
    jack.snapshots[2018] = {}
    jack.snapshots[2018][52] = Snapshot()
    jack.snapshots[2020] = {}
    jack.snapshots[2020][2] = Snapshot()
    jack.snapshots[2020][1] = Snapshot()

    jack.snapshots[2018][52].world_quests = 20
    jack.snapshots[2019][50].world_quests = 25
    jack.snapshots[2019][51].world_quests = 40
    jack.snapshots[2019][52].world_quests = 50
    jack.snapshots[2020][1].world_quests = 75
    jack.snapshots[2020][2].world_quests = 100

    jack.snapshots[2018][52].dungeons = 100
    jack.snapshots[2019][50].dungeons = 110
    jack.snapshots[2019][51].dungeons = 120
    jack.snapshots[2019][52].dungeons = 130
    jack.snapshots[2020][1].dungeons = 140
    jack.snapshots[2020][2].dungeons = 170

    jack.snapshots[2018][52].highest_mplus = 8
    jack.snapshots[2019][50].highest_mplus = 12
    jack.snapshots[2019][51].highest_mplus = 3
    # jack.snapshots[2019][52].highest_mplus = None
    jack.snapshots[2020][1].highest_mplus = 13
    # jack.snapshots[2020][2].highest_mplus = None

    _get_historical_data(jack)

    assert jack.historic_world_quests_done == "25|25|10|15|5"
    assert jack.historic_dungeons_done == "30|10|10|10|10"
    assert jack.historic_mplus_done == "13|0|3|12|8"