def testValidateStudent(self):
     val = StudentValidator()
     """
         Student ID must exist
     """
     st = Student("", "Ion", Address("Adr", 1, "Cluj"))
     try:
         val.validate(st)
         self.assertTrue(False)
     except ValidationException:
         pass
     """
         Student name must exist
     """
     st = Student("3", "", Address("Adr", 1, "Cluj"))
     try:
         val.validate(st)
         self.assertTrue(False)
     except ValidationException:
         pass
     """
         Address must exist
     """
     st = Student("3", "Ion", Address("", "Cluj", ""))
     try:
         val.validate(st)
         self.assertTrue(False)
     except ValidationException:
         pass
 def testUpdate(self):
     ctr = StudentController(StudentValidator(), StudentRepository())
     ctr.create("1", "Ion", "Cluj", "Turda", "Adr1")
     st = ctr.update("1", "Ionel", "Cluj", "Dej", "Clujului")
 
     studs = ctr.search("Ionel")
     self.assertEqual(len(studs) , 1)
     self.assertEqual(studs[0].getAddr().getStreet() , "Clujului")
     
     """
         Verify the old student is returned
     """
     self.assertEqual(st.getName() , "Ion")
     self.assertEqual(st.getAddr().getStreet() , "Adr1")
 
     """
         Try to update an inexisting student
     """
     try:
         st = ctr.update("2", "Ionel", "Addrr", 1, "Cluj")
         self.assertTrue(False)
     except ValueError:
         pass
 
     """
         Try to update to invalid data
     """
     try:
         ctr.update("1", "", "", 1, "Cluj")
         self.assertTrue(False)
     except ValidationException:
         pass
    def testCreateStudent(self):
        """
         test function for create student
         Feature 1 - add a student
         Task 4 - Create student - controller
        """
        ctr = StudentController(StudentValidator(), StudentRepository())
        st = ctr.create("1", "Ion", "Cluj-Napoca", "Turda", "Addr")
        self.assertEqual(st.getId(), "1")
        self.assertEqual(st.getName(), "Ion")
        self.assertEqual(st.getAddr().getStreet(), "Addr")
        self.assertEqual(ctr.getNrStudents(), 1)

        """
            Test for invalid Student instance
        """
        try:
            ctr.create("1", "", "", 1, "Cluj")
            self.assertTrue(False)
        except ValidationException:
            pass
        
        """
            Test for duplicate id
        """
        try:
            ctr.create("1", "Ion2", "Adr2", 1, "Cluj")
            self.assertTrue(False)
        except DuplicateIDException:
            pass
 def testListFirst5(self):
     stRep = StudentRepository()
     stctr = StudentController(StudentValidator(), stRep)
     stctr.create("1", "Ion", "Cluj", "Gherla", "Turzii")
     stctr.create("2", "Ion2", "Cluj", "Gherla", "Turzii")
     stctr.create("3", "Ion3", "Cluj", "Gherla", "Turzii")
     stctr.create("4", "Ion4", "Cluj", "Gherla", "Turzii")
     stctr.create("5", "Ion5", "Cluj", "Gherla", "Turzii")
     stctr.create("6", "Ion6", "Cluj", "Gherla", "Turzii")
 
     ctr = GradeController(GradeRepository(), GradeValidator(), stRep)
     ctr.assign("1", "FP", 2)
     ctr.assign("2", "FP", 7)
     ctr.assign("3", "FP", 8)
     ctr.assign("4", "FP", 10)
     ctr.assign("5", "FP", 6)
     ctr.assign("6", "FP", 9)
 
     stgrs = ctr.getTop5("FP")
     self.assertEqual(len(stgrs) , 5)
     self.assertEqual(stgrs[0].getStudentId() , "4")
     self.assertEqual(stgrs[1].getStudentId() , "6")
     self.assertEqual(stgrs[2].getStudentId() , "3")
     self.assertEqual(stgrs[3].getStudentId() , "2")
     self.assertEqual(stgrs[4].getStudentId() , "5")
 def testAssignGrade(self):
     stRep = StudentRepository()
     stctr = StudentController(StudentValidator(), stRep)
     stctr.create("1", "Ion", "Cluj", "Turda", "Addrr8")
     ctr = GradeController(GradeRepository(), GradeValidator(), stRep)
 
     gr = ctr.assign("1", "FP", 10)
     self.assertEqual(gr.getDiscipline() , "FP")
     self.assertEqual(gr.getGradeValue() , 10)
     self.assertEqual(gr.getStudent().getId() , "1")
     self.assertEqual(gr.getStudent().getName() , "Ion")
 def testListGrade(self):
     stRep = StudentRepository()
     stctr = StudentController(StudentValidator(), stRep)
     stctr.create("1", "Ion", "Adr", 1, "Cluj")
 
     ctr = GradeController(GradeRepository(), GradeValidator(), stRep)
     gr = ctr.assign("1", "FP", 10)
     grs = ctr.listGrades("1")
     self.assertEqual(len(grs) , 1)
     gr = ctr.assign("1", "SO", 10)
     grs = ctr.listGrades("1")
     self.assertEqual(len(grs) , 2)
 def testRemoveStudent(self):
     ctr = StudentController(StudentValidator(), StudentRepository())
     ctr.create("1", "Ion", "Cluj", "Dej", "Clujului 82")
     
     """
         Test for invalid id
     """
     try:
         ctr.remove("2")
         self.assertTrue(False)
     except ValueError:
         pass
     
     self.assertEqual(ctr.getNrStudents() , 1)
 
     st = ctr.remove("1")
     self.assertEqual(ctr.getNrStudents() , 0)
     self.assertEqual(st.getId(), "1")
     self.assertEqual(st.getName() , "Ion")
     self.assertEqual(st.getAddr().getStreet() , "Clujului 82")
 def testSearchCriteria(self):
     rep = StudentRepository()
     ctr = StudentController(StudentValidator(), rep)
     ctr.create("1", "Ion", "Adr", 1, "Cluj")
     st2 = ctr.create("2", "Ion2", "Adr", 1, "Cluj")
     ctr.create("3", "Ioana1", "Adr", 1, "Cluj")
     st4 = ctr.create("4", "Ioana2", "Adr", 1, "Cluj")
     ctr.create("5", "Vlad", "Adr", 1, "Cluj")
 
     studs = ctr.search("Ion")
     self.assertEqual(len(studs) , 2)
     self.assertTrue(st2 in studs)
 
     studs = ctr.search("Io")
     self.assertEqual(len(studs) , 4)
     self.assertTrue(st4 in studs)
 
     studs = ctr.search("Al")
     self.assertEqual(len(studs) , 0)
 
     studs = ctr.search("")
     self.assertEqual(len(studs) , 5)
