コード例 #1
0
    def _test_add_search_assignment(self):
        self._repo = Repository([])
        assert self._repo.size() == 0

        self._repo.add(self._assignment_ok)
        assert self._repo.size() == 1

        key_assignment = Assignment(self._assignment_ok.get_assignment_id(),
                                    None, None)
        found_assignment = self._repo.search(key_assignment)

        assert found_assignment.get_description(
        ) == self._assignment_ok.get_description()

        assignment_same_id = Assignment(
            self._assignment_ok.get_assignment_id(), 'Ceva ',
            date(2022, 12, 2))
        try:
            self._repo.add(assignment_same_id)
            assert False
        except RepoError as error:
            assert str(error) == "id existent\n"

        another_assignment = Assignment(123, 'nu stiu', date(2022, 12, 2))
        try:
            self._repo.search(another_assignment)
            assert False
        except RepoError as error:
            assert str(error) == "id inexistent\n"
コード例 #2
0
    def test_addassignmentservice(self):
        assing = str(Assignment('123', 'Homework due Tomorrow', '2021-12-22'))
        val = Assignment_Validator()
        self.assertEqual(val.check_if_deadline_passed('2020-12-32'), False)
        self.assertEqual(val.check_if_deadline_passed('2020-10-10-10'), False)
        self.assertEqual(val.validate_datetime('2020-12-32'), False)
        self.assertEqual(val.validate_datetime('2020-10-10-10'), False)
        self.assertEqual(val.validate_datetime('2020-10-30'), False)
        try:
            val.validate(self.assing_list.list_of_assignments,
                         Assignment('123', 'Ho', '2020-10-20'))
            self.assertFalse('not ok')
        except AssignmentValidatorException as ve:
            s = str(ve)
            self.assertTrue('ok')
        try:
            val.validate(self.assing_list.list_of_assignments,
                         Assignment('123', 'Ho', '20212-12-22'))
            self.assertFalse('not ok')
        except AssignmentValidatorException as ve:
            s = str(ve)
            self.assertTrue('ok')
        self.assing_list.add_assignment('123', 'Homework due Tomorrow',
                                        '2021-12-22')
        try:
            self.assing_list.add_assignment('123', 'Homework due Tomorrow',
                                            '2021-12-22')
            self.assertFalse('Not good')
        except AssignmentException:
            self.assertTrue('OK')
        self.assertEqual(len(self.assing_list), 1)

        self.assing_list.add_assignment('124', 'Homework due Tomorrow',
                                        '2021-12-22')
        self.assing_list.add_assignment('125', 'Homework due Tomorrow',
                                        '2021-12-22')
        self.assing_list.add_assignment('126', 'Homework due Tomorrow',
                                        '2021-12-22')
        self.assing_list.add_assignment('127', 'Homework due Tomorrow',
                                        '2021-12-22')
        self.assertEqual(len(self.assing_list), 5)
        try:
            self.assing_list.add_assignment('128', 'Ho', '2021-12-22')
            self.assertFalse('Not good')
        except AssignmentException:
            self.assertTrue('OK')

        try:
            self.assing_list.add_assignment('128', 'Homework due Tomorrow',
                                            '2021-12-222')
            self.assertFalse('Not good')
        except AssignmentException:
            self.assertTrue('OK')

        try:
            self.assing_list.add_assignment('123', 'Homework due Tomorrow',
                                            '2021-12-22')
            self.assertFalse('Not good')
        except AssignmentException:
            self.assertTrue('OK')
