def testStudentRepo_statistics_students_best_situation(self): self._students = StudentRepo() self._disciplines = DisciplineRepo() self._grades = GradeRepo() self.__superService = SuperService(self._students, self._disciplines, self._grades) self._students.add_student(56, "Hill Nina") self._students.add_student(90, "Hol Guara") self._students.add_student(120, "Alex Cerg") self._disciplines.add_discipline(87, "Maths") self._disciplines.add_discipline(234, "Logic") self._disciplines.add_discipline(99, "Art") self._grades.add_grade(87, 56, 10) #2 self._grades.add_grade(87, 56, 3) self._grades.add_grade(99, 120, 4) #1 self._grades.add_grade(234, 120, 10) result = [] result = self.__superService.students_best_situation() result2 = [] result2.append(Student(120, "Alex Cerg")) result2.append(Student(56, "Hill Nina")) self.assertEqual(result[0].studentId, result2[0].studentId) self.assertEqual(result[0].studentName, result2[0].studentName) self.assertEqual(result[1].studentId, result2[1].studentId) self.assertEqual(result[1].studentName, result2[1].studentName)
def testDisciplineRepo_disciplines_with_grades(self): self._students = StudentRepo() self._disciplines = DisciplineRepo() self._grades = GradeRepo() self.__superService = SuperService(self._students, self._disciplines, self._grades) self._students.add_student(56, "Hill Nina") self._students.add_student(90, "Hol Guara") self._students.add_student(120, "Alex Cerg") self._disciplines.add_discipline(87, "Maths") self._disciplines.add_discipline(234, "Logic") self._disciplines.add_discipline(99, "Art") self._disciplines.add_discipline(178, "Chemestry") self._grades.add_grade(87, 56, 10) self._grades.add_grade(87, 56, 3) self._grades.add_grade(99, 120, 4) self._grades.add_grade(234, 120, 10) result = [] result = self.__superService.disciplines_with_grades() result2 = [] result2.append(Discipline(234, "Logic")) result2.append(Discipline(87, "Maths")) result2.append(Discipline(99, "Art")) self.assertEqual(result[0].disciplineId, result2[0].disciplineId) self.assertEqual(result[0].disciplineName, result2[0].disciplineName) self.assertEqual(result[1].disciplineId, result2[1].disciplineId) self.assertEqual(result[1].disciplineName, result2[1].disciplineName)
def testGradeRepo_addGrade(self): self._students = StudentRepo() self._disciplines = DisciplineRepo() self._grades = GradeRepo() self._students.add_student(56, "Hill Nina") self._students.add_student(30, "Christina Shepherd") self._disciplines.add_discipline(78, "Maths") self._disciplines.add_discipline(120, "Physics") self._grades.add_grade(78, 30, 7) self.assertEqual(len(self._grades.getAll()), 1) self._grades.add_grade(120, 56, 10) self.assertEqual(len(self._grades.getAll()), 2)
def _loadFile(self): filepath = self._fileName try: f = open(filepath, "r") line = f.readline().strip() while len(line) > 0: line = line.split(",") GradeRepo.add_grade(self,Grade(int(line[0]), int(line[1]), int(line[2]), int(line[3]))) line = f.readline().strip() f.close() except IOError as e: """ Here we 'log' the error, and throw it to the outer layers """ print("An error occured - " + str(e)) raise e
def _saveFile(self): ''' 1. Open text file for writing 'w' 2. for each car in the repository: a. transform it into one-line string b. write it to the file 3. close file ''' filepath = self._fileName f = open(filepath, 'w') line = "" for grade in GradeRepo.getAll(self): line = "" line += str(grade.gradeId) + "," + str(grade.disciplineId) + "," + str(grade.studentId) + "," + str(grade.gradeValue) + "\n" f.write(line) f.close()
class TestsSecondFunctionality(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) def testGradeRepo_addGrade(self): self._students = StudentRepo() self._disciplines = DisciplineRepo() self._grades = GradeRepo() self._students.add_student(56, "Hill Nina") self._students.add_student(30, "Christina Shepherd") self._disciplines.add_discipline(78, "Maths") self._disciplines.add_discipline(120, "Physics") self._grades.add_grade(78, 30, 7) self.assertEqual(len(self._grades.getAll()), 1) self._grades.add_grade(120, 56, 10) self.assertEqual(len(self._grades.getAll()), 2)
class TestsForthFunctionality(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) def testStudentRepo_statistics_students_failing(self): self._students = StudentRepo() self._disciplines = DisciplineRepo() self._grades = GradeRepo() self.__superService = SuperService(self._students, self._disciplines, self._grades) self._students.add_student(56, "Hill Nina") self._students.add_student(90, "Hol Guara") self._students.add_student(120, "Alex Cerg") self._disciplines.add_discipline(87, "Maths") self._disciplines.add_discipline(234, "Logic") self._disciplines.add_discipline(99, "Art") self._grades.add_grade(87, 56, 10) self._grades.add_grade(87, 56, 3) self._grades.add_grade(99, 120, 4) #student 120 should be in the result self._grades.add_grade(234, 120, 10) result = [] result = self.__superService.students_failing() result2 = [] result2.append(Student(120, "Alex Cerg")) self.assertEqual(result[0].studentId, result2[0].studentId) self.assertEqual(result[0].studentName, result2[0].studentName) def testStudentRepo_statistics_students_best_situation(self): self._students = StudentRepo() self._disciplines = DisciplineRepo() self._grades = GradeRepo() self.__superService = SuperService(self._students, self._disciplines, self._grades) self._students.add_student(56, "Hill Nina") self._students.add_student(90, "Hol Guara") self._students.add_student(120, "Alex Cerg") self._disciplines.add_discipline(87, "Maths") self._disciplines.add_discipline(234, "Logic") self._disciplines.add_discipline(99, "Art") self._grades.add_grade(87, 56, 10) #2 self._grades.add_grade(87, 56, 3) self._grades.add_grade(99, 120, 4) #1 self._grades.add_grade(234, 120, 10) result = [] result = self.__superService.students_best_situation() result2 = [] result2.append(Student(120, "Alex Cerg")) result2.append(Student(56, "Hill Nina")) self.assertEqual(result[0].studentId, result2[0].studentId) self.assertEqual(result[0].studentName, result2[0].studentName) self.assertEqual(result[1].studentId, result2[1].studentId) self.assertEqual(result[1].studentName, result2[1].studentName) def testDisciplineRepo_disciplines_with_grades(self): self._students = StudentRepo() self._disciplines = DisciplineRepo() self._grades = GradeRepo() self.__superService = SuperService(self._students, self._disciplines, self._grades) self._students.add_student(56, "Hill Nina") self._students.add_student(90, "Hol Guara") self._students.add_student(120, "Alex Cerg") self._disciplines.add_discipline(87, "Maths") self._disciplines.add_discipline(234, "Logic") self._disciplines.add_discipline(99, "Art") self._disciplines.add_discipline(178, "Chemestry") self._grades.add_grade(87, 56, 10) self._grades.add_grade(87, 56, 3) self._grades.add_grade(99, 120, 4) self._grades.add_grade(234, 120, 10) result = [] result = self.__superService.disciplines_with_grades() result2 = [] result2.append(Discipline(234, "Logic")) result2.append(Discipline(87, "Maths")) result2.append(Discipline(99, "Art")) self.assertEqual(result[0].disciplineId, result2[0].disciplineId) self.assertEqual(result[0].disciplineName, result2[0].disciplineName) self.assertEqual(result[1].disciplineId, result2[1].disciplineId) self.assertEqual(result[1].disciplineName, result2[1].disciplineName)
undoController = UndoController() # loading settings.properties filepath = "settingstext.properties" try: f = open(filepath, "r") line = f.readline().strip() #reading line 1 repository = ... line = line.split(" ") if line[2] == "inmemory": #using in-memory repositories studentRepo = StudentRepo() disciplineRepo = DisciplineRepo() gradeRepo = GradeRepo(studentRepo, disciplineRepo) studentRepo.init_students() disciplineRepo.init_disciplines() gradeRepo.init_grades() elif line[2] == "text": from StudentTextRepo import StudentTextRepository from DisciplineTextRepo import DisciplineTextRepository from GradeTextRepo import GradeTextRepository line = f.readline().strip() #reading line 2 students = ... line = line.split(" ") studentRepo = StudentTextRepository(line[2]) line = f.readline().strip() #reading line 3 disciplines = ...
def add_grade(self, obj): self._grades = [] self._loadFile() GradeRepo.add_grade(self, obj) self._saveFile()
def __init__(self, studentRepo, disciplineRepo, fileName): GradeRepo.__init__(self, studentRepo, disciplineRepo) self._fileName = fileName self._loadFile()
def remove_grade(self, grade_id): self._grades = [] self._loadFile() removed_grade = GradeRepo.remove_grade(self, grade_id) self._saveFile() return removed_grade