def updateStudent(self, ident, newName):
     oldName = self._studentRepo[ident].name
     StudentController.updateStudent(self, ident, newName)
     redo = FunctionCall(self.updateStudent, ident, newName)
     undo = FunctionCall(self.updateStudent, ident, oldName)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
 def removeStudent(self, ident):
     '''
     Removes a student
     '''
     name = self._studentRepo[ident].name
     StudentController.removeStudent(self, ident)
     redo = FunctionCall(self.removeStudent, ident)
     undo = FunctionCall(self.addStudent, ident, name)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
     self._gradeController.removeStudent(ident)
 def addStudent(self, ident, name):
     s = StudentController.addStudent(self, ident, name)
     '''
     If the operation did not raise an Exception, then we record it for Undo/Redo
     '''
     redo = FunctionCall(self.addStudent, ident, name)
     undo = FunctionCall(self.removeStudent, ident)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
     return s
Example #4
0
class StudentControllerTest(unittest.TestCase):
    def setUp(self):
        studentValidator = StudentValidator()
        studentRepo = Repository()
        self._ctrl = StudentController(studentRepo,studentValidator)

    def testStudentController(self):
        self.assertEqual(self._ctrl.getStudCount(), 0)
        self._ctrl.add("4", "Pop Catalin", "916")
        self.assertEqual(self._ctrl.getStudCount(), 1)
        self._ctrl.remove("4")
        self.assertEqual(self._ctrl.getStudCount(), 0)
class TestStudentController(unittest.TestCase):
    def setUp(self):
        self.__repo = StudentRepository()
        self.__ctrl = StudentController(self.__repo)
        self.__student1 = Student(1, "Anna")
        self.__student2 = Student("", "Mary")

    def tearDown(self):
        del self.__repo
        del self.__ctrl
        del self.__student1
        del self.__student2

    def testController(self):
        assert (len(self.__ctrl.getAll()) == 0)
        self.__ctrl.add(self.__student1.studentID, self.__student1.studentName)
        assert (len(self.__ctrl.getAll()) == 1)
        try:
            self.__ctrl.add(self.__student2.studentID,
                            self.__student2.studentName)
        except StudentControllerException:
            pass
Example #6
0
elif whatRepo == 'binaryfiles':
    fileName = extractName(f.readline().strip())
    studentsRepository = StudentsPickleRepository(fileName)

    fileName = extractName(f.readline().strip())
    disciplineRepository = DisciplinesPickleRepository(fileName)

    fileName = extractName(f.readline().strip())
    gradesRepository = GradesPickleRepository(fileName)

f.close()

undoController = UndoController()
undoController.newOperation()
students = StudentController(studentsRepository, undoController,
                             gradesRepository)
disciplines = DisciplineController(disciplineRepository, undoController,
                                   gradesRepository)
grades = GradesController(studentsRepository, disciplineRepository,
                          gradesRepository, undoController)

ui = UI(students, disciplines, grades, undoController)


def generateStudents():
    undoController.newOperation(), students.store(Student(
        123, 'Andrei Stefan'))
    undoController.newOperation(), students.store(
        Student(124, 'Cosmin Iordache'))
    undoController.newOperation(), students.store(Student(
        125, 'Simon Claudiu'))
Example #7
0
 def setUp(self):
     self.v = StudentValidator()
     self.s = Student("1", "Marcel")
     self.r = Repository()
     self.c = StudentController(self.r, self.v)
