class TestBookController(unittest.TestCase):
    def setUp(self):
        self.repo = Repository()
        self.rentalRepo = Repository()
        self.Ucontroller = UndoController()
        self.book = Book(21, 'titlu', 'descriere', 'author')
        self.book2 = Book(22, 'titlu2', 'descriere2', 'author2')
        self.controller = BookController(self.repo, self.Ucontroller,
                                         self.rentalRepo)

    def test_something(self):
        self.Ucontroller.newOperation()
        self.controller.addBook(self.book)
        self.assertEqual(len(self.repo), 1)
        self.Ucontroller.newOperation()
        self.controller.removeBook(21)
        self.assertEqual(len(self.repo), 0)
        self.Ucontroller.newOperation()
        self.controller.addBook(self.book)
        self.Ucontroller.newOperation()
        self.controller.updateBook(self.book)
        self.Ucontroller.newOperation()
        self.controller.addBook(self.book2)
        self.assertEqual(len(self.controller.getAllBooks()), 2)
        self.assertEqual(self.controller.getBook(22), self.book2)
        self.assertRaises(ControllerException, self.controller.searchBook,
                          'nu')
        self.assertRaises(ControllerException, self.controller.searchBook, '')
        self.assertEqual(len(self.controller.searchBook('tit')), 2)
        self.Ucontroller.newOperation()
        self.controller.removeBook(22)
        self.assertEqual(
            str(self.controller),
            '021. titlu by author\n->descriere\nStatus: Available\n\n')
class TestRentalController(unittest.TestCase):
    def setUp(self):
        self.repo = Repository()
        self.brepo = Repository()
        self.crepo = Repository()
        self.Ucontroller = UndoController()
        self.book = Book(21, 'titlu', 'descriere', 'author')
        self.book2 = Book(22, 'titlu2', 'descriere2', 'author')
        self.brepo.add(self.book)
        self.brepo.add(self.book2)
        self.client = Client(23, 'alex')
        self.client2 = Client(24, 'ana')
        self.client3 = Client(29, 'ana')

        self.crepo.add(self.client)
        self.crepo.add(self.client2)
        self.rental = Rental(21236, 21, 24, date(2017, 11, 5),
                             date(2017, 12, 6), date(2017, 12, 5))
        self.rental2 = Rental(21238, 22, 24, date(2017, 11, 5),
                              date(2017, 12, 6), date(2017, 12, 5))
        self.rental3 = Rental(21238, 23, 24, date(2017, 11, 5),
                              date(2017, 12, 6), date(2017, 12, 5))
        self.rental4 = Rental(21238, 21, 29, date(2017, 11, 5),
                              date(2017, 12, 6), date(2017, 12, 5))
        self.rental5 = Rental(21231, 21, 23, date(2017, 11, 5),
                              date(2017, 10, 6), None)

        self.controller = RentalController(self.repo, self.brepo, self.crepo,
                                           self.Ucontroller)
        self.ceva = LateRentalCount(12, 32)
        self.altceva = BookRentalCount(12, 23)
        self.nu = AuthorRentalCount('da', 23)
        self.da = ClientRentalCount(32, 12)

    def test_controller(self):
        self.Ucontroller.newOperation()
        self.controller.addRental(self.rental2)
        self.assertEqual(len(self.repo), 1)
        self.assertEqual(self.controller.getRental(21238).getID(), 21238)
        self.assertRaises(ControllerException, self.controller.addRental,
                          self.rental3)
        self.assertRaises(ControllerException, self.controller.addRental,
                          self.rental4)
        self.book2.set_available(False)
        self.assertRaises(ControllerException, self.controller.addRental,
                          self.rental2)
        self.assertRaises(ControllerException, self.controller.returnBook,
                          13123124)
        self.Ucontroller.newOperation()
        self.controller.addRental(self.rental)
        self.assertEqual(self.controller.returnBook(21236), self.rental)
        self.assertEqual(len(self.controller.getAllRental()), 2)
        self.assertEqual(len(self.controller.mostRentedBooks()), 2)
        self.assertEqual(len(self.controller.mostActiveClients()), 2)
        self.assertEqual(len(self.controller.mostRentedAuthors()), 1)
        self.controller.deleteRental(self.rental.getID())
        self.Ucontroller.newOperation()
        self.controller.addRental(self.rental5)
        self.assertEqual(len(self.controller.lateRentals()), 1)
        self.assertEqual(self.ceva.getBook(), 12)
        self.assertEqual(self.ceva.getCount(), 32)
        self.assertFalse(self.ceva > self.ceva)
        self.assertEqual(str(self.ceva),
                         'Book 12 has been overdue for 32 days')
        self.assertEqual(self.altceva.getCount(), 23)
        self.assertEqual(self.altceva.getBook(), 12)
        self.assertFalse(self.altceva > self.altceva)
        self.assertEqual(str(self.altceva), 'Book 12 was rented 23 times')
        self.assertEqual(self.nu.getBook(), 'da')
        self.assertEqual(self.nu.getCount(), 23)
        self.assertEqual(str(self.nu), 'Author da was rented for 23 times')
        self.assertFalse(self.nu > self.nu)
        self.assertFalse(self.da > self.da)
        self.assertEqual(str(self.da),
                         'Client 32 has rented books for 12 days')
        self.assertEqual(self.da.getCount(), 12)
        self.assertEqual(self.da.getBook(), 32)
