Пример #1
0
def test_player_mod_stats_arrows(db):
    player = PlayerFactory()
    ModFactory(player_unit=PlayerUnitFactory(unit=UnitFactory(),
                                             player=player),
               slot=1,
               speed=30,
               primary_stat='SP')
    ModFactory(player_unit=PlayerUnitFactory(unit=UnitFactory(),
                                             player=player),
               slot=1,
               speed=25,
               primary_stat='OF')
    ModFactory(player_unit=PlayerUnitFactory(unit=UnitFactory(),
                                             player=player),
               slot=1,
               speed=12,
               primary_stat='OF')

    qs = Player.objects.filter(pk=player.pk).annotate_stats()

    assert qs.count() == 1
    assert qs[0].mod_count_speed_25 == 1
    assert qs[0].mod_count_speed_20 == 0
    assert qs[0].mod_count_speed_15 == 0
    assert qs[0].mod_count_speed_10 == 1
    assert qs[0].mod_total_speed_15plus == 25
Пример #2
0
def test_units_and_skills(db):
    unit1 = UnitFactory(skill=[])
    unit2 = UnitFactory(skill=[])
    skill1 = SkillFactory(unit=unit1, is_zeta=True)
    skill2 = SkillFactory(unit=unit1, is_zeta=False)

    assert set(Skill.objects.filter(unit=unit1)) == {skill1, skill2}
    assert set(Skill.objects.filter(unit=unit1, is_zeta=True)) == {skill1}
    assert Skill.objects.filter(unit=unit2).count() == 0
Пример #3
0
    def test_one_medal(self):
        unit = UnitFactory()
        unit2 = UnitFactory()  # a non-medaled unit
        StatMedalRuleFactory.create_batch(7, unit=unit)

        url = reverse("sqds_medals:list")
        response = self.client.get(url)

        self.assertContains(response, unit.name)
        self.assertNotContains(response, unit2.name)
Пример #4
0
def test_units_and_categories(db):
    categories = CategoryFactory.create_batch(4)
    unit1 = UnitFactory(categories=categories[:3])
    unit2 = UnitFactory(categories=[categories[0]])
    unit3 = UnitFactory(categories=[categories[1]])

    assert set(Unit.objects.filter(categories=categories[0])) == {unit1, unit2}
    assert set(Unit.objects.filter(categories=categories[1])) == {unit1, unit3}
    assert set(Unit.objects.filter(categories=categories[2])) == {unit1}
    assert Unit.objects.filter(categories=categories[3]).count() == 0
    assert set(Unit.objects.filter(categories__in=categories[0:2])) == {unit1, unit2,
                                                                        unit3}
    assert set(Category.objects.filter(unit_set=unit1)) == set(categories[:3])
Пример #5
0
    def test_player_unit_table_zeta(self):
        player = PlayerFactory()

        # Should have zero zeta
        unit_no_zeta = UnitFactory()
        PlayerUnitFactory(player=player, unit=unit_no_zeta, gp=1000)
        SkillFactory(unit=unit_no_zeta, is_zeta=True)

        # Should have one zetas
        unit_one_zeta = UnitFactory()
        pu_one_zeta = PlayerUnitFactory(player=player,
                                        unit=unit_one_zeta,
                                        gp=999)
        SkillFactory(unit=unit_one_zeta, is_zeta=False)
        ZetaFactory(skill=SkillFactory(unit=unit_one_zeta, is_zeta=True),
                    player_unit=pu_one_zeta)
        SkillFactory(unit=unit_one_zeta, is_zeta=False)

        # Should have two zetas
        unit_two_zetas = UnitFactory()
        pu_two_zetas = PlayerUnitFactory(player=player,
                                         unit=unit_two_zetas,
                                         gp=998)
        ZetaFactory(skill=SkillFactory(unit=unit_two_zetas, is_zeta=True),
                    player_unit=pu_two_zetas)
        ZetaFactory(skill=SkillFactory(unit=unit_two_zetas, is_zeta=True),
                    player_unit=pu_two_zetas)

        # Should two zetas as well
        unit_three_zetas = UnitFactory()
        pu_three_zetas = PlayerUnitFactory(player=player,
                                           unit=unit_three_zetas,
                                           gp=997)
        ZetaFactory(skill=SkillFactory(unit=unit_three_zetas, is_zeta=True),
                    player_unit=pu_three_zetas)
        ZetaFactory(skill=SkillFactory(unit=unit_three_zetas, is_zeta=True),
                    player_unit=pu_three_zetas)
        SkillFactory(unit=unit_three_zetas, is_zeta=False)
        SkillFactory(unit=unit_three_zetas, is_zeta=True)

        url = reverse('sqds:units')
        response = self.client.get(url)
        soup = BeautifulSoup(response.content, 'lxml')
        table = soup.find_all('div', class_='table-container')[0].table

        self.assertEqual(response.status_code, 200)
        self.assertEqual('-', table_get_cell(table, 'Zetas', 0))
        self.assertEqual('Z', table_get_cell(table, 'Zetas', 1))
        self.assertEqual('ZZ', table_get_cell(table, 'Zetas', 2))
        self.assertEqual('ZZ', table_get_cell(table, 'Zetas', 3))
