Exemple #1
0
 def setUp(self):
     super().setUp()
     self.__student_repository = Repository(StudentValidator)
     self.__student_controller = StudentController(
         self.__student_repository)
     self.__discipline_repository = Repository(DisciplineValidator)
     self.__discipline_controller = DisciplineController(
         self.__discipline_repository)
     self.__grade_repository = Repository(GradeValidator)
     self.__grade_controller = GradeController(self.__grade_repository,
                                               self.__student_repository,
                                               self.__discipline_repository)
    def initialise(self):
        self.student_repository = Repository(StudentValidator)
        self.discipline_repository = Repository(DisciplineValidator)
        self.grade_repository = GradesRepository(GradeValidator)
        self.student_controller = StudentController(self.student_repository)
        self.discipline_controller = DisciplineController(
            self.discipline_repository)
        self.grade_controller = GradeController(self.grade_repository,
                                                self.student_repository,
                                                self.discipline_repository)

        self.student_controller.add_student(1, 'George')
        self.student_controller.add_student(2, 'Ada')
        self.student_controller.add_student(3, 'Ana')
        self.student_controller.add_student(4, 'Maria')
        self.student_controller.add_student(5, 'Vlad')

        self.discipline_controller.add_discipline(1, 'mate')
        self.discipline_controller.add_discipline(2, 'info')
def runApplicationWithUndo():
    settings = Settings()
    undoController = UndoController()

    if str(settings.mode_repository) == "inmemory":
        student_repository = Repository(StudentValidator)
        discipline_repository = Repository(DisciplineValidator)
        grade_repository = Repository(GradeValidator)

    elif settings.mode_repository == "textfiles":
        student_repository = FileRepository(StudentValidator, settings.students, Student)
        discipline_repository = FileRepository(DisciplineValidator, settings.disciplines, Discipline)
        grade_repository = FileRepository(GradeValidator, settings.grades, Grade)

    elif settings.mode_repository == "binaryfiles":
        student_repository = BinaryRepository(StudentValidator, settings.students, Student)
        discipline_repository = BinaryRepository(DisciplineValidator, settings.disciplines, Discipline)
        grade_repository = BinaryRepository(GradeValidator, settings.grades, Grade)


    elif settings.mode_repository == "sqlfiles":
        student_repository = SQLRepository(StudentValidator, settings.students, Student, "Students", 1)
        discipline_repository = SQLRepository(DisciplineValidator, settings.disciplines, Discipline, "Disciplines", 1)
        grade_repository = SQLRepository(GradeValidator, settings.grades, Grade, "Grades", 2)



    elif settings.mode_repository == "jsonfiles":
        student_repository = JSONRepository(StudentValidator, settings.students, Student)
        discipline_repository = JSONRepository(DisciplineValidator, settings.disciplines, Discipline)
        grade_repository = JSONRepository(GradeValidator, settings.grades, Grade)

    else:
        print("You have to insert a valid repository mode!!!")

    student_controller = StudentController(student_repository, undoController)
    discipline_controller = DisciplineController(discipline_repository, undoController)
    grade_controller = GradeController(grade_repository, student_repository, discipline_repository, undoController)

    if settings.interface_mode == "gui":
        ui_gui = GUI(student_controller, discipline_controller, grade_controller, undoController)
        ui_gui.run_app()
    elif settings.interface_mode == "console":
        console = Console(student_controller, discipline_controller, grade_controller, undoController)
        console.runApp()
    else:
        print("You have to insert a valid interface!!!")
Exemple #4
0
class TestDisciplineController(unittest.TestCase):

    validator = DisciplineValidator
    repository = Repository(validator)
    controller = DisciplineController(repository)

    def test_add_discipline(self):

        self.controller.add_discipline(1, 'mate')
        self.assertGreater(len(self.repository.get_all()), 0,
                           'The item was not appended')
        print('Tested adding a discipline')

    def test_find_by_name(self):

        self.assertEqual(len(self.controller.find_by_name('mate')), 1,
                         'item should have been found')
        self.assertEqual(len(self.controller.find_by_name('fp')), 0,
                         'item should have not been found')
        print('Tested finding a discipline by name')

    def test_get_all(self):

        self.assertEqual(len(self.controller.get_all()), 1,
                         'wrong number of objects returned')
        print('Tested getting all disciplines')

    def test_remove_by_id(self):
        try:
            self.controller.remove_by_id(2)
            assert False
        except RepositoryException:
            assert True

        self.controller.remove_by_id(1)
        self.assertEqual(len(self.controller.get_all()), 0,
                         'item should have been deleted')

    def test_update(self):
        self.controller.add_discipline(2, 'fp')
        self.controller.update(2, 'mate')
        self.assertEqual(len(self.controller.find_by_name('mate')), 1,
                         'item was not succesfuly updated')
        print('Tested updating a discipline')
