def test_remove_assignment(self): assignments = Repo() assignment1 = Assignment(1, "fiejfe", "01.01.2020") assignment2 = Assignment(2, "frijfr", "10.10.2000") assignments.add(assignment1) assert (assignments.size() == 1) assignments.add(assignment2) assert (assignments.size() == 2) assignments.remove(assignment2) assert (assignments.size() == 1) assignments.remove(assignment1) assert (assignments.size() == 0)
def late_students(self): today = datetime.today().strftime('%Y.%m.%d') grades = self.__repo_grade.get_all() students = Repo() for grade in grades: assign = Assignment(grade.get_assignment_id(), None, None) assign = self.__repo_assignment.search(assign) date = assign.get_assignment_deadline() if date < today and grade.get_grade() == -1: student = Student(grade.get_student_id(), None, None) if student not in students: student = self.__repo_student.search(student) students.add(student) return students.get_all()
def test_create_assignment(self): a_id = 1 description = "homework" deadline = "10-10-2010" assignment = Assignment(a_id, description, deadline) assert (assignment.get_id() == 1) assert (assignment.get_assignment_description() == description) assert (assignment.get_assignment_deadline() == deadline) assignment.set_assignment_description("tema") assert (assignment.get_assignment_description() == "tema") dif_assign_same_id = Assignment(1, "diefie", "10.10.2000") assert (assignment == dif_assign_same_id)
def test_update_assignment(self): a_id = 1 description = "homework" deadline = "10-10-2010" assignment = Assignment(a_id, description, deadline) assignment.set_assignment_description("lola") assert (assignment.get_assignment_description() == "lola") assignment.set_assignment_deadline("20.12.2019") assert (assignment.get_assignment_deadline() == "20.12.2019")
def get_assignments_for_student(self, student_id): grades = Repo() grades = self.__repo_grade.search_for_student(student_id, grades).get_all() assignments = Repo() for grade in grades: if grade.get_grade() == -1: assign = Assignment(grade.get_assignment_id(), None, None) assignments.add(self.__repo_assignment.search(assign)) return assignments.get_all()
def add_assignment(self, assignment_id, assignment_description, assignment_deadline): """ function that add an assignment to the repository :param assignment_id: integer :param assignment_description: string :param assignment_deadline: string :return: - """ assignment = Assignment(assignment_id, assignment_description, assignment_deadline) self.__repo_assignment.add(assignment)
def remove_assignment(self, id_assignment): """ function that search for the id of an assignment in repository and remove it :param id_assignment: integer :return: - """ assignment = Assignment(id_assignment, None, None) self.__repo_assignment.remove(assignment) grades = Repo() grades = self.__repo_grade.search_for_assignments(id_assignment, grades).get_all() for grade in grades: self.__repo_grade.remove(grade)
def initialize_assignments(Repo_Assignment): Dates = [ "2019.10.10", "2019.11.10", "2019.11.15", "2020.11.23", "2019.10.12", "201911.12", "2019.07.12", "2020.10.20", "2020.02.02", "2020.02.12" ] Descr = [ "homework1", "homework2", "homework3", "homework4", "homework5", "homework6", "homework7", "homework8", "homework9", "homework10" ] for i in range(10): try: assignment_id = randint(1, 100) assignment_description = Descr[randint(0, 9)] assignment_deadline = Dates[randint(0, 9)] Repo_Assignment.add( Assignment(assignment_id, assignment_description, assignment_deadline)) except RepoError: continue return Repo_Assignment
def update_assignment(self, assignment_id, assignment_description, assignment_deadline): """ function that update the description and the deadline of an assignment :param assignment_id: integer :param assignment_description: string :param assignment_deadline: date :return: - """ assignment = Assignment(assignment_id, None, None) assignment = self.__repo_assignment.search(assignment) self.__repo_assignment.remove(assignment) if assignment_description is not None: assignment.set_assignment_description(assignment_description) if assignment_deadline is not None: assignment.set_assignment_deadline(assignment_deadline) self.__repo_assignment.add(assignment)