Пример #6
0
def test_player_mod_stats_6pips(db):
    toon_mod_pips = [
        (5, 5, 5, 5, 5, 5),
        (5, 6, 6, 6, 6, 6),
        (None, None, None, None, None, None),
        (None, 6, None, 5, None, 6),
        (None, 4, 4, 4, 6, 5),
        (1, 2, 3, 4, 5, 6),
    ]

    mod_count = sum(x is not None for x in itertools.chain(*toon_mod_pips))
    mod_count_6dot = sum(x is not None and x == 6
                         for x in itertools.chain(*toon_mod_pips))

    player = PlayerFactory()
    for mod_pips in toon_mod_pips:
        pu = PlayerUnitFactory(unit=UnitFactory(), player=player)
        for slot, pips in enumerate(mod_pips):
            if pips is not None:
                ModFactory(player_unit=pu, slot=slot, pips=pips)

    qs = Player.objects.filter(pk=player.pk).annotate_stats()

    assert qs.count() == 1
    assert qs[0].mod_count == mod_count
    assert qs[0].mod_count_6dot == mod_count_6dot
Пример #7
0
def generate_game_data(unit_api_id=None):
    """
    Generate random mock game data. Returns array of units
    """
    categories = CategoryFactory.create_batch(5)
    GearFactory.create_batch(30)
    if unit_api_id:
        return [
            UnitFactory(api_id=api_id,
                        categories=random_sublist(categories, 0.1))
            for api_id in unit_api_id
        ]
    else:
        return [
            UnitFactory(categories=random_sublist(categories, 0.1))
            for _ in range(15)
        ]
Пример #8
0
def test_player_annotate_stats_unit_count(db):
    player = PlayerFactory()

    PlayerUnitFactory(player=player, unit=UnitFactory(), rarity=7, gear=13)
    PlayerUnitFactory(player=player, unit=UnitFactory(), rarity=7, gear=12)
    PlayerUnitFactory(player=player, unit=UnitFactory(), rarity=6, gear=11)
    PlayerUnitFactory(player=player, unit=UnitFactory(), rarity=6, gear=10)

    qs = Player.objects.filter(pk=player.pk).annotate_stats()

    assert qs.count() == 1
    assert qs[0].unit_count == 4
    assert qs[0].g13_unit_count == 1
    assert qs[0].g12_unit_count == 1
    assert qs[0].g11_unit_count == 1
    assert qs[0].g10_unit_count == 1
    assert qs[0].seven_star_unit_count == 2
Пример #9
0
def test_player_dict_from_ally_code_some_units(db):
    player = PlayerFactory()
    units = UnitFactory.create_batch(3)
    for u in units:
        PlayerUnitFactory(player=player, unit=u)

    unit_ids = [units[0].api_id, units[2].api_id]
    dct = PlayerUnit.objects.dict_from_ally_code(player.ally_code, unit_ids)
    assert dct.keys() == set(unit_ids)