Exemple #5
0
class TestGradeController(TestCase):
    def setUp(self):
        super().setUp()
        self.__student_repository = Repository(StudentValidator)
        self.__student_controller = StudentController(
            self.__student_repository)
        self.__discipline_repository = Repository(DisciplineValidator)
        self.__discipline_controller = DisciplineController(
            self.__discipline_repository)
        self.__grade_repository = Repository(GradeValidator)
        self.__grade_controller = GradeController(self.__grade_repository,
                                                  self.__student_repository,
                                                  self.__discipline_repository)

    def test_checkExistentIdInRepository(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['1', "Corina"]
        self.__student_controller.addStudent(args)
        args = ["1", "1", 2]
        self.__grade_controller.addGrade(args)
        gr1 = Grade("1", "2", '8')
        # self.assertRaises(GradeValidatorException, self.__grade_controller.checkExistentIdInRepository, gr1, self.__student_repository, self.__discipline_repository)

    def test_addGrade(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['1', "Corina"]
        self.__student_controller.addStudent(args)
        args = ["1", "1", 2]
        self.__grade_controller.addGrade(args)
        self.assertEqual(
            self.__grade_controller.get_all_grade()[0].grade_value, 2)

    def test_get_all_grade(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['1', "Corina"]
        self.__student_controller.addStudent(args)
        args = ["1", "1", 2]
        self.__grade_controller.addGrade(args)
        self.assertEqual(len(self.__grade_controller.get_all_grade()), 1)

    def test_remove_by_studentID(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['1', "Corina"]
        self.__student_controller.addStudent(args)
        args = ["1", "1", 2]
        self.__grade_controller.addGrade(args)
        self.__grade_controller.remove_by_studentID([1])
        self.assertEqual(len(self.__grade_controller.get_all_grade()), 0)

    def test_remove_by_disciplineID(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['1', "Corina"]
        self.__student_controller.addStudent(args)
        args = ["1", "1", 2]
        self.__grade_controller.addGrade(args)
        self.__grade_controller.remove_by_disciplineID([1])
        self.assertEqual(len(self.__grade_controller.get_all_grade()), 0)

    def test_getStudentsAtDiscipline(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['2', "OOP"]
        self.__discipline_controller.addDiscipline(args)
        args = ['1', "Corina"]
        self.__student_controller.addStudent(args)
        args = ['2', "Ana"]
        self.__student_controller.addStudent(args)
        args = ["1", "1", 2]
        self.__grade_controller.addGrade(args)
        args = ["1", "2", 7]
        self.__grade_controller.addGrade(args)
        args = ["2", "1", 2]
        self.__grade_controller.addGrade(args)
        args = ["2", "2", 7]
        self.__grade_controller.addGrade(args)
        self.assertRaises(ValueError,
                          self.__grade_controller.getStudentsAtDiscipline, "a")
        self.assertEqual(self.__grade_controller.getStudentsAtDiscipline(1), {
            '1': 2,
            '2': 7
        })
        self.assertRaises(ValueError,
                          self.__grade_controller.getStudentsAtDiscipline, "a")

    def test_getFallenStudents(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['1', "Corina"]
        self.__student_controller.addStudent(args)
        args = ["1", "1", 2]
        self.__grade_controller.addGrade(args)
        self.assertEqual(self.__grade_controller.getFallenStudents(), {'1': 0})

    def test_getBestStudents(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['3', "OOP"]
        self.__discipline_controller.addDiscipline(args)
        args = ['1', "Corina"]
        self.__student_controller.addStudent(args)
        args = ['2', "Corina"]
        self.__student_controller.addStudent(args)
        args = ["1", "1", 2]
        self.__grade_controller.addGrade(args)
        args = ["1", "2", 9]
        self.__grade_controller.addGrade(args)
        args = ["3", "2", 8]
        self.__grade_controller.addGrade(args)
        self.assertEqual(self.__grade_controller.getBestStudents(), {
            '2': 8.5,
            '1': 2
        })

    def test_getBestDisciplines(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['3', "OOP"]
        self.__discipline_controller.addDiscipline(args)
        args = ['1', "Corina"]
        self.__student_controller.addStudent(args)
        args = ['2', "Corina"]
        self.__student_controller.addStudent(args)
        args = ["1", "1", 2]
        self.__grade_controller.addGrade(args)
        args = ["1", "2", 9]
        self.__grade_controller.addGrade(args)
        args = ["3", "1", 9]
        self.__grade_controller.addGrade(args)
        args = ["3", "2", 3]
        self.__grade_controller.addGrade(args)

        self.assertEqual(self.__grade_controller.getBestDisciplines(), {
            1: 5.5,
            3: 6.0
        })

    def test_backup_op(self):
        assert (self.__grade_controller.backup_op() == None)

    def test_undo_op(self):
        assert (self.__grade_controller.undo_op() == None)

    def test_redo_op(self):
        assert (self.__grade_controller.redo_op(False) == None)
Exemple #6
0
            student_repository = PickleRepository(StudentValidator,
                                                  settings['students'],
                                                  Student)
            discipline_repository = PickleRepository(DisciplineValidator,
                                                     settings['disciplines'],
                                                     Discipline)
            grade_repository = PickleRepository(GradeValidator,
                                                settings['grades'], Grade)
            enroll_repository = PickleRepository(EnrollValidator,
                                                 settings['enroll'], Link)

        enroll_controller = EnrolledController(enroll_repository,
                                               student_repository,
                                               discipline_repository)
        student_controller = StudentController(student_repository)
        discipline_controller = DisciplineController(discipline_repository)
        grade_controller = GradeController(grade_repository,
                                           student_repository,
                                           discipline_repository,
                                           enroll_controller)

        undo_redo_controller = UndoRedoController(student_repository,
                                                  discipline_repository,
                                                  grade_repository,
                                                  enroll_controller)

        if settings['ui'] == 'command':
            console = Console(student_controller, grade_controller,
                              discipline_controller, enroll_controller,
                              undo_redo_controller)
 def setUp(self):
     super().setUp()
     self.__discipline_repository = Repository(DisciplineValidator)
     self.__discipline_controller = DisciplineController(
         self.__discipline_repository)
class TestDisciplineController(TestCase):
    def setUp(self):
        super().setUp()
        self.__discipline_repository = Repository(DisciplineValidator)
        self.__discipline_controller = DisciplineController(
            self.__discipline_repository)

    def test_addDiscipline(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        self.assertEqual(
            self.__discipline_controller.get_all_discipline()[0].name, "Mate",
            "Name it should be Mate")

    def test_get_all_discipline(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        lst = self.__discipline_controller.get_all_discipline()
        self.assertEqual(lst[0].name, "Mate", "It should be Mate")

    def test_get_all_id(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        self.assertEqual(self.__discipline_controller.get_all_id(), [1],
                         "It should be [1]")

    def test_removeDiscipline(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        self.__discipline_controller.removeDiscipline([1])
        self.assertEqual(
            len(self.__discipline_controller.get_all_discipline()), 0,
            "The list is empty")

    def test_updateDiscipline(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['1', "OOP"]
        self.__discipline_controller.updateDiscipline(args)
        self.assertEqual(
            self.__discipline_controller.get_all_discipline()[0].name, "OOP",
            "Name it should be OOP")

    def test_searchByID(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        self.assertEqual(
            self.__discipline_controller.searchByID(1)[0].name, "Mate",
            "The name must be Mate")
        self.assertEqual(self.__discipline_controller.searchByID(2), [],
                         "None")

    def test_searchByName(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['15', "Matematica"]
        self.__discipline_controller.addDiscipline(args)
        self.assertEqual(
            self.__discipline_controller.searchByName("ate")[1].name,
            "Matematica")

    def test_searchDisciplines(self):
        args = ['1', "Mate"]
        self.__discipline_controller.addDiscipline(args)
        args = ['15', "Matematica"]
        self.__discipline_controller.addDiscipline(args)
        self.assertEqual(
            self.__discipline_controller.searchDisciplines(['15'])[0].name,
            "Matematica")
        self.assertEqual(
            self.__discipline_controller.searchDisciplines(["ate"])[1].name,
            "Matematica")

    def test_backup_op(self):
        assert (self.__discipline_controller.backup_op() == None)

    def test_undo_op(self):
        assert (self.__discipline_controller.undo_op() == None)

    def test_redo_op(self):
        assert (self.__discipline_controller.redo_op(False) == None)
class TestGradeController(unittest.TestCase):
    def initialise(self):
        self.student_repository = Repository(StudentValidator)
        self.discipline_repository = Repository(DisciplineValidator)
        self.grade_repository = GradesRepository(GradeValidator)
        self.student_controller = StudentController(self.student_repository)
        self.discipline_controller = DisciplineController(
            self.discipline_repository)
        self.grade_controller = GradeController(self.grade_repository,
                                                self.student_repository,
                                                self.discipline_repository)

        self.student_controller.add_student(1, 'George')
        self.student_controller.add_student(2, 'Ada')
        self.student_controller.add_student(3, 'Ana')
        self.student_controller.add_student(4, 'Maria')
        self.student_controller.add_student(5, 'Vlad')

        self.discipline_controller.add_discipline(1, 'mate')
        self.discipline_controller.add_discipline(2, 'info')

    def setUp(self):
        unittest.TestCase.setUp(self)
        self.initialise()

    def test_enroll_student(self):
        self.grade_controller.enroll_student(3, 1)
        self.grade_controller.enroll_student(1, 2)
        self.grade_controller.enroll_student(1, 1)
        self.grade_controller.enroll_student(2, 1)
        self.grade_controller.enroll_student(2, 2)
        self.grade_controller.enroll_student(3, 2)
        print(len(self.grade_controller.GradeController__enrolled))
        self.assertEqual(len(self.grade_controller.GradeController__enrolled),
                         6, 'students not successfully enrolled')

        print('tested enrolling a student to a discipline')

    def test_add_grade(self):
        self.initialise()
        self.grade_controller.enroll_student(1, 2)
        print(self.student_controller.get_all())
        self.grade_controller.add_grade(1, 2, 10)
        self.assertEqual(len(self.grade_controller.get_all()), 1,
                         ' grade not added')

        print('tested giving grades to students')

    def test_update_grade(self):
        self.grade_controller.update_grade(1, 2, 10, 9)
        #self.assertEqual(self.grade_repository.find_by_id(1, 2)

    def test_get_enrolled_disciplines_for_student(self):
        try:
            self.grade_controller.enroll_student(1, 2)
        except:
            pass
        self.assertEqual(
            len(self.grade_controller.get_enrolled_disciplines_for_student(1)),
            1, 'incorrect enrolling for student')

        print('tested getting enrolled disciplines for student')

    def test_get_enrolled_students_for_discipline(self):
        self.grade_controller.enroll_student(1, 2)
        print(self.grade_controller.get_enrolled_students_for_discipline(2))
        self.assertEqual(
            len(self.grade_controller.get_enrolled_students_for_discipline(2)),
            1,
            len(self.grade_controller.get_enrolled_students_for_discipline(2)))

        print('tested get enrolled students for discipline')

    def test_disenroll_studnet(self):
        self.grade_controller.disenroll_student(1, 2)
        self.assertEqual(
            len(self.grade_controller.get_enrolled_disciplines_for_student(1)),
            0, 'dissenrolling student did not work')

        print('tested disenrolling student from discipline')

    def test_disenroll_student_all(self):

        print('tested disenrolling student from all disciplines')

    def test_disenroll_discipline_all(self):

        print('tested disenrolling discipline from all students')

    def test_get_all(self):

        print('tested getting all grades')

    def test_remove_by_student_id(self):

        print('tested removing by student id')

    def test_remove_by_value(self):

        print('tested removing by value')

    def test_remove_by_dicipline_id(self):

        print('tested removing by discipline id')

    def test_remove(self):

        print('tested removing by grade entity')

    def test_get_students_sorted_by_discipline(self):

        print('tested geting students sorted by discipline')

    def test_get_students_sorted_alphabetically(self):

        print('tested geting students sorted alphabetically')

    def test_aggregated_avg(self):

        print('tested computing aggregated average for student')

    def test_aggregated_avg_d(self):

        print('tested computing aggregated average for discipline')

    def test_get_best_students(self):

        print('tested getting best students')

    def test_get_best_disciplines(self):

        print('tested gettig best discipline')

    def test_get_failing_students(self):

        print('tested getting failing students')

    def test_get_grades_for_student(self):

        print('tested getting grades for student')

    def test_get_grades_for_discipline(self):

        print('tested getting grades for discipline')