Example #8
0
class StudentTestCase(unittest.TestCase):
    def setUp(self):
        self.v = StudentValidator()
        self.s = Student("1", "Marcel")
        self.r = Repository()
        self.c = StudentController(self.r, self.v)

    '''
    testing the student class(not controller)
    '''

    def testStudentValidator(self):
        self.assertTrue(self.v.validate, self.s)
        self.s.name = ""
        self.assertRaises(ValidatorException, self.v.validate, self.s)
        self.s.name = None
        self.assertRaises(ValidatorException, self.v.validate, self.s)
        self.s.name = "an12a"
        self.assertRaises(ValidatorException, self.v.validate, self.s)

    '''
    Student controller test
    '''

    def test(self):
        '''
        Test add student
        '''
        self.c.addStudent("1", "Ana")
        self.assertEqual(len(self.c), 1)
        self.assertRaises(RepositoryException, self.c.addStudent, "1", "Again")
        self.assertEqual(len(self.c), 1)
        self.assertRaises(ValidatorException, self.c.addStudent, "3", "A71nc")
        self.c.addStudent("2", "Ion")
        self.assertRaises(ValidatorException, self.c.addStudent, "2", "")
        self.c.addStudent("3", "George")
        self.assertEqual(len(self.c), 3)
        '''
        Test remove student
        '''
        self.c.removeStudent("1")
        self.assertEqual(len(self.c), 2)
        self.assertRaises(RepositoryException, self.c.removeStudent, "1")
        self.assertRaises(RepositoryException, self.c.removeStudent, "random")
        self.c.removeStudent("2")
        self.assertEqual(len(self.c), 1)
        self.assertTrue(self.c.removeStudent, "1")
        self.assertEqual(len(self.c), 1)
        '''
        Test update student
        '''
        self.c.addStudent("2", "Gigi")
        self.assertEqual(len(self.c), 2)
        self.c.updateStudent("2", "CoolName")
        self.assertEqual(len(self.c), 2)
        self.assertRaises(RepositoryException, self.c.updateStudent, "1",
                          "Ana")
Example #9
0
from controller.GradeController import GradeController
from controller.StudentController import StudentController
from controller.UndoController import UndoController
from domain.validators import GradeValidator, StudentValidator
from repository.GradeRepo import GradeRepo
from repository.StudentRepo import StudentRepo

if __name__ == '__main__':
    print("App started running.")

    grade_validator = GradeValidator()
    student_validator = StudentValidator()

    grade_repo = GradeRepo(grade_validator)
    student_repo = StudentRepo(student_validator)

    grade_controller = GradeController(grade_repo)
    student_controller = StudentController(student_repo)
    undo_controller = UndoController(student_controller, grade_controller)

    console = Console(student_controller, grade_controller, undo_controller)

    try:
        console.run()
    except Exception:
        print("An error accured.")
        traceback.print_exc()

    print("That's all folks.")

 def __init__(self, undoController, studentRepo, studentValidator,
              gradeController):
     StudentController.__init__(self, studentRepo, studentValidator)
     self._undoController = undoController
     self._gradeController = gradeController
Example #11
0
 def setUp(self):
     studentValidator = StudentValidator()
     studentRepo = Repository()
     self._ctrl = StudentController(studentRepo,studentValidator)
from domain.Student import Student
from domain.Student import StudentValidator
from controller.StudentController import StudentController
from repository.FileRepository import FileRepository


class StudentRandomDataGenerator:
    def __init__(self, studentController):
        self._studentController = studentController

    def addData(self):
        with open(r"C:\Users\Denis\Desktop\random data gener\students.txt",
                  "r") as f:
            lines = f.readlines()
            ident = uuid.uuid4().hex  # get random id
            lenLines = len(lines)
            studentNr = random.randint(0, lenLines)
            try:
                self._studentController.addStudent(str(ident),
                                                   lines[studentNr])
            except:
                pass


sv = StudentValidator()
sr = FileRepository(r"C:\Users\Denis\Desktop\random data gener\blabla.txt",
                    Student)
sc = StudentController(sr, sv)
s = StudentRandomDataGenerator(sc)
s.addData()
 def setUp(self):
     self.__repo = StudentRepository()
     self.__ctrl = StudentController(self.__repo)
     self.__student1 = Student(1, "Anna")
     self.__student2 = Student("", "Mary")
Example #14
0
    print("\nChoose what kind of repository you want to use \n")
    print("1 - inmemory repository")
    print("2 - text file repository")
    print("3 - binary file repository")
    print("0 - to exit")
    repository_mode = int(input("\nYour choice for repository is: "))
    if repository_mode == 1:
        studentValidator = StudentValidator()
        disciplineValidator = DisciplineValidator()
        gradeValidator = GradeValidator()

        studentRepo = StudentRepository()
        disciplineRepo = DisciplineRepository()
        gradeRepo = GradeRepository()

        studentController = StudentController(studentRepo)
        disciplineController = DisciplineController(disciplineRepo)
        gradeController = GradeController(gradeRepo, disciplineRepo,
                                          studentRepo)

        ui = ConsoleUI(studentController, disciplineController,
                       gradeController)
        opt = ui.runApp()
        if opt == 0:
            break

    elif repository_mode == 2:
        studentValidator = StudentValidator()
        disciplineValidator = DisciplineValidator()
        gradeValidator = GradeValidator()