Esempio n. 1
0
def generateDisciplines():
    undoController.newOperation(), disciplines.store(Discipline(1, 'Math'))
    undoController.newOperation(), disciplines.store(
        Discipline(2, 'Assembly Language'))
    undoController.newOperation(), disciplines.store(
        Discipline(3, 'Programming Fundamentals'))
    undoController.newOperation(), disciplines.store(
        Discipline(4, 'Computation Logic'))
    undoController.newOperation(), disciplines.store(Discipline(5, 'Sport'))
Esempio n. 2
0
 def test_discipline_repository(self):
     disc_repo = DisciplineRepository()
     self.assertIsInstance(disc_repo, DisciplineRepository,
                           'Wrong instance')
     self.assertIsInstance(disc_repo, Repository, 'Wrong instance')
     self.assertEqual(len(disc_repo._list), 0)
     disc_repo.store(Discipline('Maatee'))
     self.assertEqual(disc_repo._list[-1].name, 'Maatee')
     disc_repo.remove(0)
     disc_repo.store(Discipline('Matha'))
     self.assertEqual(disc_repo._list[-1].name, 'Matha')
     disc_repo.update(-1, 'nomoreMateee')
     self.assertEqual(disc_repo._list[-1].name, 'nomoreMateee')
    def testName(self):
        "Discipline ID must be positive"

        discipline = Discipline(-1, "Ana")
        try:
            self.__validator.validate(discipline)
        except DisciplineValidatorException:
            pass

        "Discipline name cannot be empty"
        discipline = Discipline(1, "")
        try:
            self.__validator.validate(discipline)
        except DisciplineValidatorException:
            pass
Esempio n. 4
0
 def update(self, oldDisciplineID, newID, newName):
     """
     Updates the discipline with oldDisciplineID to newDiscipline
     """
     newDiscipline = Discipline(newID, newName)
     self._validator.validate(newDiscipline)
     return self._repo.update(oldDisciplineID, newDiscipline)
 def _load_file(self):
     with open(self._path, 'r') as fp:
         data = json.load(fp)
         for obj in data['disciplines']:
             id = obj['_id']
             name = obj['name']
             obj = Discipline.create_from_data(name, id)
             self._list.append(obj)
     fp.close()
Esempio n. 6
0
 def addDiscipline(self, ident, name):
     '''
     Adds a discipline to the repository
     ident - the id of the discipline
     name - discipline's name
     '''
     d = Discipline(ident, name)
     self._disciplineValidator.validate(d)
     self._disciplineRepo.store(d)
     return d
 def add(self, name):
     """
     Makes validations, creates the object and calls the repo Add
     :raises: IOErr
     """
     if not name.isalpha():
         raise IOErr("name must be literal")
     obj = Discipline(name)
     self._repo.store(obj)
     return obj
Esempio n. 8
0
 def add(self, disciplineID, disciplineName):   
     try:
         disciplineID = int(disciplineID)
     except ValueError:
         raise DisciplineControllerException ("Discipline ID must be an integer")
     if not disciplineName.isalpha():
         raise DisciplineControllerException("Name must contain only letters")            
     discipline = Discipline(disciplineID, disciplineName)
     self.__validator.validate(discipline)
     self.__disciplineRepo.add(discipline)
Esempio n. 9
0
 def update(self, disciplineID, newName): 
     try:
         disciplineID = int(disciplineID)
     except ValueError:
         raise DisciplineControllerException ("Discipline ID must be an integer")  
     if not newName.isalpha():
         raise DisciplineControllerException("Name must contain only letters")  
     newSt = Discipline(disciplineID, newName)
     self.__validator.validate(newSt)
     self.__disciplineRepo.update(newSt)
 def _load_file(self):
     file = open(self._path, 'r')
     line = file.readline()
     while line:
         line = line.strip().split()
         name = line[0]
         id = line[1]
         obj = Discipline.create_from_data(name, id)
         self._list.append(obj)
         line = file.readline()
     file.close()
Esempio n. 11
0
 def __readDiscipline(self):
     '''
     Functionality: Try to read a Discipline object parameters, if fail print invalid input 
     INPUT: -
     OUTPUT: an object Discipline
     '''
     print("Please insert the discipline ID:")
     ID = self.__getNumber()
     name = input("Discipline Name: ")
     
     return Discipline(ID, name)