Пример #10
0
    def setUpTestData(cls):
        generate_game_data()

        # ensure everyone has some some Separatist
        sep_category = CategoryFactory(api_id='affiliation_separatist')
        sep_unit = UnitFactory(categories=[sep_category])

        generate_guild()
        for player in Player.objects.all():
            PlayerUnitFactory(player=player, unit=sep_unit)
Пример #11
0
def test_player_mod_stats(db):
    """
    We create a bunch of player units equipped with mod of defined speed. We avoid
    speed primaries for arrows in this test.
    """
    # 2nd mod is always the array
    toon_mod_speeds = [
        (5, 17, 4, 5, 1, 0),
        (6, 15, 15, 2, 5, 1),
        (None, 30, None, 14, 0, 1),
        (None, None, None, None, None, None),
        (None, 30, None, None, None, None),
        (24, 30, 27, 21, 2, 25),
        (16, 17, 18, 19, 20, 21),
    ]

    mod_count = sum(x is not None for x in itertools.chain(*toon_mod_speeds))
    mod_count_6dot = 0
    mod_count_speed_25 = sum(
        x is not None and 25 <= x
        for i, x in enumerate(itertools.chain(*toon_mod_speeds)))
    mod_count_speed_20 = sum(
        x is not None and 20 <= x < 25
        for i, x in enumerate(itertools.chain(*toon_mod_speeds)))
    mod_count_speed_15 = sum(
        x is not None and 15 <= x < 20
        for i, x in enumerate(itertools.chain(*toon_mod_speeds)))
    mod_count_speed_10 = sum(
        x is not None and 10 <= x < 15
        for i, x in enumerate(itertools.chain(*toon_mod_speeds)))
    mod_total_speed_15plus = sum(
        x for i, x in enumerate(itertools.chain(*toon_mod_speeds))
        if x is not None and x >= 15)

    player = PlayerFactory()
    for mod_speeds in toon_mod_speeds:
        pu = PlayerUnitFactory(unit=UnitFactory(), player=player)
        for slot, speed in enumerate(mod_speeds):
            if speed is not None:
                ModFactory(player_unit=pu,
                           slot=slot,
                           speed=speed,
                           pips=5,
                           primary_stat='DE')

    qs = Player.objects.filter(pk=player.pk).annotate_stats()

    assert qs.count() == 1
    assert qs[0].mod_count == mod_count
    assert qs[0].mod_count_6dot == mod_count_6dot
    assert qs[0].mod_count_speed_25 == mod_count_speed_25
    assert qs[0].mod_count_speed_20 == mod_count_speed_20
    assert qs[0].mod_count_speed_15 == mod_count_speed_15
    assert qs[0].mod_count_speed_10 == mod_count_speed_10
    assert qs[0].mod_total_speed_15plus == mod_total_speed_15plus
Пример #12
0
 def test_guild_view_total_separatists(self):
     guild = generate_guild(player_count=0)
     players = PlayerFactory.create_batch(3, guild=guild)
     unit = UnitFactory(categories=Category.objects.filter(
         api_id='affiliation_separatist'))
     for player in players:
         PlayerUnitFactory(player=player, gp=1000, unit=unit)
     url = reverse('sqds:guild', args=[guild.api_id])
     response = self.client.get(url)
     text = big_number(3000.)
     self.assertContains(response, text)
Пример #13
0
    def test_zeta_display(self):
        unit = UnitFactory()
        skill = SkillFactory(unit=unit, is_zeta=True)
        ZetaMedalRuleFactory(unit=unit, skill=skill)
        StatMedalRuleFactory.create_batch(6, unit=unit)

        url = reverse("sqds_medals:list")
        response = self.client.get(url)

        self.assertContains(response, skill.name)
        self.assertContains(response, unit.name)