コード例 #3
0
    def test_updateassignmentrepo(self):
        assing = Assignment('123', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        assing = Assignment('124', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        assing = Assignment('125', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        assing = Assignment('126', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)

        self.assing_repo.update_object(1, '2022-11-22')
        self.assertEqual(self.assing_repo[1].Deadline, '2022-11-22')
コード例 #4
0
    def test_removeassignmentrepo(self):
        assing = Assignment('123', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        self.assing_repo.remove_object(assing)
        assing = Assignment('124', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        self.assing_repo.remove_object(assing)
        assing = Assignment('125', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        self.assing_repo.remove_object(assing)
        assing = Assignment('126', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        self.assing_repo.remove_object(assing)

        self.assertEqual(len(self.assing_repo.objects), 0)
コード例 #5
0
    def setUp(self):

        student_repo = Repository()
        assignment_repo = Repository()
        grade_repo = Repository()
        student_validator = Student_Validator()
        assignment_validator = Assignment_Validator()
        grade_validator = Grade_Validator()
        self._undo_service = UndoService()

        student_service = studentService(student_repo, grade_repo, student_validator, self._undo_service )
        assignment_service = assignmentService(assignment_repo, grade_repo, assignment_validator, self._undo_service)
        grade_service = gradeService(student_repo, assignment_repo, grade_repo, student_validator, assignment_validator,grade_validator, self._undo_service)

        student_validator = Student_Validator()
        assignment_validator = Assignment_Validator()
        grade_validator = Grade_Validator()

        self._student_list = student_service
        self._assignment_list = assignment_service
        self._grade_list = grade_service
        self.list_s.add_student('124', 'Mark Park', '912')
        self.list_s.add_student('125', 'Mark Park', '912')
        self.list_s.add_student('126', 'Mark Park', '912')
        self.list_s.add_student('127', 'Mark Park', '913')
        self.list_s.add_student('128', 'Mark Park', '914')
        self.assing_list.add_assignment('124', 'Homework due Tomorrow', '2021-12-22')
        self.assing_list.add_assignment('125', 'Homework due Tomorrow', '2021-12-22')
        self.assing_list.add_assignment('126', 'Homework due Tomorrow', '2021-12-22')
        self.assing_list.list_of_assignments.add_object(Assignment('127', 'Homework due Tomorrow', '2020-10-22'))
コード例 #6
0
    def _load(self):
        """
        We load the data from Data base
        """
        try:
            # we try here to make the connection to the data base
            connection_string = psycopg2.connect(
                "host=localhost dbname=postgres user=postgres password=polopolo"
            )
            current_connector = connection_string.cursor()
            # if we get to this line it means that the connection was succesfully done!
            # now according to the value stored in self._entity we will select all data from the corresponding table
            current_connector.execute(self.get_selectquery)

            # after that we will store it in the list
            for row in current_connector:
                if self._entity == 'Student':
                    super().add_object(
                        Student(str(row[0]), str(row[1]), str(row[2])))
                if self._entity == 'Assignment':
                    super().add_object(
                        Assignment(str(row[0]), str(row[1]), str(row[2])))
                if self._entity == 'Grade':
                    super().add_object(
                        Grade(str(row[0]), str(row[1]), str(row[2])))
            current_connector.close()
            connection_string.close()

        except Exception as ve:
            raise RepositoryException(ve)
コード例 #7
0
 def generate(self):
     for i in range(1, 11):
         description = random.choice(self._descriptions)
         self._descriptions.remove(description)
         deadline = random.choice(self._deadlines)
         assign = Assignment(i, description, deadline)
         self._init_assignments.append(assign)
コード例 #8
0
    def _load(self):
        """
        we will load into the memory repos the data from the files
        """

        try:

            file = open(self._filename, "r")
            self._data = json.load(file)
            # we check which file was opened to enter data correctly // we could have done 3 repo's instead of this one
            for item in self._data[self._entity]:
                if self._entity == 'Student':
                    super().add_object(
                        Student(item[self._atr1], item[self._atr2],
                                item[self._atr3]))
                if self._entity == 'Assignment':
                    super().add_object(
                        Assignment(item[self._atr1], item[self._atr2],
                                   item[self._atr3]))
                if self._entity == 'Grade':
                    super().add_object(
                        Grade(item[self._atr1], item[self._atr2],
                              item[self._atr3]))
            # file.close()
        except JSONDecodeError:
            self._data[self._entity] = []

            with open(self._filename, 'w') as outfile:
                json.dump(self._data, outfile)
                outfile.close()
コード例 #9
0
 def generate_random_assignment(self):
     for i in range(0, 10):
         id = self.generate_rand_ass_id()
         description = ['Homework with classes', 'Preparation for the written exam',' Project for passing the class','Optional Homework','Individual Exercises', 'Mandatory Homework', 'Final grade project', 'Bonus points project','Erasmus interview project']
         deadline = ['2020-10-10','2020-11-16','2020-08-12','2021-12-25','2020-11-19','2021-02-01','2021-01-10','2021-07-23','2021-05-18','2021-03-29']
         rand_desc = description[random.randint(0,8)]
         rand_dead = deadline[random.randint(0,9)]
         assignment = Assignment(id, rand_desc, rand_dead)
         self.llist_a.list_of_assignments.add_object(assignment)
コード例 #10
0
    def _test_validate_assignment(self):
        validation_assignment = ValidationAssignment()

        validation_assignment.validate_assignment(self._assignment_ok)

        self._assignment_not_ok = Assignment(-11, 'Ceva', date(2022, 12, 2))
        try:
            validation_assignment.validate_assignment(self._assignment_not_ok)
            assert False
        except ValidationError as error:
            assert str(error) == "invalid id!\n"

        self._assignment_not_ok = Assignment(-11, "", date(2022, 12, 2))
        try:
            validation_assignment.validate_assignment(self._assignment_not_ok)
            assert False
        except ValidationError as error:
            assert str(error) == "invalid id!\ninvalid description!\n"
コード例 #11
0
    def test_addassignmentrepo(self):
        assing = Assignment('123', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        try:
            self.assing_repo.add_object(assing)
            self.assertTrue('OK')
        except AssignmentException:
            self.assertFalse('Not good')

        self.assertEqual(len(self.assing_repo), 2)
        assing = Assignment('123', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        assing = Assignment('124', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        assing = Assignment('125', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        assing = Assignment('126', 'Homework due Tomorrow', '2021-12-22')
        self.assing_repo.add_object(assing)
        self.assertEqual(len(self.assing_repo), 6)
コード例 #12
0
    def add_assignment(self, id, description, deadline):
        """
        we add a given assignment if it is valid
        :param id: the given ID
        :param description: the given description
        :param deadline: the given Deadline

        """
        # if there is no exception raised, it means that the id is unique
        self._validator.validate(self.list_of_assignments,
                                 Assignment(id, description, deadline))
        ass = Assignment(id, description, deadline)
        # if the code gets to this point it means that the assignment is valid so we can do the undo/redo

        undo_function = FunctionCall(self.list_of_assignments.remove_object,
                                     ass)
        redo_function = FunctionCall(self.list_of_assignments.add_object, ass)
        operation = OperationCall(undo_function, redo_function)
        self._undo_service.record(operation)

        self.list_of_assignments.add_object(ass)
コード例 #13
0
    def _load(self):
        """
        We load the data from file
        """

        file = open(self._filename, "rt")
        lines = file.readlines()
        file.close()

        for line in lines:
            line = line.split(";")
            current_date = line[2].split("-")
            line[2] = datetime.date(int(current_date[0]), int(current_date[1]), int(current_date[2]))
            super().add_object(Assignment(line[0], line[1], line[2]))
コード例 #14
0
    def test_validate_assignment(self):

        ok_assignment = Assignment(12, 'Homework', date(2019, 12, 1))
        not_ok_assignment = Assignment(12, '', date(2010, 1, 1))
        self.elems()

        self._valid_assignment.validate_assignment(ok_assignment)

        try:
            self._valid_assignment.validate_assignment(not_ok_assignment)
            self.assertTrue(False)
        except ValidationError as error:
            self.assertEqual(str(error), "invalid description!\n")
        except Exception:
            self.assertTrue(False)

        not_ok_assignment = Assignment(-12, '', date(2010, 1, 1))
        try:
            self._valid_assignment.validate_assignment(not_ok_assignment)
            self.assertTrue(False)
        except ValidationError as error:
            self.assertEqual(str(error), "invalid id!\ninvalid description!\n")
        except Exception:
            self.assertTrue(False)
コード例 #15
0
 def test_create_assignment(self):
     test_assignment = Assignment(12, 'Homework', date(2019, 12, 1))
     self.assertEqual(test_assignment.get_assignment_id(), 12)
     self.assertEqual(test_assignment.get_deadline(), date(2019, 12, 1))
     test_assignment.set_description('Project')
     self.assertEqual(test_assignment.get_description(), 'Project')
コード例 #16
0
def create_assignment(assignment_id, description, deadline):
    deadline = str(deadline)
    deadline = deadline.split('-')
    return Assignment(
        int(assignment_id), description,
        date(int(deadline[0]), int(deadline[1]), int(deadline[2])))
コード例 #17
0
 def _test_remove_assignment(self):
     self._repo = Repository([])
     self._repo.add(Assignment(56, "Iliescu Horea", date(2019, 12, 1)))
     assert self._repo.size() == 1
     self._repo.delete(Assignment(56, "Iliescu Horea", date(2019, 12, 1)))
     assert self._repo.size() == 0
コード例 #18
0
    def _test_create_assignment(self):
        test_assignment = Assignment(12, 'Ceva tema grea', date(2019, 12, 12))
        self._assignment_ok = test_assignment
        assert test_assignment.get_assignment_id() == 12

        test_assignment.set_description('Nimic nou')
        assert test_assignment.get_description() == 'Nimic nou'
        assert test_assignment.get_deadline().year == 2019
        assert test_assignment.get_deadline().month == 12
        assert test_assignment.get_deadline().day == 12
        test_assignment.set_deadline(date(2020, 11, 2))
        assert test_assignment.get_deadline().month == 11