from examples.ex25_studentManagement.repository.GradeCSVFileRepository import GradeCSVFileRepository
from examples.ex25_studentManagement.repository.StudentCSVFileRepository import StudentCSVFileRepository

from examples.ex25_studentManagement.domain.GradeValidator import GradeValidator
from examples.ex25_studentManagement.domain.StudentValidator import StudentValidator
from examples.ex25_studentManagement.controller.StudentController import StudentController
from examples.ex25_studentManagement.controller.GradeController import GradeController
from examples.ex25_studentManagement.ui.Console import ConsoleUI
from examples.ex25_studentManagement.repository.StudentPickleFileRepository import StudentPickleFileRepository
from examples.ex25_studentManagement.repository.GradeRepository import GradeRepository
from examples.ex25_studentManagement.repository.GradePickleFileRepository import GradePickleFileRepository
"""
    1. Set up entity validators
"""
studentValidator = StudentValidator()
gradeValidator = GradeValidator()
"""
    2. Initialize the repositories
"""
studentRepo = StudentCSVFileRepository("students.txt")
# studentRepo = StudentPickleFileRepository()
gradeRepo = GradeCSVFileRepository(studentRepo, "grades.txt")
# gradeRepo = GradePickleFileRepository(studentRepo)
"""
    3. Initialize GRASP controllers
"""
studentController = StudentController(studentValidator, studentRepo)
gradeController = GradeController(gradeRepo, gradeValidator, studentRepo)
"""
    4. Start up the UI
"""