Ejemplo n.º 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
Ejemplo n.º 2
0
    def test_player_unit_table_single_unit(self):
        player = PlayerFactory()
        pus = [
            PlayerUnitFactory(player=player,
                              unit=Unit.objects.first(),
                              gp=1000),
            PlayerUnitFactory(player=player,
                              unit=Unit.objects.last(),
                              gp=999,
                              speed=0,
                              health=0,
                              mod_speed=0,
                              mod_potency=0.,
                              mod_tenacity=0)
        ]

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

        column_to_test = [
            ('Speed', 'speed'),
            ('Mod speed', 'mod_speed'),
            ('HP', 'health'),
            ('Mod HP', 'mod_health'),
            ('Prot.', 'protection'),
            ('Mod prot.', 'mod_protection'),
            ('Phys. dmg', 'physical_damage'),
            ('Mod phys. dmg', 'mod_physical_damage'),
            ('Phys. CC', 'physical_crit_chance'),
            ('Mod phys. CC', 'mod_physical_crit_chance'),
            ('Spec. dmg', 'special_damage'),
            ('Mod spec. dmg', 'mod_special_damage'),
            ('Spec. CC', 'special_crit_chance'),
            ('Mod spec. CC', 'mod_special_crit_chance'),
            ('CD', 'crit_damage'),
            ('Pot.', 'potency'),
            ('Mod pot.', 'mod_potency'),
            ('Ten.', 'tenacity'),
            ('Mod ten.', 'mod_tenacity'),
            ('Armor', 'armor'),
            ('Res.', 'resistance'),
        ]

        self.assertEqual(response.status_code, 200)
        for row_index, pu in enumerate(pus):
            for col in column_to_test:
                self.assertAlmostEqual(string_to_float(
                    table_get_cell(table, col[0], row_index)),
                                       getattr(pu, col[1]),
                                       places=2)
        self.assertTrue(table_column_contains_int(table, 'Speed'))
Ejemplo n.º 3
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))
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
    def test_player_unit_table_mod_speed_vs_pure_mod_speed(self):
        player = PlayerFactory()

        def create_mod_set(player_unit, speeds):
            for i in range(6):
                ModFactory(player_unit=player_unit, slot=i, speed=speeds[i])

        pu1 = PlayerUnitFactory(player=player,
                                unit=Unit.objects.first(),
                                gp=1000,
                                mod_speed=0)
        create_mod_set(pu1, [0, 0, 0, 0, 0, 0])

        pu2 = PlayerUnitFactory(player=player,
                                unit=Unit.objects.first(),
                                gp=999,
                                mod_speed=45)
        create_mod_set(pu2, [5, 6, 7, 8, 9, 10])

        pu3 = PlayerUnitFactory(player=player,
                                unit=Unit.objects.first(),
                                gp=998,
                                mod_speed=100)
        create_mod_set(pu3, [8, 8, 8, 8, 8, 8])

        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(
            string_to_float(table_get_cell(table, 'Mod speed', 0)), 0)
        self.assertEqual(
            string_to_float(table_get_cell(table, 'Pure mod speed', 0)), 0)
        self.assertEqual(
            string_to_float(table_get_cell(table, 'Mod speed', 1)), 45)
        self.assertEqual(
            string_to_float(table_get_cell(table, 'Pure mod speed', 1)), 45)
        self.assertEqual(
            string_to_float(table_get_cell(table, 'Mod speed', 2)), 100)
        self.assertEqual(
            string_to_float(table_get_cell(table, 'Pure mod speed', 2)), 48)
Ejemplo n.º 9
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
Ejemplo n.º 10
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
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
def test_guild_annotate_faction_gp(game_data):
    guild = GuildFactory()
    player = PlayerFactory(guild=guild)
    sep_units = list(
        Unit.objects.filter(categories__api_id='affiliation_separatist'))
    gr_units = list(
        Unit.objects.filter(categories__api_id='affiliation_republic'))

    sep_pus = [
        PlayerUnitFactory(player=player, unit=unit)
        for unit in random.sample(sep_units, 3)
    ]
    gr_pus = [
        PlayerUnitFactory(player=player, unit=unit)
        for unit in random.sample(gr_units, 3)
    ]
    qs = Guild.objects.annotate_faction_gp()

    assert qs[0].sep_gp == sum(pu.gp for pu in sep_pus)
    assert qs[0].gr_gp == sum(pu.gp for pu in gr_pus)
Ejemplo n.º 13
0
    def test_base_view(self):
        player = PlayerFactory()
        pu = PlayerUnitFactory(player=player)
        url = reverse('sqds:unit', args=[pu.player.ally_code, pu.unit.api_id])
        response = self.client.get(url)

        self.assertContains(response, pu.unit.name)
        self.assertContains(response, str(pu.speed))
        self.assertContains(response, 'G' + str(pu.gear))
        self.assertContains(response, str(pu.level))
        self.assertTemplateUsed(response, 'sqds/unit.html')
Ejemplo n.º 14
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
Ejemplo n.º 15
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
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
0
Archivo: utils.py Proyecto: abey79/sqds
def generate_player_unit(unit, player, **kwargs):
    player_unit = PlayerUnitFactory(unit=unit, player=player, **kwargs)

    # Generate some gear
    for _ in range(random.randint(0, 5)):
        PlayerUnitGear(player_unit=player_unit,
                       gear=random.choice(Gear.objects.all()))

    # Zeta some abilities
    for skill in Skill.objects.filter(unit=unit):
        if skill.is_zeta and random.random() > 0.5:
            ZetaFactory(player_unit=player_unit, skill=skill)

    # Equip some mods
    for slot in random_sublist(range(7)):
        ModFactory(player_unit=player_unit, slot=slot)

    return player_unit
Ejemplo n.º 19
0
    def test_mod_view(self):
        player = PlayerFactory()
        pu = PlayerUnitFactory(player=player)
        ModFactory(player_unit=pu,
                   slot=0,
                   primary_stat='OF',
                   offense_percent=0.0588,
                   speed=17)
        ModFactory(player_unit=pu,
                   slot=1,
                   primary_stat='DE',
                   speed=13,
                   speed_roll=3)
        ModFactory(player_unit=pu, slot=2, primary_stat='PR', offense=120)

        url = reverse('sqds:unit', args=[pu.player.ally_code, pu.unit.api_id])
        response = self.client.get(url)

        self.assertContains(response, str(13))
        self.assertContains(response, 'Speed (3)')
        self.assertContains(response, '5.88%')
        self.assertContains(response, str(120))
Ejemplo n.º 20
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