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)
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 testSearch(self): self.assertRaises(RepoException, self.repo.search, Nota(1, 0, 0, 0)) self.repo.store(Nota(1, 1, 7, 9)) result_nota = self.repo.search(Nota(1, 0, 0, 0)) self.assertEquals(result_nota.get_idNota(), 1) self.assertEquals(result_nota.get_idStudent(), 1) self.assertEquals(result_nota.get_idDisciplina(), 7) self.assertEquals(result_nota.get_punctaj(), 9)
def testCauta(self): key_nota = Nota(10, 0, 0, 0) result_nota = self.ctr.cauta_nota(key_nota) self.assertEquals(result_nota.get_idNota(), 10) self.assertEquals(result_nota.get_idStudent(), 1) self.assertEquals(result_nota.get_idDisciplina(), 7) self.assertEquals(result_nota.get_punctaj(), 9.8) key_nota = Nota(30, 0, 0, 0) self.assertRaises(RepoException, self.ctr.cauta_nota, key_nota)
def testUpdate(self): self.assertRaises(RepoException, self.repo.update, Nota(1, 0, 0, 0)) self.repo.store(Nota(1, 1, 7, 6.7)) result_nota = self.repo.search(Nota(1, 0, 0, 0)) self.assertEquals(result_nota.get_idNota(), 1) self.assertEquals(result_nota.get_idStudent(), 1) self.assertEquals(result_nota.get_idDisciplina(), 7) self.assertEquals(result_nota.get_punctaj(), 6.7) self.repo.update(Nota(1, 1, 30, 10)) result_nota = self.repo.search(Nota(1, 0, 0, 0)) self.assertEquals(result_nota.get_idNota(), 1) self.assertEquals(result_nota.get_idStudent(), 1) self.assertEquals(result_nota.get_idDisciplina(), 30) self.assertEquals(result_nota.get_punctaj(), 10)
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)
def add_nota(self, idNota, idStudent, idDisciplina, punctaj): """ Adauga o nota idNota, idStudent, idDisciplina - numar natural punctaj - numar real pozitiv Post-conditions: ridica ValidationException daca nota nu este valida """ nota = Nota(idNota, idStudent, idDisciplina, punctaj) self.__valid_note.valideaza(nota, self.__repo_studenti, self.__repo_discipline) self.__repo_note.store(nota)
def testModifica(self): nota = Nota(10, 1, 7, 3.5) self.ctr.modifica_nota(nota) result_nota = self.ctr.cauta_nota(nota) self.assertEquals(nota.get_idNota(), result_nota.get_idNota()) self.assertEquals(nota.get_idStudent(), result_nota.get_idStudent()) self.assertEquals(nota.get_idDisciplina(), result_nota.get_idDisciplina()) self.assertEquals(nota.get_punctaj(), result_nota.get_punctaj()) key_nota = Nota(50, 0, 0, 0) self.assertRaises(ValidationException, self.ctr.modifica_nota, key_nota) key_nota = Nota(50, 2, 7, 6.2) self.assertRaises(RepoException, self.ctr.modifica_nota, key_nota)
def __ui_modifica_nota(self): idNota = int(input('Introduceti id-ul notei careia doriti sa ii modificati punctajul: ')) punctaj = float(input('Introduceti noul punctaj: ')) nota = Nota(idNota,0,0,punctaj) result_nota = self.__controller_note.cauta_nota(nota) nota.set_idStudent(result_nota.get_idStudent()) nota.set_idDisciplina(result_nota.get_idDisciplina()) self.__controller_note.modifica_nota(nota)
def TestDelNota(): repoNota = RepoNota() st = Student(2, "mihai", 215) lab = Laborator(2, 2, "mihai", "22.10.2015") nota = Nota(2, st, lab) repoNota.store_note(nota) l = repoNota.get_all_note() assert len(l) == 1 repoNota.delete_nota(st) l = repoNota.get_all_note() assert len(l) == 0
def __loadFromFile(self): try: f = open(self.__fName, 'r') except IOError: return line = f.readline().strip() rez = [] while line != "": date = line.split(';') nota = Nota(int(date[0]), int(date[1]), int(date[2]), float(date[3])) rez.append(nota) line = f.readline().strip() f.close() return rez
def __loadFromFile(self): try: f = open(self.__fName, "r") except IOError: raise FileRepoError()() line = f.readline().strip() while line != "": attrs = line.split(";") student = self.__studentRepo.searchById(int(attrs[1])) laborator = self.__laboratorRepo.searchById( int(attrs[2]), int(attrs[3])) nota = Nota(int(attrs[0]), student, laborator) RepoNota.store_note(self, nota) line = f.readline().strip() f.close()
def get_all_note(self): note = [] try: f = open(self.__fName, "r") except IOError: raise FileRepoError()() line = f.readline().strip() while line != "": attrs = line.split(";") student = self.__studentRepo.searchById(int(attrs[1])) laborator = self.__laboratorRepo.searchById( int(attrs[2]), int(attrs[3])) nota = Nota(int(attrs[0]), student, laborator) note.append(nota) line = f.readline().strip() f.close() return note
def addNota(self, idStudent, nrLab, nrPrb, mark): lab = self.__repoLaborator.searchById(nrLab, nrPrb) student = self.__repoStudent.searchById(idStudent) nota = Nota(mark, student, lab) self.__validNota.valideazaNota(nota) self.__repoNota.store_note(nota)
def __ui_del_nota(self): idNota = int(input('Introduceti id-ul notei pe care doriti sa o stergeti: ')) key_nota = Nota(idNota,0,0,0) self.__controller_note.del_nota(key_nota) print('Nota a fost stearsa din catalog!')
def __ui_cauta_nota(self): idNota = int(input('Introduceti id-ul notei pe care doriti sa o cautati: ')) key_nota = Nota(idNota,0,0,0) result_nota = self.__controller_note.cauta_nota(key_nota) print('Nota cautata este: ',result_nota)
def testNoteFile(self): self.assertEquals(len(self.repo_file_note), 0) self.repo_file_note.store(Nota(1, 1, 1, 10)) self.repo_file_note.store(Nota(2, 2, 2, 6.8)) self.repo_file_note.store(Nota(3, 3, 3, 8.4)) self.assertEquals(len(self.repo_file_note), 3)
def testDelete(self): self.assertEquals(self.ctr.get_nr_note(), 2) self.ctr.del_nota(Nota(10, 0, 0, 0)) self.assertEquals(self.ctr.get_nr_note(), 1) self.assertRaises(RepoException, self.ctr.del_nota, Nota(10, 0, 0, 0))
def testStore(self): self.repo.store(Nota(1, 1, 7, 7.5)) self.repo.store(Nota(2, 2, 7, 5.5)) self.assertEquals(len(self.repo), 2) self.assertRaises(RepoException, self.repo.store, Nota(1, 1, 7, 2))