Пример #14
0
def test_stat_medal_rule_str_repr(db):
    unit = UnitFactory()
    rule = StatMedalRuleFactory(unit=unit, stat="health", value=10000)

    assert "Health" in str(rule)
    assert str(10000) in str(rule)

    assert "health" in repr(rule)
    assert str(1000) in repr(rule)
    assert unit.name in repr(rule)
    assert "StatMedalRule" in repr(rule)
Пример #15
0
def test_zeta_medal_rule_str(db):
    unit = UnitFactory()
    skill = SkillFactory(unit=unit, is_zeta=True)
    rule = ZetaMedalRuleFactory(unit=unit, skill=skill)

    assert "Zeta" in str(rule)
    assert skill.name in str(rule)

    assert "ZetaMedalRule" in repr(rule)
    assert skill.name in repr(rule)
    assert unit.name in repr(rule)
Пример #16
0
def test_player_annotate_stats_zeta_count(db):
    player = PlayerFactory()
    unit = UnitFactory()
    SkillFactory(unit=unit, is_zeta=True)
    skill = SkillFactory(unit=unit, is_zeta=True)
    SkillFactory(unit=unit, is_zeta=False)
    pu = PlayerUnitFactory(player=player, unit=unit)
    ZetaFactory(player_unit=pu, skill=skill)

    qs = Player.objects.filter(pk=player.pk).annotate_stats()

    assert qs.count() == 1
    assert qs[0].zeta_count == 1
Пример #17
0
def test_update_all_deletes_invalid_medals(db):
    unit = UnitFactory()
    PlayerUnitFactory(unit=unit, player=PlayerFactory(), health=3500)
    rules = [
        StatMedalRuleFactory(unit=unit, stat="health", value=x * 1000)
        for x in range(7)
    ]

    Medal.objects.update_all()
    assert Medal.objects.count() == 4
    rules[0].delete()
    Medal.objects.update_all()
    assert Medal.objects.count() == 0
Пример #18
0
def test_update_for_unit_after_rule_removal(db):
    unit = UnitFactory()
    rules = [
        StatMedalRuleFactory(unit=unit, stat="health", value=x * 1000)
        for x in range(7)
    ]
    player = PlayerFactory()
    PlayerUnitFactory(player=player, unit=unit, health=3500)

    assert Medal.objects.count() == 0
    Medal.objects.update_for_unit(unit)
    assert Medal.objects.count() == 4
    rules[0].delete()
    Medal.objects.update_for_unit(unit)
    assert Medal.objects.count() == 0
Пример #19
0
    def test_wrong_medals(self):
        unit_ok, unit_under, unit_over = UnitFactory.create_batch(3)
        ZetaMedalRuleFactory(unit=unit_ok,
                             skill=SkillFactory(unit=unit_ok, is_zeta=True))
        ZetaMedalRuleFactory(unit=unit_under,
                             skill=SkillFactory(unit=unit_under, is_zeta=True))
        StatMedalRuleFactory.create_batch(6, unit=unit_ok)
        StatMedalRuleFactory.create_batch(8, unit=unit_over)
        StatMedalRuleFactory.create_batch(5, unit=unit_under)

        url = reverse("sqds_medals:list")
        response = self.client.get(url)

        self.assertContains(response, unit_ok.name)
        self.assertNotContains(response, unit_over.name)
        self.assertNotContains(response, unit_under.name)
Пример #20
0
def test_update_all_with_ally_code(db):
    """
    Medals should not be created for player unit belonging to players whose ally code
    are not passed to MedalManager.update_all()
    """
    unit = UnitFactory()
    for x in range(7):
        StatMedalRuleFactory(unit=unit, stat="health", value=x * 1000)

    p1, p2 = PlayerFactory.create_batch(2)
    PlayerUnitFactory(player=p1, unit=unit, health=3500)
    pu2 = PlayerUnitFactory(player=p2, unit=unit, health=3500)

    Medal.objects.update_all(ally_codes=[p1.ally_code])
    assert Medal.objects.count() == 4
    assert Medal.objects.filter(player_unit=pu2).count() == 0

    Medal.objects.update_all()
    assert Medal.objects.count() == 8
