def setUp(self):
     courses = CourseRepository()
     self.course1 = Course(1, "Asc", "Vancea")
     self.course2 = Course(2, "Fp", "I")
     self.course3 = Course(3, "Logica", "Pop")
     courses.save(self.course1)
     courses.save(self.course2)
     self.course_controller = CourseController(courses)
 def setUp(self):
     self.courses = CourseRepository()
     self.course1 = Course(1, "Asc", "Vancea")
     self.courses.save(self.course1)
     self.course2 = Course(2, "Fp", "Is")
     self.course3 = Course(3, "Logica", "Pop")
     self.course4 = Course(1, "L", "Pop")
     self.courses.save(self.course2)
Beispiel #3
0
 def setUp(self):
     self.grades = GradeRepository()
     self.course1 = Course(1, "Asc", "Vancea")
     self.student1 = Student(1, "Vlad")
     self.student2 = Student(2, "Ion")
     self.course2 = Course(2, "Fp", "I")
     self.grade1 = Grade(self.student1, self.course1, 10)
     self.grade2 = Grade(self.student1, self.course2, 4)
     self.grade3 = Grade(self.student2, self.course1, 7)
     self.grade4 = Grade(self.student1, self.course1, 8)
     self.grades.save(self.grade1)
     self.grades.save(self.grade2)
Beispiel #4
0
 def find_by_professor(self, professor):
     try:
         f = open("data/courses", "r")
         courses = []
         for line in f:
             object = line.split(",")
             course = Course(int(object[0]), object[1], object[2])
             self.validator.validate(course)
             if course.get_professor() == professor:
                 courses.append(course)
         return courses
     except IOError:
         raise ValueError("Cannot read course data")
Beispiel #5
0
 def find_by_id(self, id):
     try:
         f = open("data/courses", "r")
         for line in f:
             object = line.split(",")
             course = Course(int(object[0]), object[1], object[2])
             self.validator.validate(course)
             if course.get_id() == id:
                 f.close()
                 return course
         return -1
     except IOError:
         raise ValueError("Cannot read course data")
Beispiel #6
0
 def save(self, course_to_add):
     try:
         f = open("data/courses", "a+")
         for line in f:
             object = line.split(",")
             course = Course(int(object[0]), object[1], object[2])
             self.validator.validate(course)
             if course.get_id() == course_to_add.get_id():
                 raise CourseError("Duplicated Id's")
         s = str(course_to_add.get_id()) + "," + course_to_add.get_name(
         ) + "," + course_to_add.get_professor() + ",\n"
         f.write(s)
         f.close()
     except IOError:
         raise ValueError("Cannot read course data")
Beispiel #7
0
 def find_index(self, course_to_add):
     try:
         f = open("data/courses", "r")
         index = 0
         for line in f:
             object = line.split(",")
             course = Course(int(object[0]), object[1], object[2])
             self.validator.validate(course)
             if course.get_id() == course_to_add.get_id():
                 f.close()
                 return index
             else:
                 index = index + 1
         return -1
     except IOError:
         raise ValueError("Cannot read course data")
 def setUp(self):
     self.student = Student(1, "Vlad")
     self.course = Course(10, "Asc", "Vancea")
     self.grade = Grade(self.student, self.course, 10)
     self.invalid_grade = Grade(self.student, self.course, 30)
     self.invalid_grade2 = Grade(self.student, self.course, -30)
     self.validator_g = GradeValidator()
Beispiel #9
0
    def __init__(self):
        # Put csv in dataframe object
        dfStudents = pd.read_csv("files/studentenenvakken.csv",
                                 encoding="ISO-8859-1")
        dfCourses = pd.read_csv("files/courses.csv")

        students = []
        for index, row in dfStudents.iterrows():
            newStudent = Student(row[2])
            students.append(newStudent)

        self.courses = []
        for index, row in dfCourses.iterrows():
            newCourse = Course(row[0], students, row[3])
            self.courses.append(newCourse)

        # Set rooms with sizes
        room1 = Room(1, 41)
        room2 = Room(2, 22)
        room3 = Room(3, 20)
        room4 = Room(4, 56)
        room5 = Room(5, 48)
        room6 = Room(6, 117)
        room7 = Room(7, 60)
        self.rooms = [room1, room2, room3, room4, room5, room6, room7]

        # Set timeblocks
        timeblock1 = TimeBlock(1, 9)
        timeblock2 = TimeBlock(2, 11)
        timeblock3 = TimeBlock(3, 13)
        timeblock4 = TimeBlock(4, 15)
        self.timeblocks = [timeblock1, timeblock2, timeblock3, timeblock4]
