예제 #1
0
    def test_spell(self):
        """
        Test Spell DAO
        :return: 
        """
        DAO = SpellDAO()

        spell = Spell(None, 'cs', 'Fireball', 'Mighty fireball', '8', '5', '2',
                      '12', 2, '15', Classes.MAGICIAN)
        spell2 = Spell(None, 'cs', 'Blink', 'Fast blink', '2', '1', '6', '15',
                       4, '5', Classes.MAGICIAN)

        id = DAO.create(spell)
        id2 = DAO.create(spell2)

        getObject = DAO.get(id)
        getObject2 = DAO.get(id2)

        self.assertEqual(spell, getObject, 'First spell is not equal')
        self.assertEqual(spell2, getObject2, 'Second spell is not equal')
        self.assertNotEqual(getObject, getObject2,
                            'First and second spell is equal')

        spell.name = 'Updated fireball'
        DAO.update(spell)
        getObject = DAO.get(id)

        self.assertEqual(getObject, spell)

        DAO.delete(id)

        deleted = DAO.get(id)
        self.assertIsNone(deleted)
예제 #2
0
class SpellManager(ISpellManager):
    def __init__(self):
        from data.DAO.SpellDAO import SpellDAO
        self.DAO = SpellDAO()


    def create(self, spell: Spell, nodeParentId: int = None, contextType: ObjectType = None) -> int:
        return self.DAO.create(spell, nodeParentId, contextType)


    def update_spell(self, spell: Spell):
        return self.DAO.update(spell)


    def delete(self, spellId: int):
        return self.DAO.delete(spellId)


    def get(self, spellId: int, lang: str = None, nodeId: int = None, contextType: ObjectType = None) -> Spell:
        return self.DAO.get(spellId, lang, nodeId, contextType)


    def get_all(self, lang=None) -> list:
        return self.DAO.get_all(lang)


    def create_empty(self, lang):
        spell = Spell(None, lang)
        id = self.DAO.create(spell)
        spell.id = id

        return spell