Exemple #1
0
class CharacterManager:
    def __init__(self):
        from data.DAO.CharacterDAO import CharacterDAO
        self.DAO = CharacterDAO()

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

    def update_character(self, character: Character):
        return self.DAO.update(character)

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

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

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

    def create_empty(self, lang) -> Character:
        character = Character(None, lang)
        id = self.DAO.create(character)
        character.id = id

        return character
Exemple #2
0
    def test_character(self):
        """
        Test character DAO
        :return: 
        """
        DAO = CharacterDAO()

        character = Character(None, 'cs', 'Wilson', 'Character Wilson', 1, 2,
                              3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
                              Classes.RANGER, Races.ELF, Alignment.LAWFUL_GOOD,
                              1, 1)
        character2 = Character(None, 'cs', 'Don', 'Character Don', 13, 12, 11,
                               10, 9, 8, 7, 6, 5, 4, 3, 2, 1, Classes.MAGICIAN,
                               Races.KROLL, Alignment.LAWFUL_EVIL, 1, 1)

        id = DAO.create(character)
        id2 = DAO.create(character2)

        getCharacter = DAO.get(id)
        getCharacter2 = DAO.get(id2)

        self.assertEqual(character, getCharacter,
                         'First character is not equal')
        self.assertEqual(character2, getCharacter2,
                         'Second character is not equal')
        self.assertNotEqual(getCharacter, getCharacter2,
                            'First and second character is equal')

        character.intelligence = 5
        DAO.update(character)
        getObject = DAO.get(id)

        self.assertEqual(getObject, character)

        DAO.delete(id)

        deleted = DAO.get(id)
        self.assertIsNone(deleted)