Exemple #1
0
def test_reputation_no_dictionary():
    jack = Character('jack', faction_name='Horde')
    response = { 'reputations' : None }

    Section.reputations(jack, response, None)

    assert jack.reputations == None
Exemple #2
0
def test_process_raiderio(mock_raiderio, mocker):
    jack = Character('jack')
    mock_response = mocker.MagicMock()

    process_raiderio(jack, mock_response)

    mock_raiderio.assert_called_once_with(jack, mock_response.json.return_value)
Exemple #3
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
Exemple #4
0
def test_dungeons_and_raids_missing_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' : [
                {'sub_categories' : [
                    {'id' : 15409, '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'
Exemple #5
0
def test_add_character_race(db_session):
    clegg = Character('clegg', race=Race('Undead'))

    db_session.add(clegg)

    assert 'Undead' == db_session.query(Race).filter_by(
        name="Undead").first().name
Exemple #6
0
def test_add_character_class(db_session):
    clegg = Character('clegg', character_class=Class('Warlock'))

    db_session.add(clegg)

    assert "Warlock" == db_session.query(Class).filter_by(
        name="Warlock").first().name
Exemple #7
0
def test_add_character_constructor(db_session):
    clegg = Character('clegg', level=120)

    db_session.add(clegg)

    assert db_session.query(Character).filter_by(name="clegg").filter_by(
        level=120).first()
Exemple #8
0
def test_no_duplicate_years(db_session_integrityerror):
    clegg = Character('clegg')
    y1 = Year(2019, clegg)
    y2 = Year(2019, clegg)

    db_session_integrityerror.add(y1)
    db_session_integrityerror.add(y2)
Exemple #9
0
def test_no_duplicate_weeks(db_session_integrityerror):
    clegg = Character('clegg')
    y = Year(2019, clegg)
    w1 = Week(2, y)
    w2 = Week(2, y)

    db_session_integrityerror.add(w1)
    db_session_integrityerror.add(w2)
Exemple #10
0
def test_serialize_gems():
    jack = Character('jack')
    jack.gems = [
        GemSlotAssociation('wrist',
            Gem(168641, 5, 'Quick Sand Spinel', 'inv_misc_gem_x4_uncommon_perfectcut_yellow', '+50 Haste')),
        GemSlotAssociation('waist',
            Gem(168645, 5, 'Masterful Name', 'inv_misc_gem_x5_uncommon_perfectcut_purple', '+50 Mastery'))
        ]

    _serialize_gems(jack)

    assert jack.gem_ids == '168641|168645'
    assert jack.gem_qualities == '5|5'
    assert jack.gem_names == 'Quick Sand Spinel|Masterful Name'
    assert jack.gem_icons == 'inv_misc_gem_x4_uncommon_perfectcut_yellow|inv_misc_gem_x5_uncommon_perfectcut_purple'
    assert jack.gem_stats == '+50 Haste|+50 Mastery'
    assert jack.gem_slots == 'wrist|waist'
Exemple #11
0
def test_process_blizzard_always_raise_exception(mock_section, mock_get_subsections):
    jack = Character('jack', lastmodified=5)
    fake_response = { 'summary' : {
        'last_login_timestamp' : 10}}
    mock_get_subsections.side_effect = KeyError()

    with pytest.raises(KeyError):
        process_blizzard(jack, fake_response, None, None, False)
Exemple #12
0
    def test_remove_old_characters(self, db_session):
        db_session.add(Character('jack',
            realm=db_session.query(Realm).filter_by(name='kiljaeden').first()))
        db_session.commit()

        self.audit._remove_old_characters(db_session)

        assert db_session.query(Character).filter_by(name='jack').first() == None
Exemple #13
0
def test_basic_info_no_media(fake_response_maker, db_session):
    jack = Character('jack')
    response = fake_response_maker()
    response['media'] = None
    Section.basic(jack, response, db_session)
    assert jack.avatar == None
    assert jack.bust == None
    assert jack.render == None
Exemple #14
0
def test_items_estimated_ilvl_non_default(default_items_response):
    jack = Character('jack')
    for i, item in enumerate(
            default_items_response['equipment']['equipped_items']):
        item['level']['value'] = 405 + i

    Section.items(jack, default_items_response, None)
    assert jack.estimated_ilvl == 412.5
Exemple #15
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
Exemple #16
0
def test_items_all_items(default_items_response):
    jack = Character('jack')
    Section.items(jack, default_items_response, None)
    for i, slot in enumerate(ITEM_SLOTS):
        assert getattr(jack, '{}_itemLevel'.format(slot)) == 405
        assert getattr(jack, '{}_id'.format(slot)) == 165822 + i
        assert getattr(jack,
                       '{}_name'.format(slot)) == 'Cowl of Tideborne Omens'
        assert getattr(jack, '{}_quality'.format(slot)) == 'Epic'
Exemple #17
0
def test_process_blizzard_last_modified_not_changed(mock_section, mock_get_subsections):
    jack = Character('jack', lastmodified=10)
    fake_response = { 'summary' : {
        'last_login_timestamp' : 10}}

    process_blizzard(jack, fake_response, None, None, False)

    mock_section.assert_not_called()
    mock_get_subsections.assert_not_called()
Exemple #18
0
def test_items_missing_id_value_is_None(default_items_response):
    jack = Character('jack')
    del default_items_response['equipment']['equipped_items'][0]['item']['id']

    Section.items(jack, default_items_response, None)
    assert jack.head_itemLevel == 405
    assert jack.head_id == None
    assert jack.head_name == 'Cowl of Tideborne Omens'
    assert jack.head_quality == 'Epic'
Exemple #19
0
def test_process_blizzard_last_modified_not_changed_force_refresh(mock_section, mock_get_subsections):
    jack = Character('jack', lastmodified=10)
    fake_response = { 'summary' : {
        'last_login_timestamp' : 10}}

    process_blizzard(jack, fake_response, None, None, True)

    mock_section.assert_called_once_with(jack, fake_response, None)
    mock_get_subsections.assert_called_once_with(None, fake_response, None, PROFILE_API_SECTIONS)
Exemple #20
0
def test_items_missing_name_value_is_None(default_items_response):
    jack = Character('jack')
    del default_items_response['equipment']['equipped_items'][0]['name']

    Section.items(jack, default_items_response, None)
    assert jack.head_itemLevel == 405
    assert jack.head_id == 165822
    assert jack.head_name == None
    assert jack.head_quality == 'Epic'
Exemple #21
0
def test_character_faction(db_session):
    horde = Faction('horde', id=1)
    clegg = Character('clegg', faction=horde)

    db_session.add(clegg)
    db_session.commit()
    db_session.close()

    assert 'horde' == db_session.query(Character).first().faction_name
Exemple #22
0
def test_pve_quests_missing_id():
    jack = Character('jack')
    response = { 'achievements' : { 'achievements' : [] },
            'quests_completed' : { 'quests' : [{'garbage' : 53436}] },
            'achievements_statistics' : { 'categories' : [ {'id' : 14807, 'sub_categories' : [ {'id' : 15409, 'statistics' : []}]}]}}

    Section.pve(jack, response, None)

    assert jack.weekly_event_done == 'FALSE'
Exemple #23
0
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)
Exemple #24
0
def test_weekly_event_done(event_id):
    jack = Character('jack')
    response = { 'achievements' : { 'achievements' : [] },
            'quests_completed' : { 'quests' : [{'id' : event_id}] },
            'achievements_statistics' : { 'categories' : [ {'id' : 14807, 'sub_categories' : [ {'id' : 15409, 'statistics' : []}]}]}}

    Section.pve(jack, response, None)

    assert jack.weekly_event_done == 'TRUE'
Exemple #25
0
def test_professions_clear_old_data():
    jack = Character('jack')
    response = {
        'professions': {
            'primary': [{
                'id': 182,
                'name': "Herbalism",
                'icon': 'trade_herbalism',
                'rank': 150,
                'max': 300
            }, {
                'id': 186,
                'name': "Mining",
                'icon': 'inv_pick_02',
                'rank': 122,
                'max': 300
            }],
            'secondary': [{
                'id': 356,
                'name': "Fishing",
                'icon': 'trade_fishing',
                'rank': 0,
                'max': 300
            }, {
                'id': 185,
                'name': "Cooking",
                'icon': 'inv_misc_food_15',
                'rank': 0,
                'max': 300
            }, {
                'id': 794,
                'name': "Archaeology",
                'icon': 'trade_archaeology',
                'rank': 0,
                'max': 950
            }]
        }
    }

    jack.primary1_name = 'Tailoring'
    jack.primary1_icon = 'trade_tailoring'
    jack.primary1_classic_level = 1
    jack.priamry1_classic_max = 300
    jack.primary1_burning_crusade_level = 1
    jack.priamry1_burning_crusade_max = 75

    Section.professions(jack, response)

    assert jack.primary1_name == 'Herbalism'
    assert jack.primary1_icon == 'trade_herbalism'
    assert jack.primary1_classic_level == 150
    assert jack.primary1_classic_max == 300
    assert jack.primary1_burning_crusade_level == None
    assert jack.primary1_burning_crusade_max == None
Exemple #26
0
def test_basic_info_render_old(fake_response_maker, db_session):
    jack = Character('jack')
    response = fake_response_maker(render='realm1/96/184987488-main.jpg')
    response['media'] = {
        'avatar_url': 'avatar_url',
        'bust_url': 'bust_url',
        'render_url': 'realm1/96/184987488-main.jpg'
    }
    Section.basic(jack, response, db_session)
    assert jack.render == 'realm1/96/184987488-main.jpg'
Exemple #27
0
def test_audit_item_missing(mock_is_off_hand_weapon, mock_is_primary_slot):
    jack = Character('jack')
    response = {'equipment': {'equipped_items': []}}

    Section.audit(jack, response, None)

    assert jack.finger_1_enchant_id == None
    assert jack.finger_1_enchant_quality == 0
    assert jack.finger_1_enchant_name == 'None'
    assert jack.finger_1_enchant_description == None
Exemple #28
0
def test_world_quests_total():
    jack = Character('jack')
    response = { 'achievements' : { 'achievements' : [
                {'id' : 11127, 'criteria' : {'child_criteria' : [{'amount' : 20}]}}]},
            'quests_completed' : { 'quests' : [] },
            'achievements_statistics' : { 'categories' : [ {'id' : 14807, 'sub_categories' : [ {'id' : 15409, 'statistics' : []}]}]}}

    Section.pve(jack, response, None)

    assert jack.world_quests_total == 20
Exemple #29
0
def test_items_missing_ilevel_is_None(default_items_response):
    jack = Character('jack')
    del default_items_response['equipment']['equipped_items'][0]['level']

    Section.items(jack, default_items_response, None)
    assert jack.head_itemLevel == None
    assert jack.head_id == 165822
    assert jack.head_name == 'Cowl of Tideborne Omens'
    assert jack.head_quality == 'Epic'
    assert jack.estimated_ilvl == 379.6875
Exemple #30
0
def test_world_quests_not_present_zero():
    # Necessary since world quests are part of snapshots
    jack = Character('jack')
    response = { 'achievements' : { 'achievements' : [] },
            'quests_completed' : { 'quests' : [] },
            'achievements_statistics' : { 'categories' : [ {'id' : 14807, 'sub_categories' : [ {'id' : 15409, 'statistics' : []}]}]}}

    Section.pve(jack, response, None)

    assert jack.world_quests_total == 0