Пример #21
0
    def test_stat_display(self):
        unit = UnitFactory()
        stats = [
            ("speed", 100),
            ("mod_speed", 50),
            ("health", 1000),
            ("protection", 100000),
            ("potency", 0.50),
            ("mod_critical_chance", 0.10),
            ("critical_damage", 2.22),
        ]

        for stat, value in stats:
            StatMedalRuleFactory(unit=unit, stat=stat, value=value)

        url = reverse("sqds_medals:list")
        response = self.client.get(url)

        for stat, value in stats:
            rule = StatMedalRule(stat=stat, value=value)
            self.assertContains(response, str(rule))
Пример #22
0
def test_update_for_unit(db):
    unit1, unit2 = UnitFactory.create_batch(2)
    for x in range(7):
        for unit in unit1, unit2:
            StatMedalRuleFactory(unit=unit, stat="health", value=x * 1000)
    player = PlayerFactory()
    PlayerUnitFactory(player=player, unit=unit1, health=3500)
    pu2 = PlayerUnitFactory(player=player, unit=unit2, health=3500)

    Medal.objects.update_for_unit(unit=unit1)
    assert Medal.objects.count() == 4
    assert Medal.objects.filter(player_unit=pu2).count() == 0

    Medal.objects.update_all()
    assert Medal.objects.count() == 8

    StatMedalRule.objects.filter(unit=unit1)[0].delete()
    StatMedalRule.objects.filter(unit=unit2)[0].delete()
    Medal.objects.update_for_unit(unit1)
    assert Medal.objects.count() == 3  # because of delete propagation
    assert Medal.objects.filter(player_unit=pu2).count() == 3

    Medal.objects.update_all()
    assert Medal.objects.count() == 0
Пример #23
0
def over_medaled_unit(db):
    unit = UnitFactory()
    StatMedalRuleFactory.create_batch(8, unit=unit)
    return unit
Пример #24
0
def under_medaled_unit(db):
    unit = UnitFactory()
    ZetaMedalRuleFactory(unit=unit,
                         skill=SkillFactory(unit=unit, is_zeta=True))
    StatMedalRuleFactory.create_batch(5, unit=unit)
    return unit
Пример #25
0
def test_player_dict_from_ally_code_all_units(db):
    player = PlayerFactory()
    units = UnitFactory.create_batch(3)
    for u in units:
        PlayerUnitFactory(player=player, unit=u)

    dct = PlayerUnit.objects.dict_from_ally_code(player.ally_code)

    assert dct.keys() == set(u.api_id for u in units)

    attr_list = [
        # PlayerUnit fields
        'gp',
        'rarity',
        'level',
        'gear',
        'equipped_count',
        'speed',
        'health',
        'protection',
        'physical_damage',
        'physical_crit_chance',
        'special_damage',
        'special_crit_chance',
        'crit_damage',
        'potency',
        'tenacity',
        'armor',
        'resistance',
        'armor_penetration',
        'resistance_penetration',
        'health_steal',
        'accuracy',
        'mod_speed',
        'mod_health',
        'mod_protection',
        'mod_physical_damage',
        'mod_special_damage',
        'mod_physical_crit_chance',
        'mod_special_crit_chance',
        'mod_crit_damage',
        'mod_potency',
        'mod_tenacity',
        'mod_armor',
        'mod_resistance',
        'mod_critical_avoidance',
        'mod_accuracy',
        'last_updated',

        # annotate_stats
        'mod_speed_no_set',
        'zeta_count',
    ]

    for api_id in dct:
        pu = PlayerUnit.objects.annotate_stats().get(unit__api_id=api_id)
        for attr in attr_list:
            assert getattr(dct[api_id], attr) == getattr(pu, attr)

        # dict_from_ally_code
        assert dct[api_id].unit_name == pu.unit.name
        assert dct[api_id].unit_api_id == pu.unit.api_id == api_id
        assert dct[api_id].player_name == pu.player.name == player.name
        assert dct[
            api_id].player_ally_code == pu.player.ally_code == player.ally_code