Exemple #1
0
    def test_Fstergere_asignare(self):
        # White-box testing pentru stergerea asignarilor din repository.

        p4 = Problema(1, 7, "Programare dinamica",
                      repo_problema.Data("06.07.2021"))
        p5 = Problema(2, 3, "Management baza de date",
                      repo_problema.Data("02.12.2020"))
        p6 = Problema(4, 1, "Cont bancar", repo_problema.Data("09.01.2021"))

        d4, d5 = repo_problema.Data("06.07.2021"), repo_problema.Data(
            "02.12.2020")
        d6 = repo_problema.Data("09.01.2021")

        repo_asignare.lista_asignari.stergere_asignare_file(p4, 0)
        content = repo_asignare.lista_asignari.readFromFile()
        assert content == [
            Asignare(Student(30, "Marin Stefania", 717),
                     Problema(2, 3, "Management baza de date", d5)),
            Asignare(Student(3, 'Alexandrescu Mihai', 917),
                     Problema(2, 3, "Management baza de date", d5)),
            Asignare(Student(3, 'Alexandrescu Mihai', 917),
                     Problema(4, 1, "Cont bancar", d6))
        ]

        repo_asignare.lista_asignari.stergere_asignare_file(p5, 0)
        content = repo_asignare.lista_asignari.readFromFile()
        assert content == [
            Asignare(Student(3, 'Alexandrescu Mihai', 917),
                     Problema(4, 1, "Cont bancar", d6))
        ]

        repo_asignare.lista_asignari.stergere_asignare_file(p6, 0)
        content = repo_asignare.lista_asignari.readFromFile()
        assert content == []
Exemple #2
0
    def test_Dstergere_student(self):
        # White-box testing pentru stergerea studentilor din repository.

        repo_student.lista_stud.stergere_student_file(0)
        content = repo_student.lista_stud.readFromFile()
        assert content == [
            Student(10, 'Popescu Alex', 214),
            Student(3, 'Georgescu George', 4),
            Student(15, 'Ionescu Ioana', 319),
            Student(5, 'Codreanu Mihai', 213)
        ]

        repo_student.lista_stud.stergere_student_file(3)
        content = repo_student.lista_stud.readFromFile()
        assert content == [
            Student(10, 'Popescu Alex', 214),
            Student(3, 'Georgescu George', 4),
            Student(15, 'Ionescu Ioana', 319)
        ]

        repo_student.lista_stud.stergere_student_file(2)
        content = repo_student.lista_stud.readFromFile()
        assert content == [
            Student(10, 'Popescu Alex', 214),
            Student(3, 'Georgescu George', 4)
        ]

        repo_student.lista_stud.stergere_student_file(1)
        content = repo_student.lista_stud.readFromFile()
        assert content == [Student(10, 'Popescu Alex', 214)]

        repo_student.lista_stud.stergere_student_file(0)
        assert repo_student.lista_stud.get_list() == []
    def test_validate_student(self):

        ok_student = Student(1, 'Mircea', 911)
        not_ok_student = Student(-1, 'Mircea', 911)
        self.elems()

        self._valid_student.validate_student(ok_student)

        with self.assertRaises(ValidationError):
            self._valid_student.validate_student(not_ok_student)

        not_ok_student = Student(-1, '', 911)
        try:
            self._valid_student.validate_student(not_ok_student)
            self.assertTrue(False)
        except ValidationError as error:
            self.assertEqual(str(error), "invalid id!\ninvalid name!\n")
        except Exception:
            self.assertTrue(False)

        not_ok_student = Student(-1, '', -911)
        try:
            self._valid_student.validate_student(not_ok_student)
            self.assertTrue(False)
        except ValidationError as error:
            self.assertEqual(str(error),
                             "invalid id!\ninvalid name!\ninvalid group!\n")
        except Exception:
            self.assertTrue(False)
