Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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
Esempio n. 4
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