Beispiel #10
0
 def setUp(self):
     self.students = StudentRepository()
     courses = CourseRepository()
     grades = GradeRepository()
     self.course1 = Course(1, "Asc", "Vancea")
     self.student1 = Student(1, "Vlad")
     self.student2 = Student(2, "Alex")
     courses.save(self.course1)
     self.students.save(self.student1)
     self.students.save(self.student2)
     self.course2 = Course(2, "Fp", "I")
     courses.save(self.course2)
     self.grade1 = Grade(self.student1, self.course1, 10)
     self.grade2 = Grade(self.student1, self.course2, 4)
     grades.save(self.grade1)
     grades.save(self.grade2)
     self.grade_controller = GradeController(courses, self.students, grades)
Beispiel #11
0
 def create(self, id, name, professor):
     '''
     create -> Course
     Creates and returns a Course that has the given id, name, professor
     :param id: int >= 0
     :param name: string
     :param professor: string
     '''
     course = Course(id, name, professor)
     return course
Beispiel #12
0
 def update_course(self, id, name, professor):
     '''
     update_course -> None
     Updates a Course from the list of courses
     If the course doesn't exist or there id a validation error, raises CourseError
     :param id: int
     :param name: string
     :param professor: string
     '''
     course = Course(id, name, professor)
     self.course_validator.validate(course)
     self.course_repository.update(course)
     grades_to_update = self.grade_repository.find_by_course(
         course.get_id())
     for i in range(0, len(grades_to_update)):
         student = self.student_repository.find_by_id(
             grades_to_update[i].get_id_student())
         grade = grades_to_update[i].get_grade()
         grade = self.create(student, course, grade)
         self.grade_repository.update(grade)
class TestCourseController(unittest.TestCase):
    def setUp(self):
        courses = CourseRepository()
        self.course1 = Course(1, "Asc", "Vancea")
        self.course2 = Course(2, "Fp", "I")
        self.course3 = Course(3, "Logica", "Pop")
        courses.save(self.course1)
        courses.save(self.course2)
        self.course_controller = CourseController(courses)

    def test_get_all(self):
        self.assertEqual(self.course_controller.get_all()[0], self.course1)
        self.assertEqual(self.course_controller.get_all()[1], self.course2)

    def test_add(self):
        self.course_controller.add(self.course3.get_id(),
                                   self.course3.get_name(),
                                   self.course3.get_professor())
        self.assertEqual(self.course_controller.get_all()[2].get_id(),
                         self.course3.get_id())
        self.assertEqual(self.course_controller.get_all()[2].get_name(),
                         self.course3.get_name())
        self.assertEqual(self.course_controller.get_all()[2].get_professor(),
                         self.course3.get_professor())
        self.assertRaises(
            CourseError,
            lambda: self.course_controller.add(1, "Algebra", "Modoi"))

    def test_search_id(self):
        self.assertEqual(
            self.course_controller.search_by_id(1).get_name(), "Asc")
        self.assertEqual(
            self.course_controller.search_by_id(1).get_professor(), "Vancea")
        self.assertRaises(CourseError,
                          lambda: self.course_controller.search_by_id(4))
Beispiel #14
0
 def delete(self, id):
     try:
         f = open("data/courses", "r")
         f1 = open("data/temp", "w")
         found = False
         for line in f:
             object = line.split(",")
             course = Course(int(object[0]), object[1], object[2])
             self.validator.validate(course)
             if course.get_id() != id:
                 s = str(course.get_id()) + "," + course.get_name(
                 ) + "," + course.get_professor() + ",\n"
                 f1.write(s)
             else:
                 found = True
         f.close()
         f1.close()
         if found == False:
             raise CourseError("Course not found")
         f1 = open("data/temp", "r")
         f = open("data/courses", "w")
         for line in f1:
             f.write(line)
         f.close()
         f1.close()
     except IOError:
         raise ValueError("Cannot read course data")
