Example #1
0
 def setUp(self):
     self.student1 = Student(1, 'bogdan')
     self.student2 = Student(1, 'alex')
     self.disciplina1 = Disciplina(1, 'informatica', 'prof1')
     self.disciplina2 = Disciplina(1, 'matematica', 'prof2')
     self.nota1 = Nota(1, 1, 1, 5.5)
     self.nota2 = Nota(1, 2, 2, 8.6)
Example #2
0
 def setUp(self):
     validator = ValidatorDisc()
     self.ctr = ControllerDisc(RepositoryDisc(), validator)
     disciplina1 = Disciplina(1, 'informatica', 'prof1')
     disciplina2 = Disciplina(2, 'matematica', 'prof2')
     self.ctr.add_disciplina(1, 'informatica', 'prof1')
     self.ctr.add_disciplina(2, 'matematica', 'prof2')
Example #3
0
class TestCaseDomain(unittest.TestCase):
    def setUp(self):
        self.student1 = Student(1, 'bogdan')
        self.student2 = Student(1, 'alex')
        self.disciplina1 = Disciplina(1, 'informatica', 'prof1')
        self.disciplina2 = Disciplina(1, 'matematica', 'prof2')
        self.nota1 = Nota(1, 1, 1, 5.5)
        self.nota2 = Nota(1, 2, 2, 8.6)

    def tearDown(self):
        unittest.TestCase.tearDown(self)

    def testStudent(self):
        self.assertEquals(self.student1.get_idStudent(), 1)
        self.assertEquals(self.student1.get_nume(), 'bogdan')
        self.assertEquals(str(self.student1), '1 bogdan')
        self.assertEquals(self.student1, self.student2)

    def testDisciplina(self):
        self.assertEquals(self.disciplina1.get_idDisciplina(), 1)
        self.assertEquals(self.disciplina1.get_nume(), 'informatica')
        self.assertEquals(self.disciplina1.get_profesor(), 'prof1')
        self.assertEquals(str(self.disciplina1), '1 informatica prof1')
        self.assertEquals(self.disciplina1, self.disciplina2)

    def testNota(self):
        self.assertEquals(self.nota1.get_idNota(), 1)
        self.assertEquals(self.nota1.get_idStudent(), 1)
        self.assertEquals(self.nota1.get_idDisciplina(), 1)
        self.assertEquals(self.nota1.get_punctaj(), 5.5)
        self.assertEquals(str(self.nota1), '1 1 1 5.5')
        self.assertEquals(self.nota1, self.nota2)
Example #4
0
 def testCauta(self):
     key_disc = Disciplina(1, '', '')
     result_disc = self.ctr.cauta_disciplina(key_disc)
     self.assertEquals(result_disc.get_idDisciplina(), 1)
     self.assertEquals(result_disc.get_nume(), 'informatica')
     self.assertEquals(result_disc.get_profesor(), 'prof1')
     key_disc = Disciplina(3, '', '')
     self.assertRaises(RepoException, self.ctr.cauta_disciplina, key_disc)
Example #5
0
 def testSearch(self):
     self.assertRaises(RepoException, self.repo.search,
                       Disciplina(1, '', ''))
     self.repo.store(Disciplina(1, 'info', 'p'))
     result_disc = self.repo.search(Disciplina(1, '', ''))
     self.assertEquals(result_disc.get_idDisciplina(), 1)
     self.assertEquals(result_disc.get_nume(), 'info')
     self.assertEquals(result_disc.get_profesor(), 'p')
Example #6
0
 def testRemove(self):
     self.assertRaises(RepoException, self.repo.remove,
                       Disciplina(1, 'info', 'p'))
     self.repo.store(Disciplina(1, 'info', 'p1'))
     self.repo.store(Disciplina(2, 'mate', 'p2'))
     self.assertEquals(len(self.repo), 2)
     self.repo.remove(Disciplina(1, '', ''))
     self.assertEquals(len(self.repo), 1)
     self.assertRaises(RepoException, self.repo.remove,
                       Disciplina(1, '', ''))
Example #7
0
    def setUp(self):
        self.valid_stud = ValidatorStud()
        self.student_valid = Student(1, 'bogdan')
        self.student_invalid = Student(-23, '')
        self.valid_disc = ValidatorDisc()
        self.disciplina_valida = Disciplina(2, 'informatica', 'prof')
        self.disciplina_invalida = Disciplina(-59, '', '')
        self.valid_nota = ValidatorNota()
        self.nota_valida = Nota(3, 1, 2, 7.5)
        self.nota_invalida = Nota(-1, -25, -28, 0.5)

        self.repo_stud = RepositoryStud()
        self.repo_stud.store(self.student_valid)
        self.repo_disc = RepositoryDisc()
        self.repo_disc.store(self.disciplina_valida)
