def setUp(self): super.setUp() self.__student_repo = Repository(StudentValidator) self.__link_repo = Repository(LinkValidator) self.__grade_repo = Repository(GradeValidator) self.__disc_repo = Repository(DisciplineValidator) self.__undo_controller = UndoController(self.__student_repo, self.__link_repo, self.__grade_repo, self.__disc_repo)
def setUp(self): super().setUp() self.__student_repository = Repository(StudentValidator) self.__discipline_repository = Repository(DisciplineValidator) self.__link_repository = Repository(LinkValidator) self.__link_controller = LinkController(self.__student_repository, self.__discipline_repository, self.__link_repository)
class TestLinkController(TestCase): def setUp(self): super().setUp() self.__student_repository = Repository(StudentValidator) self.__discipline_repository = Repository(DisciplineValidator) self.__link_repository = Repository(LinkValidator) self.__link_controller = LinkController(self.__student_repository, self.__discipline_repository, self.__link_repository) def test_add_link(self): self.__link_controller.add_link(1, 1) self.assertEqual(len(self.__link_controller.get_all()), 1, "Not ok") def test_get_all(self): self.__link_controller.add_link(1, 1) self.assertEqual(len(self.__link_controller.get_all()), 1, "Not ok") def test_find_by_id(self): self.__link_controller.add_link(1, 1) self.assertEqual(self.__link_controller.find_by_id("1.2"), None, "Not ok") def test_handle_delete_student(self): self.__link_controller.add_link(1, 1) self.__link_controller.handle_delete_student(1) self.assertEqual(len(self.__link_controller.get_all()), 0, "Not ok") def test_handle_delete_discipline(self): self.__link_controller.add_link(1, 1) self.__link_controller.handle_delete_discipline(1) self.assertEqual(len(self.__link_controller.get_all()), 0, "Not ok") def test_get_student_and_name_dtos(self): self.__link_controller.add_link(1, 1) self.__student_repository.save(Student(1, "Stefan")) self.__discipline_repository.save(Discipline(1, "Math")) dtos = self.__link_controller.get_student_and_name_dtos() self.assertEqual(len(dtos), 1, "Len not ok") self.assertEqual(dtos[0].student_name, "Stefan", "Stud not ok") self.assertEqual(dtos[0].discipline_name, "Math", "Disc not ok")
def __init__(self, discipline_validator, file_name): Repository.__init__(self, discipline_validator) self.__file_name = file_name
from studentRegister.repository.StudentPickleRepository import StudentPickleRepository from studentRegister.repository.repository import Repository from studentRegister.repository.undo_repository import OperationsRepository from studentRegister.ui.console import Console from studentRegister.ui.gui import GUI from studentRegister.ui.ui_handlers import UiHandleStudentCommands, UiHandleDisciplineCommands, UiHandleLinkCommands, \ UiHandleGradeCommands, UiHandleStatisticsCommands, UiHandleUndoCommands if __name__ == "__main__": print("App started running.") try: settings_file = Settings("settings.properties") repository = settings_file.repository if repository == "inmemory": student_repository = Repository(StudentValidator) discipline_repository = Repository(DisciplineValidator) elif repository == "textfiles": student_file = settings_file.student_file discipline_file = settings_file.discipline_file student_repository = StudentFileRepository(StudentValidator, student_file) discipline_repository = DisciplineFileRepository( DisciplineValidator, discipline_file) elif repository == "binaryfiles": student_file = settings_file.student_file discipline_file = settings_file.discipline_file student_repository = StudentPickleRepository( StudentValidator, student_file) discipline_repository = DisciplinePickleRepository( DisciplineValidator, discipline_file)
def setUp(self): super().setUp() discipline_repository = Repository(DisciplineValidator) self.__discipline_controller = DisciplineController(discipline_repository)
def __init__(self, student_validator, file_name): Repository.__init__(self, student_validator) self.__file_name = file_name
def setUp(self): super().setUp() self.__student_repository = Repository(StudentValidator) self.__discipline_repository = Repository(DisciplineValidator) self.__grade_repository = Repository(GradeValidator) self.__grade_controller = GradeController(self.__student_repository, self.__discipline_repository, self.__grade_repository)
def setUp(self): super().setUp() student_repository = Repository(StudentValidator) self.__student_controller = StudentController(student_repository)
def setUp(self): super().setUp() self.__repository = Repository(StudentValidator) self.__grade_repo = Repository(GradeValidator)
class TestRepository(TestCase): def setUp(self): super().setUp() self.__repository = Repository(StudentValidator) self.__grade_repo = Repository(GradeValidator) def test_save(self): student1 = Student(1, "Stefan") self.__repository.save(student1) self.assertEqual(len(self.__repository.get_all()), 1, "There should be one product in the repo") student2 = Student(1, "Dragos") self.assertRaises(RepositoryException, self.__repository.save, student2) student3 = Student("1", "Stefan") self.assertRaises(StudentValidatorException, self.__repository.save, student3) def test_find_by_id(self): student = Student(1, "Stefan") self.__repository.save(student) result = self.__repository.find_by_id(1) self.assertEqual(result, student, "Entities not equal") result = self.__repository.find_by_id(2) self.assertEqual(result, None, "Entities not equal") def test_update(self): student = Student(1, "Stefan") self.__repository.save(student) student_new = Student(1, "Adi") self.assertRaises(RepositoryException, self.__repository.update, 2, student_new) self.__repository.update(1, student_new) for item in self.__repository.get_all(): self.assertEqual(student_new, item, "Error") def test_delete_by_id(self): student = Student(1, "Stefan") self.__repository.save(student) self.assertRaises(RepositoryException, self.__repository.delete_by_id, 2) self.__repository.delete_by_id(1) self.assertEqual(len(self.__repository.get_all()), 0, "Error at delete") self.assertRaises(RepositoryException, self.__repository.delete_by_id, 1) def test_find_by_name(self): student1 = Student(1, "Adrian") student2 = Student(2, "Stefan") self.__repository.save(student1) self.__repository.save(student2) self.assertEqual(len(self.__repository.find_by_name("an")), 2, "Not ok") self.assertEqual(len(self.__repository.find_by_name("Stefan")), 1, "Not ok") self.assertEqual(len(self.__repository.find_by_name("Cristian")), 0, "Not ok") def test_get_all_grades_by_discipline(self): grade1 = Grade(1, 1, 10) grade2 = Grade(1, 2, 10) grade3 = Grade(2, 1, 10) self.__grade_repo.save(grade1) self.__grade_repo.save(grade2) self.__grade_repo.save(grade3) self.assertEqual( len(self.__grade_repo.get_all_grades_by_discipline(1)), 2, "Not ok") self.assertEqual( len(self.__grade_repo.get_all_grades_by_discipline(2)), 1, "Not ok") def test_get_all_grades_by_student(self): grade1 = Grade(1, 1, 10) grade2 = Grade(1, 2, 10) grade3 = Grade(2, 1, 10) self.__grade_repo.save(grade1) self.__grade_repo.save(grade2) self.__grade_repo.save(grade3) self.assertEqual(len(self.__grade_repo.get_all_grades_by_student(1)), 2, "Not ok") self.assertEqual(len(self.__grade_repo.get_all_grades_by_student(2)), 1, "Not ok")