Example #1
0
    def valideaza_student(self):
        studValid = Student(25, "Japonia")
        stud_id_invalid = Student(-5, "grecia")
        stud_nume_invalid = Student(5, "")
        studInvalid = Student(-5, "")
        validStud = ValidatorStudent()

        validStud.valideaza_student(studValid)
        try:
            validStud.valideaza_student(stud_id_invalid)
            assert False
        except ValidError as ve:
            assert str(ve) == "id invalid!\n"

        try:
            validStud.valideaza_student(stud_nume_invalid)
            assert False
        except ValidError as ve:
            assert str(ve) == "nume invalid!\n"

        try:
            validStud.valideaza_student(studInvalid)
            assert False
        except ValidError as ve:
            assert str(ve) == "id invalid!\nnume invalid!\n"
Example #2
0
 def repo_adauga_student(self):
     student = Student(25, "laris")
     repo_stud = Repo()
     assert repo_stud.size() == 0
     repo_stud.adauga(student)
     assert repo_stud.size() == 1
     student = Student(25, "lala")
     try:
         repo_stud.adauga(student)
         assert False
     except RepoError as re:
         assert str(re) == "item deja existent!\n"
Example #3
0
 def modifica_student(self):
     student = Student(25, "laris")
     repo_stud = Repo()
     repo_stud.adauga(student)
     nume_change = "Andrei"
     cheie_stud = Student(24, None)
     try:
         repo_stud.cauta(cheie_stud)
         assert False
     except RepoError as re:
         assert str(re) == "item inexistent"
     cheie_stud = Student(25, None)
     stud_gasit = repo_stud.cauta(cheie_stud)
     repo_stud.modifica(stud_gasit, nume_change)
     assert repo_stud.cauta(stud_gasit).get_nume() == nume_change
Example #4
0
    def caut_stud(self):
        student = Student(1, "Andrei")
        repo = Repo()

        repo.adauga(student)
        cheie = Student(2, None)

        try:
            repo.cauta(cheie)
            assert False
        except RepoError as re:
            assert str(re) == "item inexistent"
        cheie = Student(1, None)
        gasit = repo.cauta(cheie)
        assert gasit.get_id() == 1
        assert gasit.get_nume() == "Andrei"
Example #5
0
    def repo_delete_student(self):
        student = Student(25, "andrei")
        repo = Repo()

        repo.adauga(student)
        assert repo.size() == 1
        cheie_student = Student(24, None)
        try:
            repo.delete(cheie_student)
            assert False
        except RepoError as re:
            assert str(re) == "item inexistent"

        cheie_student = Student(25, None)
        repo.delete(cheie_student)
        assert repo.size() == 0
Example #6
0
    def creaza_student(self):
        st_id = 5
        st_name = "Hamsie"
        student = Student(st_id, st_name)

        assert student.get_id() == st_id
        assert student.get_nume() == st_name

        student.set_nume("Ricardo")
        assert student.get_nume() == "Ricardo"

        student2 = Student(5, "hail")
        assert student == student2
Example #7
0
    def test_validare_nota(self):
        nota_negativa = Nota(1, -3, 2)
        nota_prea_mare = Nota(1, 12, 2)
        nota_student_inexistent = Nota(5, 7, 2)
        nota_disc_inexistenta = Nota(1, 7, 3)
        nota = Nota(1, 3, 2)
        stud = Student(1, "Japonia")
        repo_stud = Repo()
        repo_stud.adauga(stud)
        disc = Disciplina(2, "mate", "info")
        repo_disc = Repo()
        repo_disc.adauga(disc)

        valid = ValidatorNote()

        valid.valideaza_note(
            nota, repo_stud.exista(Student(nota.get_student(), None)),
            repo_disc.exista(Disciplina(nota.get_id_disciplina(), None, None)))
        try:
            valid.valideaza_note(
                nota_negativa,
                repo_stud.exista(Student(nota_negativa.get_student(), None)),
                repo_disc.exista(
                    Disciplina(nota_negativa.get_id_disciplina(), None, None)))
            assert False
        except ValidError as ve:
            assert str(ve) == "nota nu poate fi negativa\n"

        try:
            valid.valideaza_note(
                nota_prea_mare,
                repo_stud.exista(Student(nota_prea_mare.get_student(), None)),
                repo_disc.exista(
                    Disciplina(nota_prea_mare.get_id_disciplina(), None,
                               None)))
            assert False
        except ValidError as ve:
            assert str(ve) == "nota nu poate fi mai mare decat 10\n"

        try:
            valid.valideaza_note(
                nota_student_inexistent,
                repo_stud.exista(
                    Student(nota_student_inexistent.get_student(), None)),
                repo_disc.exista(
                    Disciplina(nota_student_inexistent.get_id_disciplina(),
                               None, None)))
            assert False
        except ValidError as ve:
            assert str(
                ve) == "nota nu poate fi data la un student inexistent\n"
        try:
            valid.valideaza_note(
                nota_disc_inexistenta,
                repo_stud.exista(
                    Student(nota_disc_inexistenta.get_student(), None)),
                repo_disc.exista(
                    Disciplina(nota_disc_inexistenta.get_id_disciplina(), None,
                               None)))
            assert False
        except ValidError as ve:
            assert str(
                ve) == "nota nu poate fi data la o materie inexistenta\n"
Example #8
0
 def cauta_student(self, s_id):
     cheie = Student(s_id, None)
     self.__validStudent.valideaza_student(cheie)
     return self.__repoStudent.cauta(cheie)
Example #9
0
 def modify_student(self, s_id, nume_change):
     cheie = Student(s_id, "NONE")
     self.__validStudent.valideaza_student(cheie)
     self.__repoStudent.modifica(cheie, nume_change)
Example #10
0
 def delete_student(self, stud_id):
     cheie = Student(stud_id, "None")
     self.__validStudent.valideaza_student(cheie)
     self.__repoStudent.delete(cheie)
Example #11
0
 def adauga_stud(self, stud_id, nume):
     student = Student(stud_id, nume)
     self.__validStudent.valideaza_student(student)
     self.__repoStudent.adauga(student)