Beispiel #15
0
 def read_from_file(self):
     '''
     read_from_file -> list of Courses
     Reads information about courses written in a file and puts it in a list,
     raises IOError if the file is corrupted
     '''
     courses = []
     try:
         f = open("data/courses", "r")
         line = f.readline()
         while line != "":
             object = line.split(",")
             course = Course(int(object[0]), object[1], object[2])
             for i in range(0, len(courses)):
                 if int(object[0]) == courses[i].get_id():
                     raise IOError
             self.validator.validate(course)
             courses.append(course)
             line = f.readline()
         f.close()
         return courses
     except IOError:
         raise ValueError("Cannot read courses")
Beispiel #16
0
class TestGradeController(unittest.TestCase):
    def setUp(self):
        self.students = StudentRepository()
        courses = CourseRepository()
        grades = GradeRepository()
        self.course1 = Course(1, "Asc", "Vancea")
        self.student1 = Student(1, "Vlad")
        self.student2 = Student(2, "Alex")
        courses.save(self.course1)
        self.students.save(self.student1)
        self.students.save(self.student2)
        self.course2 = Course(2, "Fp", "I")
        courses.save(self.course2)
        self.grade1 = Grade(self.student1, self.course1, 10)
        self.grade2 = Grade(self.student1, self.course2, 4)
        grades.save(self.grade1)
        grades.save(self.grade2)
        self.grade_controller = GradeController(courses, self.students, grades)

    def test_get_all(self):
        self.assertEqual(self.grade_controller.get_all()[0].get_id_student(),
                         self.grade1.get_student().get_id())
        self.assertEqual(self.grade_controller.get_all()[0].get_id_course(),
                         self.grade1.get_course().get_id())
        self.assertEqual(self.grade_controller.get_all()[0].get_grade(),
                         self.grade1.get_grade())
        self.assertEqual(self.grade_controller.get_all()[1].get_id_student(),
                         self.grade2.get_student().get_id())
        self.assertEqual(self.grade_controller.get_all()[1].get_id_course(),
                         self.grade2.get_course().get_id())
        self.assertEqual(self.grade_controller.get_all()[1].get_grade(),
                         self.grade2.get_grade())

    def test_add(self):
        self.grade_controller.add(self.student2.get_id(),
                                  self.course1.get_id(), 10)
        self.assertEqual(self.grade_controller.get_all()[2].get_id_student(),
                         self.student2.get_id())
        self.assertEqual(self.grade_controller.get_all()[2].get_id_course(),
                         self.course1.get_id())
        self.assertEqual(self.grade_controller.get_all()[2].get_grade(), 10)
        self.assertRaises(GradeError,
                          lambda: self.grade_controller.add(1, 1, 3.5))
        self.assertRaises(GradeError,
                          lambda: self.grade_controller.add(10, 1, 3.5))
        self.assertRaises(GradeError,
                          lambda: self.grade_controller.add(1, 10, 3.5))
        self.assertRaises(GradeError,
                          lambda: self.grade_controller.add(1, 10, "a"))

    def test_update_course(self):
        self.grade_controller.update_course(1, "Analiza", "Berinde")
        self.assertEqual(self.grade_controller.get_all()[0].get_course_name(),
                         "Analiza")
        self.assertEqual(self.grade_controller.get_all()[0].get_professor(),
                         "Berinde")
        self.assertRaises(
            CourseError, lambda: self.grade_controller.update_course(
                10, "Analiza", "Berinde"))
        self.assertRaises(
            CourseError, lambda: self.grade_controller.update_course(
                "a", "Analiza", "Berinde"))

    def test_update_student(self):
        self.grade_controller.update_student(1, "Berinde")
        self.assertEqual(self.grade_controller.get_all()[0].get_student_name(),
                         "Berinde")
        self.assertRaises(
            StudentError,
            lambda: self.grade_controller.update_student(10, "Berinde"))
        self.assertRaises(
            StudentError,
            lambda: self.grade_controller.update_student("a", "Berinde"))
        self.assertRaises(
            StudentError,
            lambda: self.grade_controller.update_student(1, "berinde"))

    def test_update_grade(self):
        self.grade_controller.update_grade(1, 1, 9)
        self.assertEqual(self.grade_controller.get_all()[0].get_grade(), 9)
        self.assertRaises(
            GradeError, lambda: self.grade_controller.update_grade(10, 1, 10))
        self.assertRaises(
            GradeError, lambda: self.grade_controller.update_grade(1, 10, 10))
        self.assertRaises(
            GradeError,
            lambda: self.grade_controller.update_grade("a", 10, 10))
        self.assertRaises(
            GradeError, lambda: self.grade_controller.update_grade(1, 1, -10))

    def test_remove_course(self):
        self.grade_controller.remove_course(1)
        self.assertEqual(self.grade_controller.get_all()[0].get_grade(), 4)
        self.assertEqual(self.grade_controller.get_all()[0].get_id_student(),
                         1)
        self.assertEqual(self.grade_controller.get_all()[0].get_id_course(), 2)
        self.assertRaises(CourseError,
                          lambda: self.grade_controller.remove_course(10))

    def test_remove_student(self):
        self.grade_controller.remove_student(1)
        self.assertEqual(self.grade_controller.get_all(), [])
        self.assertRaises(StudentError,
                          lambda: self.grade_controller.remove_student(10))

    def test_remove_grade(self):
        self.grade_controller.remove_grade(1, 1)
        self.assertEqual(self.grade_controller.get_all()[0].get_id_student(),
                         1)
        self.assertEqual(self.grade_controller.get_all()[0].get_id_course(), 2)
        self.assertRaises(GradeError,
                          lambda: self.grade_controller.remove_grade(10, 1))

    def test_best_students(self):
        student3 = Student(3, "Maria")
        self.students.save(student3)
        self.grade_controller.add(self.student2.get_id(),
                                  self.course1.get_id(), 10)
        self.grade_controller.add(self.student2.get_id(),
                                  self.course2.get_id(), 5)
        self.grade_controller.add(student3.get_id(), self.course1.get_id(), 7)
        self.grade_controller.add(student3.get_id(), self.course2.get_id(), 7)
        self.assertEqual(len(self.grade_controller.search_highest_grades()), 1)
        self.assertEqual(
            self.grade_controller.search_highest_grades()[0][0].get_id(), 2)
        self.assertEqual(
            self.grade_controller.search_highest_grades()[0][0].get_name(),
            "Alex")
        self.assertEqual(self.grade_controller.search_highest_grades()[0][1],
                         7.5)

    def test_failed_students(self):
        student3 = Student(3, "Maria")
        self.students.save(student3)
        self.grade_controller.add(self.student2.get_id(),
                                  self.course1.get_id(), 4)
        self.grade_controller.add(self.student2.get_id(),
                                  self.course2.get_id(), 5)
        self.grade_controller.add(student3.get_id(), self.course1.get_id(), 4)
        self.grade_controller.add(student3.get_id(), self.course2.get_id(), 7)
        self.assertEqual(self.grade_controller.failed_students()[0][0],
                         "Vancea")
        self.assertEqual(self.grade_controller.failed_students()[1][0], "I")
        self.assertEqual(self.grade_controller.failed_students()[0][1], 2)
        self.assertEqual(self.grade_controller.failed_students()[1][1], 1)

    def test_search_course_grades(self):
        self.grade_controller.add(self.student2.get_id(),
                                  self.course1.get_id(), 4)
        self.assertEqual(
            self.grade_controller.search_course_grades(1)[1].get_id_student(),
            1)
        self.assertEqual(
            self.grade_controller.search_course_grades(1)
            [0].get_student_name(), "Alex")
        self.assertEqual(
            self.grade_controller.search_course_grades(1)
            [1].get_student_name(), "Vlad")
        self.assertEqual(
            self.grade_controller.search_course_grades(1)[0].get_id_student(),
            2)
        self.assertEqual(self.grade_controller.search_course_grades(4), [])
 def setUp(self):
     self.course = Course(10, "Asc", "Vancea")
     self.invalid_course = Course(-1, "", "v")
     self.validator_c = CourseValidator()
