예제 #1
0
 def addGrade(self, cmd, debug = None):
     '''
     Checks if using some parameteres a grade can be added in the repository
     
     Parameters:
     cmd - contains the parts which compose a grade
     debug - used only for testing
     '''
     parameters = Utility.splitParameters(cmd)
     if parameters == None:
         raise ValueError
     if len(parameters) == 4 and len(parameters[0]) > 0 and len(parameters[1]) == 1 and len(parameters[2]) == 1 and len(parameters[3]) > 0:
         disc = parameters[0][0]
         for i in range(1, len(parameters[0])):
             disc = disc + ' ' + parameters[0][i]
             
         name = parameters[3][0]
         for i in range(1, len(parameters[3])):
             name = name + ' ' + parameters[0][i]
             
         if Controller.isDuplicate(self, disc, "discipline") != -1 and Utility.isConvertableToInt(parameters[1][0]) and Controller.isDuplicate(self, int(parameters[1][0]), "studentID") != -1 and parameters[2][0]:
             Repository.push(self._repository, Grade(disc, parameters[1][0], name, parameters[2][0]))
             return
         elif Controller.isDuplicate(self, disc, "discipline") == -1:
             raise DuplicateDisciplineError
         elif Controller.isDuplicate(self, int(parameters[1][0]), "studentID") == -1:
             raise DuplicateIDError
     raise ValueError
예제 #2
0
파일: test.py 프로젝트: Cronologium/lab5-7
 def _test_repository_pushremove(self):
     '''
     Tests if the functions push and remove from the repository work
     '''
     repository = Repository()
     Repository.push(repository, "5", 0)
     Repository.push(repository, 2)        
     Repository.push(repository, True, 3)
     Repository.push(repository, 7.5)
     
     assert Repository.getList(repository) == ["5", 2, 7.5]
     
     Repository.remove(repository, 3)
     Repository.remove(repository, 1)
     
     assert Repository.getList(repository) == ["5", 7.5]
     
     Repository.remove(repository, 0)
     
     assert Repository.getList(repository) == [7.5]
     
     Repository.remove(repository, 0)
     Repository.remove(repository, 0)
     
     assert Repository.getList(repository) == []
예제 #3
0
파일: test.py 프로젝트: Cronologium/lab5-7
 def _test_controller_isDuplicate(self):
     '''
     Tests if finding a duplicate in the repository works
     '''
     repository = Repository()
     controller = Controller(repository)
     Repository.push(repository, Student("john", 1))
     Repository.push(repository, "Test QA")
     
     assert Controller.isDuplicate(controller, 1, "studentID") == 0
     assert Controller.isDuplicate(controller, 2, "studentID") == -1
     assert Controller.isDuplicate(controller, "Test QA", "discipline") == 1
     assert Controller.isDuplicate(controller, "Tester QA", "discipline") == -1
     assert Controller.isDuplicate(controller, 1, "???") == -1
     assert Controller.isDuplicate(controller, "78", "studentID") == -1
예제 #4
0
 def addStudent(self, cmd):
     '''
     Checks if using some parameters a student can be added in the repository
     
     Parameters:
     cmd - contains the parts which compose a student
     debug - used only for testing
     '''
     parameters = Utility.splitParameters(cmd)
     if parameters == None:
         raise ValueError
     if len(parameters) == 1 and len(parameters[0]) > 0:
         name = parameters[0][0]
         for i in range(1, len(parameters[0])):
             name = name + ' ' + parameters[0][i]
         Repository.push(self._repository, Student(name, Controller.getID(self)))
         return
     raise ValueError
예제 #5
0
 def addDiscipline(self, cmd, debug = None):
     '''
     Checks if using some parameters a discipline can be added in the repository
     
     Parameters:
     cmd - contains the parts which compose a discipline
     debug - used only for testing
     '''
     parameters = Utility.splitParameters(cmd)
     if parameters == None:
         raise ValueError
     if len(parameters) == 1 and len(parameters[0]) > 0:
         disc = parameters[0][0]
         for i in range(1, len(parameters[0])):
             disc = disc + ' ' + parameters[0][i]
         if Controller.isDuplicate(self, disc, "discipline") == -1:
             Repository.push(self._repository, disc)
             return
         else:
             raise DuplicateDisciplineError
     raise ValueError