Esempio n. 12
0
 def create(self, disciplineID, disciplineName):
     """
     Creates, validates and adds a new discipline to the discipline repository
     Input:
         - disciplineID - integer, discipline's id
         - disciplineName - string, discipline's name
     """
     discipline = Discipline(disciplineID, disciplineName)
     self._validator.validate(discipline)
     self._repo.add(discipline)
     return True
Esempio n. 13
0
 def searchForName(self, name):
     '''
     Partial string matching(search for a discipline by her name, the search is case insensitive)
     id - the id to search for ( can't be empty )
     '''
     _entity = []
     d = Discipline(None, name)
     self._disciplineValidator.validate(d)
     for student in self._disciplineRepo.getAll():
         if name.lower() in student.name.lower():
             _entity.append(str(student))
     return _entity
Esempio n. 14
0
 def setUp(self):
     self.__disciplineRepo.add(Discipline(1,"Algebra"))
     self.__disciplineRepo.add(Discipline(2,"Mathematical Analysis"))
     self.__disciplineRepo.add(Discipline(3,"Fundamentals of Programming"))
     self.__disciplineRepo.add(Discipline(4,"Computational Logic"))
     self.__disciplineRepo.add(Discipline(5,"Computer System Architecture"))
     self.__disciplineRepo.add(Discipline(14, "Sports"))
Esempio n. 15
0
 def _loadFile(self):
     try:
         file = open(self._fileName, "r")
         entry = file.readline()
         while len(entry) > 2:
             entryList = entry.split(',')
             DisciplineRepo.add(
                 self, Discipline(int(entryList[0]), entryList[1][:-1]))
             entry = file.readline()
     except FileNotFoundError as fnfe:
         raise ValueError("Cannot open file " + str(fnfe))
     finally:
         file.close()
Esempio n. 16
0
    def __loadFromFile(self):
        try:
            f = open(self.__fileName, "r")
            line = f.readline().strip()
            while line != "":
                attrs = line.split(",")
                discipline = Discipline(int(attrs[0]), attrs[1])
                DisciplineRepository.add(self, discipline)
                line = f.readline().strip()

        except IOError:
            raise FileRepositoryException()
        finally:
            f.close()
Esempio n. 17
0
 def test_Discipline(self):
     obj = Discipline('Disciplina')
     self.assertEqual(obj.name, 'Disciplina')
     self.assertIsNotNone(obj._id)
     with self.assertRaises(DisciplineError):
         obj.name = 123
     with self.assertRaises(DisciplineError):
         obj.name = '123'
     self.assertEqual(obj.get_id(), obj._id)
     self.assertEqual(obj.__str__(), obj.name)
    def create(self, discipline_id, name):
        for i in self.__repository.get_all():
            if discipline_id == i.id:
                raise DisciplineException("[ERROR] This ID is already in use")

        discipline = Discipline(discipline_id, name)

        self.__validator.validate(discipline)
        self.__repository.store(discipline)

        undo = FunctionCall(self.remove, discipline_id)
        redo = FunctionCall(self.create, discipline_id, name)
        operation = Operation(undo, redo)
        self.__undoController.add_operation(operation)

        return discipline
Esempio n. 19
0
    def store(self, discipline_id, discipline_name):
        """
        Stores a Discipline instance in the repository
        :param discipline_id: The ID of the discipline to be stored in the repository
        :param discipline_name: The name of the discipline to be stored in the repository
        :return: -
        :raises: RepoException: Discipline having the given ID already in the repository
        """
        self.__validator.validate_id(discipline_id)
        self.__validator.validate_name(discipline_name)

        if self.find_by_id(discipline_id) is not None:
            raise RepositoryException("Discipline having ID " +
                                      str(discipline_id) +
                                      " already in the repository!")

        self.__disciplines.append(Discipline(discipline_id, discipline_name))
 def update(self, discipline_id, name):
     discipline = Discipline(discipline_id, name)
     self.__validator.validate(discipline)
     self.__repository.update(discipline)
 def setUp(self):
     self.__discipline = Discipline(1, "Algebra")
 def setUp(self):
     self.v = DisciplineValidator()
     self.d = Discipline("1", "Math")
     self.r = Repository()
     self.c = DisciplineController(self.r, self.v)
 def _load_list(self):
     for obj in self._collection.find():
         self._list.append(
             Discipline.create_from_data(obj['name'], obj['_id']))
Esempio n. 24
0
 def setUp(self):
     self.__repo = DisciplineRepository()
     self.__discipline = Discipline(1, "Anna")