import unittest

from classes import Paladin
from models.spells.loader import load_paladin_spells_for_level


class PaladinTests(unittest.TestCase):
    def setUp(self):
        self.name = "Netherblood"
        self.level = 3
        self.dummy = Paladin(name=self.name, level=self.level, health=100, mana=100, strength=10)

    def test_init(self):
        """ The __init__ should load/save all the spells for the Paladin"""
        spells = [spell for level in range(1,self.level+1) for spell in load_paladin_spells_for_level(level)]

        self.assertNotEqual(len(self.dummy.learned_spells), 0)
        for spell in spells:
            self.assertIn(spell.name, self.dummy.learned_spells)
            char_spell = self.dummy.learned_spells[spell.name]
            # find the largest rank in our spells list (the char has the highest rank only)
            max_rank = list(sorted(filter(lambda x: x.name == spell.name, spells), key=lambda x: x.rank))[-1].rank

            self.assertEqual(char_spell.rank, max_rank)


if __name__ == '__main__':
    unittest.main()

@@ -1016,16 +1016,707 @@
 _rank)%0A%0A
+    def test_leave_combat(self):%0A        %22%22%22%0A        Except the normal behaviour, leave_combat should remove the SOR buff from the pally%0A        and reset his spell cds%0A        %22%22%22%0A        self.dummy._in_combat = True%0A        self.dummy.SOR_ACTIVE = True%0A        for spell in self.dummy.learned_spells.values():%0A            spell._cooldown_counter = 100%0A%0A        self.assertTrue(self.dummy.is_in_combat())%0A%0A        self.dummy.leave_combat()%0A%0A        self.assertFalse(self.dummy.is_in_combat())%0A        self.assertFalse(self.dummy.SOR_ACTIVE)%0A        # All cooldowns should be reset%0A        self.assertTrue(all(%5Bspell._cooldown_counter == 0 for spell in self.dummy.learned_spells.values()%5D))%0A
 %0Aif __na

Test for the Paladin leave_combat function