def test_srv_remove_client(self): self.Srv.add_client(12, "Name1", True) self.Srv.add_client(13, "Name2", True) assert(len(self.Srv.list_clients()) == 2) self.Srv.remove_client(12, True) assert(len(self.Srv.list_clients()) == 1) UndoManager.undo()
def test_srv_update_book(self): self.Srv.add_book(12, "Title", "Author", True) self.Srv.update_book(12, "aaa", "bbb", True) b = self.Srv.get_book_by_id(12) assert(b.bookTitle == "aaa") assert(b.bookAuthor == "bbb") UndoManager.undo()
def test_srv_remove_book(self): self.Srv.add_book(12, "Title1", "Author1", True) self.Srv.add_book(14, "Title2", "Author1", True) assert(len(self.Srv.list_books()) == 2) self.Srv.remove_book(12, True) assert(self.Srv.get_no_books() == 1) UndoManager.undo()
def test_srv_add_rental(self): self.Srv.add_book(1, "Title", "Author", True) self.Srv.add_client(1, "Name", True) self.Srv.add_rental(12, 1, 1, datetime.date(2019, 10, 11), None, True) self.Srv.update_rental(12, datetime.date(2019, 11, 10), True) assert(self.Srv.list_rental()[0]._rentalID == 12) UndoManager.undo()
def test_srv_remove_rental(self): self.Srv.add_book(1, "Title", "Author", True) self.Srv.add_client(1, "Name", True) self.Srv.add_rental(12, 1, 1, datetime.date(2019, 10, 11), None, True) self.Srv.remove_rental(12, True) assert(len(self.Srv.list_rental()) == 0) UndoManager.undo()
def add_book(self, bookId, bookName, bookAuthor, u): #adds a new book to the list of books #bookId = (str) the book ID, bookName = (str) the name of the book, bookAuthor = (str) the Author of the book book = Book(bookId, bookName, bookAuthor) self._validator.validate_book(book) self._booksList.add(book) if u == True: UndoManager.register_operation(self, UndoHandler.ADD_BOOK, int(bookId), bookName, bookAuthor)
def add_client(self, clientId, clientName, u): #adds a new client to the list of clients #clientID = (int) the client ID, clientName = (str) the name of the client client = Client(clientId, clientName) self._validatorClient.validate_client(client) self._clientsList.add(client) if u == True: UndoManager.register_operation(self, UndoHandler.ADD_CLIENT, int(clientId), clientName)
def remove_rental(self, rentalId, u): rent = Rental(int(rentalId), None, None, None, None) rent = self._repoRental.search(rent) #print(self._repoRental.size()) self._repoRental.remove(rent) if u == True: UndoManager.register_operation(self, UndoHandler.REMOVE_RENTAL, rent.rentalID, rent.book.bookID, rent.client.clientID, rent.rentedDate, rent.returnedDate)
def remove_client(self, clientId, u): #removes a client from the list of clients #clientId = (str) the client ID which has to be removed client = Client(clientId, None) client = self._clientsList.search(client) #print(client.clientName) self._clientsList.remove(client) if u == True: rlist = self._repoRental.remove_client(int(clientId)) UndoManager.register_operation(self, UndoHandler.REMOVE_CLIENT, clientId, client.clientName, rlist)
def remove_book(self, bookId, u): #removes a book from the list of books #bookId = (str) the book ID which has to be removed book = Book(int(bookId), None, None) book = self._booksList.search(book) self._booksList.remove(book) #self._repoRental.remove_book(int(bookId)) blist = self._repoRental.remove_book(int(bookId)) if u == True: UndoManager.register_operation(self, UndoHandler.REMOVE_BOOK, int(bookId), book.bookTitle, book.bookAuthor, blist)
def update_client(self, clientId, clientName, u): #updates a client with a new Title and a new Author #clientId = (str) the client ID which has to be updated #clientName = (str) the new client Name client = Client(clientId, clientName) self._validatorClient.validate_client(client) client2 = self._clientsList.search(client) self._clientsList.update(client) if u == True: UndoManager.register_operation(self, UndoHandler.UPDATE_CLIENT, client2.clientID, client2.clientName)
def update_book(self, bookId, bookTitle, bookAuthor, u): #updates a book with a new Title and a new Author #bookId = (str) the book ID which has to be updated #bookTitle = (str) the new book Title #bookAuthor = (str) the new book Author book = Book(bookId, bookTitle, bookAuthor) self._validator.validate_book(book) book2 = self._booksList.search(book) self._booksList.update(book) if u == True: UndoManager.register_operation(self, UndoHandler.UPDATE_BOOK, book2.bookID, book2.bookTitle, book2.bookAuthor)
def update_rental(self, rentalId, returnedDate, u): #updates a rental by adding its returnedDate #rentalID = (int) the rental ID #returnedDate = (date) the returnedDate rent = Rental(rentalId, None, None, None, returnedDate) book = self._repoRental.search(rent).book client = self._repoRental.search(rent).client rentedDate = self._repoRental.search(rent).rentedDate rent = Rental(rentalId, book, client, rentedDate, returnedDate) self._validatorRental.validate_rental(rent) rent2 = self._repoRental.search(rent) self._repoRental.update(rent) if u == True: UndoManager.register_operation(self, UndoHandler.UPDATE_RENTAL, int(rentalId), book.bookID, client.clientID, rentedDate, rent2.returnedDate)
def add_rental(self, rentalId, bookId, clientId, rentedDate, returnedDate, u): #adds a new rental to the list of rentals #rentalID = (int) the rental ID #bookID = (int) the book ID #clientID = (int) the client ID #rentedDate = (date) the rentedDate #returnedDate = (date) the returnedDate rent = Rental(rentalId, Book(bookId, None, None), Client(clientId, None), rentedDate, returnedDate) book = self._booksList.search(rent.book) client = self._clientsList.search(rent.client) rent = Rental(rentalId, book, client, rentedDate, returnedDate) self._validatorRental.validate_rental(rent) self._repoRental.search_unique(rent) self._repoRental.add(rent) if u == True: UndoManager.register_operation(self, UndoHandler.ADD_RENTAL, int(rentalId), int(bookId), int(clientId), rentedDate, returnedDate)
def undo(self): UndoManager.undo()
def test_srv_update_client(self): self.Srv.add_client(12, "Name1", True) self.Srv.update_client(12,"aaa", True) assert(self.Srv.list_clients()[0].clientName == "aaa") UndoManager.undo()
def test_srv_add_client(self): self.Srv.add_client(12, "Name1", True) assert(len(self.Srv.list_clients()) == 1) UndoManager.undo()
def test_srv_add_book(self): self.Srv.add_book(12, "Title1", "Author1", True) assert(len(self.Srv.list_books()) == 1) UndoManager.undo()