Example #8
0
    def valideaza(self,nota,repo_studenti,repo_discipline):
        """
        Valideaza o nota
        Ridica o exceptie in cazul in care nota nu este valida
        """
        errors = ''
        if nota.get_idNota() < 0 :
            errors += 'id invalid!\n'

        idStudent = nota.get_idStudent()
        student = Student(idStudent,'')
        try:
            result_stud = repo_studenti.search(student)
            gasit_stud = True
        except RepoException:
            gasit_stud = False
        if nota.get_idStudent() < 0 or gasit_stud == False:
            errors += 'id student invalid!\n'
        
        idDisciplina = nota.get_idDisciplina()
        disciplina = Disciplina(idDisciplina,'','')
        try:
            result_disc = repo_discipline.search(disciplina)
            gasit_disc = True
        except RepoException:
            gasit_disc = False
        if nota.get_idDisciplina() < 0 or gasit_disc == False:
            errors += 'id disciplina invalid!\n'
        
        if nota.get_punctaj() < 1 or nota.get_punctaj()>10:
            errors += 'punctaj invalid!\n'
        
        if len(errors) > 0:
            raise ValidationException(errors)
Example #9
0
 def __ui_cauta_disciplina(self):
     """
     Citirea de la consola a datelor pentru cautarea unei discipline
     """
     idDisciplina = int(input('Introduceti id-ul disciplinei pe care doriti sa o cautati: '))
     key_disc = Disciplina(idDisciplina,'','')
     result_disciplina = self.__controller_disciplina.cauta_disciplina(key_disc)
     print("Disciplina cautata este: ",result_disciplina)
Example #10
0
 def __ui_del_disciplina(self):
     """
     Citirea de la consola a datelor pentru stergerea unei discipline
     """
     idDisciplina = int(input('Introduceti id-ul disciplinei pe care doriti sa o stergeti: '))
     key_disc = Disciplina(idDisciplina,'','')
     self.__controller_disciplina.del_disciplina(key_disc)
     print('Disciplina a fost stearsa din catalog!')
Example #11
0
 def __ui_modifica_disciplina(self):
     """
     Citirea de la consola a datelor pentru modificarea unei discipline
     """
     idDisciplina = int(input('Introduceti id-ul disciplinei pe care doriti sa o modificati: '))
     nume = input('Introduceti numele nou al disciplinei: ')
     profesor = input('Introduceti numele nou al profesorului: ')
     disciplina = Disciplina(idDisciplina,nume,profesor)
     self.__controller_disciplina.modifica_disciplina(disciplina)
Example #12
0
 def add_disciplina(self, idDisciplina, nume, profesor):
     """
     Adauga o disciplina in repository
     idDisciplina - numar
     nume - string
     """
     disciplina = Disciplina(idDisciplina, nume, profesor)
     self.__validator_discipline.valideaza(disciplina)
     self.__repo_discipline.store(disciplina)
Example #13
0
 def __loadFromFile(self):
     try:
         f = open(self.__fName, 'r')
     except IOError:
         return
     line = f.readline().strip()
     rez = []
     while line != "":
         date = line.split(';')
         disc = Disciplina(int(date[0]), date[1], date[2])
         rez.append(disc)
         line = f.readline().strip()
     f.close()
     return rez
Example #14
0
 def testModifica(self):
     disciplina3 = Disciplina(1, 'fundamentele programarii', 'prof3')
     self.ctr.modifica_disciplina(disciplina3)
     result_disc = self.ctr.cauta_disciplina(disciplina3)
     self.assertEquals(disciplina3.get_idDisciplina(),
                       result_disc.get_idDisciplina())
     self.assertEquals(disciplina3.get_nume(), result_disc.get_nume())
     self.assertEquals(disciplina3.get_profesor(),
                       result_disc.get_profesor())
     key_disc = Disciplina(5, '', '')
     self.assertRaises(ValidationException, self.ctr.modifica_disciplina,
                       key_disc)
     key_disc = Disciplina(5, 'sport', 'prof5')
     self.assertRaises(RepoException, self.ctr.modifica_disciplina,
                       key_disc)
Example #15
0
 def testDiscFile(self):
     self.assertEquals(len(self.repo_file_disc), 0)
     self.repo_file_disc.store(Disciplina(1, 'info', 'p1'))
     self.repo_file_disc.store(Disciplina(2, 'mate', 'p2'))
     self.repo_file_disc.store(Disciplina(3, 'sport', 'p3'))
     self.assertEquals(len(self.repo_file_disc), 3)
Example #16
0
 def testDelete(self):
     self.assertEquals(self.ctr.get_nr_discipline(), 2)
     self.ctr.del_disciplina(Disciplina(1, '', ''))
     self.assertEquals(self.ctr.get_nr_discipline(), 1)
     self.assertRaises(RepoException, self.ctr.del_disciplina,
                       Disciplina(1, '', ''))