class TestClientController(unittest.TestCase):
    def setUp(self):
        self.repo = Repository()
        self.rentalRepo = Repository()
        self.Ucontroller = UndoController()
        self.client = Client(11, 'alex')
        self.client2 = Client(12, 'ana')
        self.controller = ClientController(self.repo, self.Ucontroller,
                                           self.rentalRepo)

    def test_something(self):
        self.assertRaises(Exception, self.Ucontroller.undo)
        self.assertRaises(Exception, self.Ucontroller.redo)
        self.Ucontroller.newOperation()
        self.controller.addClient(self.client)
        self.assertEqual(len(self.repo), 1)
        self.Ucontroller.newOperation()
        self.controller.removeClient(11)
        self.assertEqual(len(self.repo), 0)
        self.Ucontroller.newOperation()
        self.controller.addClient(self.client)
        self.Ucontroller.newOperation()
        self.controller.updateClient(self.client)
        self.Ucontroller.newOperation()
        self.controller.addClient(self.client2)
        self.assertEqual(len(self.controller.getAllClients()), 2)
        self.assertRaises(ControllerException, self.controller.searchClient,
                          'nu')
        self.assertRaises(ControllerException, self.controller.searchClient,
                          '')
        self.assertEqual(len(self.controller.searchClient('a')), 2)
        self.Ucontroller.newOperation()
        self.controller.removeClient(12)
        self.Ucontroller.undo()
        self.assertEqual(len(self.controller.getAllClients()), 2)
        self.Ucontroller.redo()
        self.assertEqual(len(self.controller.getAllClients()), 1)
Exemple #4
0
def undoTest():
    '''
    '''
    undoController = UndoController()
    studentRepo = Repository()
    disciplineRepo = Repository()
    
    
    '''
    Start grade Controller
    '''
    gradeRepo = GradeRepository()
    gradeValidator = GradeValidator()
    gradeController = GradeControllerWithUndo(undoController, gradeRepo, gradeValidator, studentRepo, disciplineRepo)
    
    '''
    Start student Controller
    '''
    studentValidator = StudentValidator()
    studentController = StudentControllerWithUndo(undoController, studentRepo, studentValidator, gradeController)
    
    '''
    Start discipline Controller
    '''
    disciplineValidator = DisciplineValidator()
    disciplineController = DisciplineControllerWithUndo(undoController, disciplineRepo, disciplineValidator, gradeController)
    #######################################################
    
    
    undoController.newOperation()
    studentA = studentController.addStudent("cc11", "Ion")

    undoController.newOperation()
    studentB = studentController.addStudent("ab133", "Ana")
    
    undoController.newOperation()
    studentC = studentController.addStudent("1", "George")
    
    undoController.newOperation()
    studentD = studentController.addStudent("2", "Mihai")
    
    
    '''
    print("Len of Student Controller: ", len(studentController))
    print(msg)
    print(studentController)
    undoController.undo()
    undoController.undo()
    undoController.undo()
    undoController.undo()
    print(msg)
    
    print("Len of Student Controller: ", len(studentController))
    print(msg)   
    
    undoController.redo()
    undoController.redo()
    undoController.redo()
    undoController.redo()
     
    print("Len of Student Controller: ", len(studentController))
    print(msg)   
    print(studentController)
    '''
    
    undoController.newOperation()
    disciplineA = disciplineController.addDiscipline("1", "Math")
    
    undoController.newOperation()
    disciplineB = disciplineController.addDiscipline("2", "Physics")
    
    undoController.newOperation()
    disciplineC = disciplineController.addDiscipline("3", "Grammar")
    
    undoController.newOperation()
    disciplineD = disciplineController.addDiscipline("4", "C++")
    
    '''
    print("Len of DisciplineController Controller: ", len(disciplineController))
    print(msg)
    print(disciplineController)
    undoController.undo()
    undoController.undo()
    undoController.undo()
    undoController.undo()
    print(msg)
    
    print("Len of DisciplineController Controller: ", len(disciplineController))
    print(msg)
    print(disciplineController)
    
    undoController.redo()
    undoController.redo()
    undoController.redo()
    undoController.redo()
    print(msg)
    print("Len of DisciplineController Controller: ", len(disciplineController))
    print(disciplineController)
    '''
    
    gradeController.enrollStudent("1", "cc11", [0])
    gradeController.addGrade("1", "cc11", [7])
    gradeController.addGrade("1", "cc11", [10])
    
    gradeController.enrollStudent("2", "cc11", [0])
    gradeController.addGrade("2", "cc11", [9])
    gradeController.addGrade("2", "cc11", [2])
    
    gradeController.enrollStudent("1", "ab133", [0])
    gradeController.addGrade("1", "ab133", [10])
    gradeController.addGrade("1", "ab133", [3])
    
    gradeController.enrollStudent("1", "1", [0])
    gradeController.addGrade("1", "1", [10])
    gradeController.addGrade("1", "1", [3])
    
    print(msg)
    print("Len of GradeController: ", len(gradeController))
    print(gradeController)
    print(msg)
    
    undoController.newOperation()
    studentController.removeStudent("1")
    
    undoController.newOperation()
    studentController.removeStudent("ab133")
    
    print(msg)
    print(studentController)
    print(msg)
    print(msg)
    
    print("Len of GradeController: ", len(gradeController))
    print(gradeController)
    
    undoController.undo()
    print(gradeController)
    
    
    undoController.undo()
    print(gradeController)