def test_remove_empty_regions(self, db_session): db_session.add(Region('nz')) db_session.commit() self.audit._remove_empty_regions(db_session) assert None == db_session.query(Region).filter_by(name='nz').first()
def test_add_region(db_session): us = Region(name='US') db_session.add(us) assert us == db_session.query(Region).filter(Region.name=='US').first() db_session.delete(us)
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
def test_delete_region_cascade_realms(db_session): us = Region('us') eu = Region('eu') db_session.add(us) db_session.add(eu) kj = Realm('kiljaeden', us) lb = Realm('lightbringer', us) ad = Realm('argentdawn', eu) db_session.commit() db_session.delete(us) assert [ad] == db_session.query(Realm).all()
def test_no_duplicate_realms(db_session_integrityerror): us = Region('us') kj = Realm('kiljaeden', us) okj = Realm('kiljaeden', us) db_session_integrityerror.add(kj) db_session_integrityerror.add(okj)
def test_dungeons_and_raids_missing_stat_quantity(bfa_raids): jack = Character('jack', realm=Realm('kiljaeden', Region('us'))) now = datetime.datetime(2019, 8, 8) bad_bfa_raids = copy.deepcopy(bfa_raids) del bad_bfa_raids[1]['quantity'] response = { 'achievements' : { 'achievements' : [] }, 'quests_completed' : { 'quests' : [] }, 'achievements_statistics' : { 'categories' : [ {'id' : 14807, 'sub_categories' : [ {'id' : 15409, 'statistics' : [ {'id' : 14392}, {'id' : 14395, 'quantity' : 8}, {'id' : 14404, 'quantity' : 9}, {'id' : 14389, 'quantity' : 10}, {'id' : 14398, 'quantity' : 11}, {'id' : 14205, 'quantity' : 12}, {'id' : 14401, 'quantity' : 13}, {'id' : 14407, 'quantity' : 14}, *bad_bfa_raids]}]}]}} Utility.set_refresh_timestamp(now) Section.pve(jack, response, None) assert jack.dungeons_total == 77 assert jack.dungeons_each_total == "Halls of Atonement+0|Mists of Tirna Scithe+8|The Necrotic Wake+9|De Other Side+10|Plaguefall+11|Sanguine Depths+12|Spires of Ascension+13|Theater of Pain+14" assert jack.raids_raid_finder == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_raid_finder_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_normal == '0|1|1|1|1|1|1|1|1|1' assert jack.raids_normal_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_heroic == '8|7|6|5|4|3|2|1|9|8' assert jack.raids_heroic_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_mythic == '1|0|0|0|0|0|0|0|9|1' assert jack.raids_mythic_weekly == '0|0|0|0|0|0|0|0|0|0'
def test_dungeons_and_raids_missing_sub_categories_id(bfa_raids): jack = Character('jack', realm=Realm('kiljaeden', Region('us'))) now = datetime.datetime(2019, 8, 8) response = { 'achievements' : { 'achievements' : [] }, 'quests_completed' : { 'quests' : [] }, 'achievements_statistics' : { 'categories' : [ {'id' : 14807, 'sub_categories' : [ {'statistics' : [ {'id' : 12749, 'quantity' : 4}, {'id' : 12752, 'quantity' : 5}, {'id' : 12763, 'quantity' : 6}, {'id' : 12779, 'quantity' : 7}, {'id' : 12768, 'quantity' : 8}, {'id' : 12773, 'quantity' : 9}, {'id' : 12776, 'quantity' : 10}, {'id' : 12782, 'quantity' : 11}, {'id' : 12745, 'quantity' : 12}, {'id' : 12785, 'quantity' : 13}, {'id' : 13620, 'quantity' : 14}, *bfa_raids]}]}]}} Utility.set_refresh_timestamp(now) Section.pve(jack, response, None) assert jack.dungeons_total == 0 assert jack.dungeons_each_total == "Halls of Atonement+0|Mists of Tirna Scithe+0|The Necrotic Wake+0|De Other Side+0|Plaguefall+0|Sanguine Depths+0|Spires of Ascension+0|Theater of Pain+0" assert jack.raids_raid_finder == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_raid_finder_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_normal == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_normal_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_heroic == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_heroic_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_mythic == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_mythic_weekly == '0|0|0|0|0|0|0|0|0|0'
def test_no_duplicate_characters(db_session_integrityerror): us = Region('us') kj = Realm('kiljaeden', us) clegg = Character('clegg', realm=kj) oclegg = Character('clegg', realm=kj) db_session_integrityerror.add(clegg) db_session_integrityerror.add(oclegg)
def test_add_realm_region(db_session): kj = Realm('kiljaeden') us = Region(name='US') kj.region = us db_session.add(kj) assert us == db_session.query(Region).filter_by( name='US').join(Realm).filter_by(name="kiljaeden").first()
def test_update_snapshot_do_not_add_on_missing_dungeons(): clegg = Character('clegg', realm=Realm('kiljaeden', Region('us'))) now = datetime.datetime(2019, 8, 5) Utility.set_refresh_timestamp(now) clegg.world_quests_total = 0 update_snapshots(clegg) assert 2019 in clegg.snapshots assert 31 not in clegg.snapshots[2019]
def test_add_region_realm(db_session): us = Region(name='US') kj = Realm('kiljaeden') us.realms.append(kj) db_session.add(us) assert kj == db_session.query(Realm).filter_by( name="kiljaeden").join(Region).filter_by(name='US').first()
def test_delete_region_cascade_characters(db_session): us = Region('us') eu = Region('eu') db_session.add(us) db_session.add(eu) kj = Realm('kiljaeden', us) lb = Realm('lightbringer', us) ad = Realm('argentdawn', eu) clegg = Character('clegg', realm=kj) tali = Character('tali', realm=ad) db_session.commit() db_session.delete(us) assert [tali] == db_session.query(Character).all()
def test_get_snapshots_year_not_present(): jack = Character('jack', realm=Realm('kiljaeden', Region('us'))) jack.snapshots = {} 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
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
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()
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)
def test_serialzie(mocker): jack = Character('jack', realm=Realm('kiljaeden', Region('us'))) mock_serialize_gems = mocker.patch('altaudit.processing._serialize_gems') mock_get_snapshots = mocker.patch('altaudit.processing._get_snapshots') mock_get_historical_data = mocker.patch('altaudit.processing._get_historical_data') altaudit.processing.HEADERS = [ 'name', 'region_name', 'realm_slug' ] result = serialize(jack) assert result == ['jack', 'us', 'kiljaeden'] mock_serialize_gems.assert_called_once_with(jack) mock_get_snapshots.assert_called_once_with(jack) mock_get_historical_data.assert_called_once_with(jack)
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
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
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
def db(): us = Region(name='us') kj = Realm(name='kiljaeden', region=us) lb = Realm(name='lightbringer', region=us) archer = Character(name='archer', realm=kj, lastmodified=123456) rando = Character(name='rando', realm=kj, lastmodified=7891011) ray = Character(name='ray', realm=lb, lastmodified=13141516) engine = create_engine("sqlite://") Base.metadata.create_all(engine) session = sessionmaker(engine)() session.add_all([archer, rando, ray]) session.commit() session.close() yield engine Base.metadata.drop_all(engine)
def test_raids_all_boss_difficulties(bfa_raids): jack = Character('jack', realm=Realm('kiljaeden', Region('us'))) now = datetime.datetime(2019, 8, 8) response = { 'achievements' : { 'achievements' : [] }, 'quests_completed' : { 'quests' : [] }, 'achievements_statistics' : { 'categories' : [ {'id' : 14807, 'sub_categories' : [ {'id' : 15409, 'statistics' : bfa_raids}]}]}} Utility.set_refresh_timestamp(now) Section.pve(jack, response, None) assert jack.raids_raid_finder == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_raid_finder_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_normal == '1|1|1|1|1|1|1|1|1|1' assert jack.raids_normal_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_heroic == '8|7|6|5|4|3|2|1|9|8' assert jack.raids_heroic_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_mythic == '1|0|0|0|0|0|0|0|9|1' assert jack.raids_mythic_weekly == '0|0|0|0|0|0|0|0|0|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"
def test_raids_missing_last_updated_timestamp(bfa_raids): jack = Character('jack', realm=Realm('kiljaeden', Region('us'))) now = datetime.datetime(2019, 8, 8) bad_bfa_raids = copy.deepcopy(bfa_raids) entry_to_alter = next(entry for entry in bad_bfa_raids if entry['id'] == 14432) del entry_to_alter['last_updated_timestamp'] response = { 'achievements' : { 'achievements' : [] }, 'quests_completed' : { 'quests' : [] }, 'achievements_statistics' : { 'categories' : [ {'id' : 14807, 'sub_categories' : [ {'id' : 15409, 'statistics' : bad_bfa_raids}]}]}} Utility.set_refresh_timestamp(now) Section.pve(jack, response, None) assert jack.raids_raid_finder == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_raid_finder_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_normal == '1|1|1|1|1|1|1|1|1|1' assert jack.raids_normal_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_heroic == '8|7|6|5|0|3|2|1|9|8' assert jack.raids_heroic_weekly == '0|0|0|0|0|0|0|0|0|0' assert jack.raids_mythic == '1|0|0|0|0|0|0|0|9|1' assert jack.raids_mythic_weekly == '0|0|0|0|0|0|0|0|0|0'
def test_character_realm_region(db_session): us = Region('us') kj = Realm('kiljaeden', us) clegg = Character('clegg', realm=kj) assert clegg.region_name == 'us'