Beispiel #18
0
class TestCourseRepository(unittest.TestCase):
    def setUp(self):
        self.grades = GradeRepository()
        self.course1 = Course(1, "Asc", "Vancea")
        self.student1 = Student(1, "Vlad")
        self.student2 = Student(2, "Ion")
        self.course2 = Course(2, "Fp", "I")
        self.grade1 = Grade(self.student1, self.course1, 10)
        self.grade2 = Grade(self.student1, self.course2, 4)
        self.grade3 = Grade(self.student2, self.course1, 7)
        self.grade4 = Grade(self.student1, self.course1, 8)
        self.grades.save(self.grade1)
        self.grades.save(self.grade2)

    def test_save(self):
        self.grades.save(self.grade3)
        self.assertEqual(self.grades.find_all()[2].get_id_student(),
                         self.grade3.get_student().get_id())
        self.assertEqual(self.grades.find_all()[2].get_id_course(),
                         self.grade3.get_course().get_id())
        self.assertEqual(self.grades.find_all()[2].get_grade(),
                         self.grade3.get_grade())
        self.assertRaises(GradeError, lambda: self.grades.save(self.grade4))

    def test_find_all(self):
        self.assertEqual(self.grades.find_all()[0].get_id_student(),
                         self.grade1.get_student().get_id())
        self.assertEqual(self.grades.find_all()[0].get_id_course(),
                         self.grade1.get_course().get_id())
        self.assertEqual(self.grades.find_all()[0].get_grade(),
                         self.grade1.get_grade())
        self.assertEqual(self.grades.find_all()[1].get_id_student(),
                         self.grade2.get_student().get_id())
        self.assertEqual(self.grades.find_all()[1].get_id_course(),
                         self.grade2.get_course().get_id())
        self.assertEqual(self.grades.find_all()[1].get_grade(),
                         self.grade2.get_grade())

    def test_update(self):
        self.grades.update(self.grade4)
        self.assertEqual(self.grades.find_all()[0].get_id_student(),
                         self.grade4.get_student().get_id())
        self.assertEqual(self.grades.find_all()[0].get_id_course(),
                         self.grade4.get_course().get_id())
        self.assertEqual(self.grades.find_all()[0].get_grade(),
                         self.grade4.get_grade())
        self.assertRaises(GradeError, lambda: self.grades.update(self.grade3))

    def test_delete(self):
        self.grades.delete(1, 1)
        self.assertEqual(self.grades.find_all()[0].get_id_student(),
                         self.grade2.get_student().get_id())
        self.assertEqual(self.grades.find_all()[0].get_id_course(),
                         self.grade2.get_course().get_id())
        self.assertEqual(self.grades.find_all()[0].get_grade(),
                         self.grade2.get_grade())
        self.assertRaises(GradeError, lambda: self.grades.delete(4, 1))
        self.assertRaises(GradeError, lambda: self.grades.delete(1, 4))

    def test_find_by_id(self):
        self.assertEqual(self.grades.find_by_id(1, 1), self.grade1)
        self.assertEqual(self.grades.find_by_id(5, 1), -1)

    def test_find_index(self):
        self.assertEqual(self.grades.find_index(self.grade2), 1)
        self.assertEqual(self.grades.find_index(self.grade3), -1)

    def test_find_by_student(self):
        self.assertEqual(
            self.grades.find_by_student(1)[0].get_id_course(),
            self.course1.get_id())
        self.assertEqual(
            self.grades.find_by_student(1)[0].get_course_name(),
            self.course1.get_name())
        self.assertEqual(self.grades.find_by_student(1)[0].get_grade(), 10)
        self.assertEqual(
            self.grades.find_by_student(1)[1].get_id_course(),
            self.course2.get_id())
        self.assertEqual(
            self.grades.find_by_student(1)[1].get_course_name(),
            self.course2.get_name())
        self.assertEqual(self.grades.find_by_student(1)[1].get_grade(), 4)
        self.assertEqual(self.grades.find_by_student(5), [])
        repo = GradeRepository()
        self.assertEqual(repo.find_by_student(1), [])

    def test_find_by_course(self):
        self.grades.save(self.grade3)
        self.assertEqual(
            self.grades.find_by_course(1)[0].get_id_student(),
            self.student1.get_id())
        self.assertEqual(
            self.grades.find_by_course(1)[1].get_id_student(),
            self.student2.get_id())
        self.assertEqual(
            self.grades.find_by_course(1)[0].get_student_name(),
            self.student1.get_name())
        self.assertEqual(
            self.grades.find_by_course(1)[1].get_student_name(),
            self.student2.get_name())
        self.assertEqual(self.grades.find_by_course(1)[0].get_grade(), 10)
        self.assertEqual(self.grades.find_by_course(1)[1].get_grade(), 7)
        self.assertEqual(self.grades.find_by_course(5), [])