Exemple #1
0
 def __test_create_disciplina(self):
     disci = Disciplina(10, 'info', 'neagu')
     self.assertEqual(disci.get_id(), 10)
     self.assertEqual(disci.get_nume(), 'info')
     self.assertEqual(disci.get_nume_prof(), 'neagu')
     disci.set_nume('mate')
     self.assertEqual(disci.get_nume(), 'mate')
     disci.set_nume_prof('coada')
     self.assertEqual(disci.get_nume_prof(), 'coada')
     disci1 = Disciplina(10, 'info', 'neagu')
     self.assertTrue(disci == disci1)
     self.__disciplina = disci
Exemple #2
0
class NoteTests(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)

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

    def __test_creeaza_nota(self):
        self.__student = Student(10, 'Bogdan')
        self.__disciplina = Disciplina(1, 'info', 'neagu')
        nota = Nota(self.__student, self.__disciplina, 7)
        self.assertEqual(nota.get_stud(), self.__student)
        self.assertEqual(nota.get_disci(), self.__disciplina)
        self.assertEqual(nota.get_nota(), 7)
        self.assertEqual(
            str(nota),
            self.__student.get_nume() + ' are nota 7 la disciplina ' +
            self.__disciplina.get_nume())
        nota2 = Nota(self.__student, self.__disciplina, 9)
        self.assertFalse(nota == nota2)
        nota.set_nota(9)
        self.assertEqual(nota.get_nota(), 9)
        self.assertTrue(nota == nota2)
        self.__nota = nota

    def __test_valideaza_nota(self):
        valid_nota = ValidatorNota()
        valid_nota.valideaza_nota(self.__nota)
        self.__nota_invalida = Nota(self.__student, self.__disciplina, -5)
        with self.assertRaises(ValidError):
            valid_nota.valideaza_nota(self.__nota_invalida)

    def __test_repo_note(self):
        clear_file('test.txt')
        self.__repo = FileRepo('test.txt', Nota.read_line, Nota.write_line)
        self.assertEqual(self.__repo.size(), 0)
        self.__repo.adauga(self.__nota)
        self.assertEqual(self.__repo.size(), 1)
        self.assertEqual(self.__repo.get_all(), [self.__nota])
        with self.assertRaises(RepoError):
            self.__repo.adauga(self.__nota)
        x = self.__repo.cauta(self.__nota)
        self.assertEqual(x, self.__nota)
        stud = Student(20, '')
        disci = Disciplina(20, '', '')
        self.__nota_inexistenta = Nota(stud, disci, 4)
        with self.assertRaises(RepoError):
            x = self.__repo.cauta(self.__nota_inexistenta)
        self.__nota_to_modify = self.__nota
        self.__modified_nota = self.__nota
        self.__modified_nota.set_nota(5)
        self.__repo.modifica(self.__nota_to_modify, self.__modified_nota)
        self.assertEqual(self.__nota.get_nota(), 5)
        with self.assertRaises(RepoError):
            self.__repo.sterge(self.__nota_inexistenta)
        self.__repo.sterge(self.__nota)
        assert (self.__repo.size() == 0)

    def run_note_tests(self):
        self.__test_creeaza_nota()
        self.__test_valideaza_nota()
        self.__test_repo_note()