Exemple #4
0
    def test_Bsrv_cautare_student_Black_Box(self):
        # Black-box testing pentru service-ul de cautare a problemelor: adaug cateva probleme, pentru
        # a putea cauta indiferent de problemele introduse mai sus, in white-box testing.

        repo_student.lista_stud.set_content([])

        srv_student = ServiceStudent()
        srv_student.srv_adaugare_student("1, Ionescu Alexandru, 213")
        srv_student.srv_adaugare_student("18, Popescu Andrei, 317")
        srv_student.srv_adaugare_student("420, Popovici Mihai, 919")

        assert srv_student.srv_cautare_student("1") == (1, "Ionescu Alexandru", 213)
        assert srv_student.srv_cautare_student("18") == (18, "Popescu Andrei", 317)
        assert srv_student.srv_cautare_student("420") == (420, "Popovici Mihai", 919)

        self.assertRaises(IDError, srv_student.srv_cautare_student, "-1")
        self.assertRaises(IDError, srv_student.srv_cautare_student, "b")
        self.assertRaises(IDError, srv_student.srv_cautare_student, "0")
        self.assertRaises(ExistentaError, srv_student.srv_cautare_student, "15")
        self.assertRaises(ExistentaError, srv_student.srv_cautare_student, "2")

        # Refacem content-ul dinaintea adaugarilor mele, pentru a merge restul testelor white-box.

        repo_student.lista_stud.set_content([Student(1, 'Popescu Alexandru', 213), Student(2, 'Antonovici Traian', 917),
                                             Student(1024, 'Stefanescu Daniel', 319)])
Exemple #5
0
    def test_update_student_repo(self):
        stud = Student('124', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        stud = Student('125', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        stud = Student('126', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        stud = Student('127', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)

        self.list_s_repo.update_object(0, '913')
        self.assertEqual(self.list_s_repo[0].student_group, '913')
Exemple #6
0
 def test_if_iterable(self):
     iterable = IterableDataStructure()
     stud = Student('123', 'Mark Park', '912')
     iterable.add(stud)
     stud = Student('124', 'Mark Park', '912')
     iterable.add(stud)
     stud = Student('125', 'Mark Park', '912')
     iterable.add(stud)
     stud = Student('126', 'Mark Park', '912')
     iterable.add(stud)
     index = 0
     for student in iterable:
         if student is not None:
             index += 1
     print(index)
Exemple #7
0
    def test_add_student_repo(self):
        stud = str(Student('123', 'Mark Park', '912'))

        self.list_s_repo.add_object(stud)
        self.assertEqual(len(self.list_s_repo.objects), 1)

        stud = Student('124', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        stud = Student('125', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        stud = Student('126', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        stud = Student('127', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        self.assertEqual(len(self.list_s_repo.objects), 5)
    def test_getters_asignare(self):
        # White-box testing: testez toate ramurile pentru getteri
        # (student, problema, nota si asignarea sub forma de tuple).

        s1, p1 = Student(1, "Pop Ion", 213), Problema(1, 1, "Cont bancar", "20.12.2020")
        a1 = Asignare(s1, p1)

        assert a1.get_nota() == 0
        assert a1.get_student() == Student(1, "Pop Ion", 213)
        assert a1.get_problema() == Problema(1, 1, "Cont bancar", "20.12.2020")

        a1.set_nota(9)
        assert a1.get_nota() == 9

        assert a1.get_asignare_tuple() == (Student(1, "Pop Ion", 213), Problema(1, 1, "Cont bancar", "20.12.2020"))
    def readFromFile(self):
        content = []
        file = open(self.__path, "r")

        line = file.readline()
        while line:
            line = line.strip()
            param = line.split("; ")

            if len(param) == 3:
                student = param[0].split(", ")
                problema = param[1].split(", ")
                nota = param[2]

                asignare = Asignare(
                    Student(int(student[0]), student[1], int(student[2])),
                    Problema(int(problema[0]), int(problema[1]), problema[2],
                             Data(problema[3])))

                asignare.set_nota(int(nota))

                content.append(asignare)

            line = file.readline()

        file.close()
        return content
Exemple #10
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)
Exemple #11
0
    def test_Enotare_asignare(self):
        # White-box testing pentru stergerea asignarilor din repository.

        s4 = Student(30, "Marin Stefania", 717)

        p4 = Problema(1, 7, "Programare dinamica",
                      repo_problema.Data("06.07.2021"))
        p5 = Problema(2, 3, "Management baza de date",
                      repo_problema.Data("02.12.2020"))
        p6 = Problema(4, 1, "Cont bancar", repo_problema.Data("09.01.2021"))

        repo_asignare.lista_asignari.notare_problema_file(s4, p4, 10)
        nota = repo_asignare.lista_asignari.readFromFile()[0].get_nota()
        assert nota == 10

        repo_asignare.lista_asignari.notare_problema_file(s4, p5, 7)
        nota = repo_asignare.lista_asignari.readFromFile()[1].get_nota()
        assert nota == 7

        repo_asignare.lista_asignari.notare_problema_file(
            repo_student.lista_stud.get_content()[1], p5, 9)
        nota = repo_asignare.lista_asignari.readFromFile()[2].get_nota()
        assert nota == 9

        repo_asignare.lista_asignari.notare_problema_file(
            repo_student.lista_stud.get_content()[1], p6, 3)
        nota = repo_asignare.lista_asignari.readFromFile()[3].get_nota()
        assert nota == 3
Exemple #12
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()
Exemple #13
0
 def generate(self):
     for i in range(1, 11):
         name = random.choice(self._names)
         self._names.remove(name)
         group = random.choice(self._groups)
         stud = Student(i, name, group)
         self._init_students.append(stud)
    def test_setters_asignare(self):
        # White-box testing: testez toate ramurile pentru setteri, dar si pentru getteri
        # (student, problema si nota).

        s1, p1 = Student(1, "Pop Ion", 213), Problema(1, 1, "Cont bancar", "20.12.2020")
        nota = 7
        a1 = Asignare(0, 0)

        a1.set_nota(nota)
        assert a1.get_nota() == 7

        a1.set_student(s1)
        assert a1.get_student() == Student(1, "Pop Ion", 213)

        a1.set_problema(p1)
        assert a1.get_problema() == Problema(1, 1, "Cont bancar", "20.12.2020")
Exemple #15
0
    def srv_modificare_student(self, stud_id, intrare):
        """
        Functia primeste ID-ul studentului ce trebuie modificat si noile date de intrare. Dupa ce se asigura validitatea
        datelor de intrare, functia prelucreaza datele si le trimite in repo pentru a fi modificate.

        :param stud_id: ID-ul studentului ce trebuie modificat, validat de functia de mai sus.
        :param intrare: Un sir de caractere ce ar trebui sa reprezinte noile date ale studentului.
        """

        validator_student = ValidatorStudent()
        stud_id = int(stud_id)

        try:
            validator_student.validare_student(intrare)

            param = intrare.split(", ")

            index_student_gasit = repo.lista_stud.cautare_student(
                len(repo.lista_stud.get_content()) - 1, stud_id)
            repo.lista_stud.validare_unicitate_stud_id(index_student_gasit,
                                                       param[0])

            stud_id, nume, grupa = param[0], param[1], param[2]
            student = Student(0, 0, 0)

            student.set_stud_id(stud_id)
            student.set_nume(nume)
            student.set_grupa(grupa)

            repo_asignare.lista_asignari.modificare_asignare_file(
                repo.lista_stud.get_content()[index_student_gasit], student, 1)
            repo.lista_stud.modificare_student_file(index_student_gasit,
                                                    student)

        except IDError:
            raise IDError(
                "Noul ID al studentului este invalid! Introduceti alte date de intrare:"
            )

        except NumeError:
            raise NumeError(
                "Noul nume al studentului este invalid! Introduceti alte date de intrare:"
            )

        except GrupaError:
            raise GrupaError(
                "Noua grupa a studentului este invalida! Introduceti alte date de intrare:"
            )

        except IDUnicError:
            raise IDUnicError(
                "Exista deja un student cu acest ID! Introduceti alte date de intrare:"
            )

        except ParamError:
            raise ParamError(
                "Parametri insuficienti! Introduceti alte date de intrare:")
Exemple #16
0
    def setUp(self):
        self.__a1 = Asignare(Student(1, "Farcasanu Stefan", 213),
                             Problema(1, 1, "Biblioteca", Data("05.04.2021")))
        self.__a2 = Asignare(Student(2, "Dina Andrei-Const", 213),
                             Problema(1, 1, "Biblioteca", Data("05.04.2021")))
        self.__a3 = Asignare(Student(3, "Dretcanu Mihai", 917),
                             Problema(1, 2, "Cinema", Data("18.12.2020")))
        self.__a4 = Asignare(Student(4, "Dretcanu Mihai", 313),
                             Problema(1, 2, "Cinema", Data("18.12.2020")))

        self.__a1.set_nota(6)
        self.__a2.set_nota(6)
        self.__a3.set_nota(10)
        self.__a4.set_nota(9)

        self.__d1 = [213, 2]
        self.__d2 = [313, 1]
Exemple #17
0
    def test_srv_medie_mica(self):
        srv_student = ServiceStudent()
        srv_statistici = ServiceStatistici()

        stat = srv_statistici.srv_medie_mica(1)
        stud1, nota1, stud2, nota2 = stat[0][0], stat[0][1], stat[1][0], stat[1][1]

        assert stud1 == Student(1, 'Popescu Alexandru', 213)
        assert nota1 == 4.0
        assert stud2 == Student(2, 'Antonovici Traian', 917)
        assert nota2 == 4.0

        srv_student.srv_stergere_student(2)
        srv_student.srv_stergere_student(1)
        stat = srv_statistici.srv_medie_mica(1)

        assert stat == []
 def _test_create_student(self):
     test_student = Student(10, "Iliescu Georgian", 911)
     self.assertEqual(test_student.get_student_id(), 10)
     assert test_student.get_group() == 911
     test_student.set_group(900)
     assert test_student.get_group() == 900
     self._stud_ok = test_student
Exemple #19
0
    def test_removestudentrepo(self):

        self.assertEqual(len(self.list_s_repo.objects), 0)

        stud = Student('124', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        self.list_s_repo.remove_object(stud)
        stud = Student('125', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        self.list_s_repo.remove_object(stud)
        stud = Student('126', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        self.list_s_repo.remove_object(stud)
        stud = Student('127', 'Mark Park', '912')
        self.list_s_repo.add_object(stud)
        self.list_s_repo.remove_object(stud)

        self.assertEqual(len(self.list_s_repo.objects), 0)
Exemple #20
0
    def add_student(self, id, name, group):
        """
        we add a student with the given id, name, group
        :param id: the given id
        :param name: the given name
        :param group: the given group
        """
        self.validator.validate(self, Student(id, name, group))
        student = Student(id, name, group)

        undo_function = FunctionCall(self.student_list_service.remove_object,
                                     student)
        redo_function = FunctionCall(self.student_list_service.add_object,
                                     student)
        operation = OperationCall(undo_function, redo_function)
        self._undo_service.record(operation)

        self.student_list_service.add_object(student)
Exemple #21
0
 def generate_random_student(self):
     for i in range(0, 10):
         id = self.generate_random_id()
         surname = ['Dan', 'Pop', 'Marcus', 'George', 'Farcau', 'Molnar', 'Vancea', 'Pintea', 'Nistor']  # 9 terms
         names = ['Sergiu', 'George', 'Raul', 'Catalin', 'Marian', 'Raluca', 'Andrei', 'Mircea', 'Alex',                       'Victor']  # 10
         groups = ['911', '912', '913', '914', '915', '916', '917']  # 7 terms
         rand_names = surname[random.randint(0,8)] + " " + names[random.randint(0,9)]
         rand_groups = groups[random.randint(0,6)]
         student = Student(id, rand_names, rand_groups)
         self.llist_s.student_list_service.add_object(student)
Exemple #22
0
    def test_Aadaugare_asignare(self):
        # White-box testing pentru adaugarea asignarilor in repository.

        repo_asignare.lista_asignari.adaugare_asignare_file(self.a1)
        content = repo_asignare.lista_asignari.readFromFile()
        assert content == [
            Asignare(Student(15, 'Pop Ion', 213),
                     Problema(1, 1, 'Management baza de date', dl1))
        ]

        repo_asignare.lista_asignari.adaugare_asignare_file(self.a2)
        content = repo_asignare.lista_asignari.readFromFile()
        assert content == [
            Asignare(Student(15, 'Pop Ion', 213),
                     Problema(1, 1, 'Management baza de date', dl1)),
            Asignare(Student(15, 'Pop Ion', 213),
                     Problema(3, 1, 'Cheltuieli de familie', dl2))
        ]

        repo_asignare.lista_asignari.adaugare_asignare_file(self.a3)
        content = repo_asignare.lista_asignari.readFromFile()
        assert content == [
            Asignare(Student(15, 'Pop Ion', 213),
                     Problema(1, 1, 'Management baza de date', dl1)),
            Asignare(Student(15, 'Pop Ion', 213),
                     Problema(3, 1, 'Cheltuieli de familie', dl2)),
            Asignare(Student(3, 'Alexandrescu Mihai', 917),
                     Problema(3, 1, 'Cheltuieli de familie', dl3))
        ]

        repo_asignare.lista_asignari.adaugare_asignare_file(self.a4)
        content = repo_asignare.lista_asignari.readFromFile()
        assert content == [
            Asignare(Student(15, 'Pop Ion', 213),
                     Problema(1, 1, 'Management baza de date', dl1)),
            Asignare(Student(15, 'Pop Ion', 213),
                     Problema(3, 1, 'Cheltuieli de familie', dl2)),
            Asignare(Student(3, 'Alexandrescu Mihai', 917),
                     Problema(3, 1, 'Cheltuieli de familie', dl3)),
            Asignare(Student(3, 'Alexandrescu Mihai', 917),
                     Problema(2, 1, 'Cheltuieli service auto', dl4))
        ]
Exemple #23
0
    def test_srv_studenti_ordonat(self):
        srv_statistici = ServiceStatistici()

        stat = srv_statistici.srv_studenti_ordonati("1 2", 'cresc', 'a', 1)
        stud1, nota1, stud2, nota2 = stat[0].get_student(), stat[0].get_nota(), stat[1].get_student(), stat[
            1].get_nota()
        stud3, nota3 = stat[2].get_student(), stat[2].get_nota()

        assert stud1 == Student(2, "Antonovici Traian", 917) and nota1 == 2
        assert stud2 == Student(1, "Popescu Alexandru", 213) and nota2 == 6
        assert stud3 == Student(3, "Popovici Alina", 311) and nota3 == 7

        stat = srv_statistici.srv_studenti_ordonati("1 2", 'desc', 'n', 1)
        stud1, nota1, stud2, nota2 = stat[0].get_student(), stat[0].get_nota(), stat[1].get_student(), stat[
            1].get_nota()
        stud3, nota3 = stat[2].get_student(), stat[2].get_nota()

        assert stud3 == Student(2, 'Antonovici Traian', 917)
        assert nota3 == 2
        assert stud2 == Student(1, 'Popescu Alexandru', 213)
        assert nota2 == 6
        assert stud1 == Student(3, 'Popovici Alina', 311)
        assert nota1 == 7

        self.assertRaises(ParamError, srv_statistici.srv_studenti_ordonati, "34", 'desc', 'n', 1)
        self.assertRaises(NrLabError, srv_statistici.srv_studenti_ordonati, "a 4", 'desc', 'n', 1)
        self.assertRaises(NrProbError, srv_statistici.srv_studenti_ordonati, "3 -4", 'cresc', 'n', 1)
        self.assertRaises(ExistentaError, srv_statistici.srv_studenti_ordonati, "3 4", 'cresc', 'n', 1)
Exemple #24
0
    def test_addstudentservice(self):
        stud = Student('123','Mark Park','912')
        self.list_s.add_student('123','Mark Park','912')
        try:
            val = Student_Validator()
            val.validate(self.list_s,Student('123','MarkP','112'))
            self.assertFalse('not ok')
        except studentValidatorException as ve:
            s = str(ve)
            self.assertTrue('ok')
        self.assertEqual(len(self.list_s), 1)
        self.assertEqual(len(self.list_s.student_list_service), 1)
        try:
            self.list_s.add_student('123', 'Mark Park', '912')
            self.assertFalse('Not good')
        except studentException:
            self.assertTrue('OK')
        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.assertEqual(len(self.list_s.student_list_service), 4)

        try:
            self.list_s.add_student('12a', 'Mark Park','123')
            self.assertFalse('Not good')
        except studentException:
            self.assertTrue('OK')

        try:
            self.list_s.add_student('392', 'Mark Park','123')
            self.assertFalse('Not good')
        except studentException:
            self.assertTrue('OK')

        try:
            self.list_s.add_student('392', 'Mark P@rk','912')
            self.assertFalse('Not good')
        except studentException:
            self.assertTrue('OK')
Exemple #25
0
    def srv_adaugare_student(self, intrare):
        """
        Functia primeste un sir de caractere, il valideaza, si daca este totul in regula, prelucreaza datele si
        le trimite in repo pentru adaugare.

        :param intrare: Un sir de caractere care ar trebui sa fie datele de intrare pentru student.
        """

        validator_student = ValidatorStudent()

        try:
            validator_student.validare_student(intrare)

            param = intrare.split(", ")
            repo.lista_stud.validare_unicitate_stud_id(-1, param[0])

            stud_id, nume, grupa = param[0], param[1], param[2]
            student = Student(0, 0, 0)

            student.set_stud_id(stud_id)
            student.set_nume(nume)
            student.set_grupa(grupa)

            repo.lista_stud.adaugare_student_file(student)

        except IDError:
            raise IDError(
                "ID-ul studentului este invalid! Introduceti alte date de intrare:"
            )

        except NumeError:
            raise NumeError(
                "Numele studentului este invalid! Introduceti alte date de intrare:"
            )

        except GrupaError:
            raise GrupaError(
                "Grupa studentului este invalida! Introduceti alte date de intrare:"
            )

        except IDUnicError:
            raise IDUnicError(
                "Exista deja un student cu acest ID! Introduceti alte date de intrare:"
            )

        except ParamError:
            raise ParamError(
                "Parametri insuficienti! Introduceti alte date de intrare:")
Exemple #26
0
    def setUp(self):
        student1 = Student(15, "Pop Ion", 213)
        student2 = Student(3, "Alexandrescu Mihai", 917)
        student3 = Student(5, "Ionescu Malina", 316)

        new_content = [student1, student2, student3]
        repo_student.lista_stud.set_content(new_content)

        problema1 = Problema(1, 1, "Management baza de date", dl1)
        problema2 = Problema(3, 1, "Cheltuieli de familie", dl2)
        problema3 = Problema(2, 1, "Cheltuieli service auto", dl3)
        problema4 = Problema(1, 3, "Baza de date studenti", dl4)

        new_content = [problema1, problema2, problema3, problema4]
        repo_problema.lista_prob.set_content(new_content)

        self.a1 = Asignare(repo_student.lista_stud.get_content()[0],
                           repo_problema.lista_prob.get_content()[0])
        self.a2 = Asignare(repo_student.lista_stud.get_content()[0],
                           repo_problema.lista_prob.get_content()[1])
        self.a3 = Asignare(repo_student.lista_stud.get_content()[1],
                           repo_problema.lista_prob.get_content()[1])
        self.a4 = Asignare(repo_student.lista_stud.get_content()[1],
                           repo_problema.lista_prob.get_content()[2])
    def _test_validate_student(self):
        valid_student = ValidationStudent()
        try:
            valid_student.validate_student(self._stud_ok)
            assert True
        except Exception:
            assert False

        self._stud_not_ok = Student(-11, "", -11)
        try:
            valid_student.validate_student(self._stud_not_ok)
            assert False
        except ValidationError as errors:
            assert str(
                errors) == "invalid id!\ninvalid name!\ninvalid group!\n"
    def _test_add_search_student(self):
        self._repo = Repository([])
        assert self._repo.size() == 0

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

        student_key = Student(self._stud_ok.get_student_id(), None, None)
        found_student = self._repo.search(student_key)
        assert found_student.get_name() == self._stud_ok.get_name()

        self._student_sameID = Student(10, "mircea", 987)
        try:
            self._repo.add(self._student_sameID)
            assert False
        except RepoError as error:
            assert str(error) == "id existent\n"

        self._another_student = Student(56, "Iliescu Horea", 976)
        try:
            self._repo.search(self._another_student)
            assert False
        except RepoError as error:
            assert str(error) == "id inexistent\n"
Exemple #29
0
 def _load(self):
     """
     We load the data from file
     """
     try:
         file = open(self._filename, 'rt')
         lines = file.readlines()
         file.close()
         for line in lines:
             line = line.split(";")
             super().add_object(Student(line[0], line[1],
                                        str(int(line[2]))))
     except FileNotFoundError:
         raise RepositoryException(
             f"File {self._filename} does not exist!...\n")
    def test_getters_student(self):
        # White-box testing: testez toate ramurile pentru getteri
        # (ID-ul studentului, numr, grupa, si toate atributele).

        student = Student(1, "Pop Ion", 213)

        assert student.get_stud_id() == 1
        assert student.get_nume() == "Pop Ion"
        assert student.get_grupa() == 213
        assert student.get_all() == (1, "Pop Ion", 213)