Пример #1
0
 def both_return(self, ID):
     try:
         self.__Rcontroller.returnBook(int(ID.get()))
         messagebox.showinfo(
             "INFO", "BOOK RETURNED\n" + str(
                 Rental.printReturned(
                     self.__Rcontroller.getRental(int(ID.get())))))
     except ArithmeticError as exc:
         window = Toplevel(self.master)
         window.pack_propagate(0)
         v = StringVar()
         v.set(str(exc))
         label = Label(window, textvariable=v)
         label.pack()
Пример #2
0
class TestDomain(unittest.TestCase):

    def setUp(self):
        self.client = Client(23, 'alex')
        self.client2 = Client(12, 'diana')
        self.book = Book(21, 'titlu', 'descriere', 'author')
        self.book2 = Book(22, 'titlu2', 'descriere2', 'author2')
        self.rental = Rental(21236, 21, 23, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5))
        self.rental2 = Rental(21236, 21, 23, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5))

    def tearDown(self):
        pass

    def test_create_Client(self):
        # CLIENTS TESTS
        self.assertEqual(23, self.client.getID())
        self.assertEqual('alex', self.client.getName())
        self.client.setName('da')
        self.assertEqual('da', self.client.getName())
        self.assertFalse(self.client == self.client2)
        self.assertEqual(str(self.client), '023. da\n')
        self.assertEqual(self.client.create_client(23, 'alex'), self.client)

    def test_create_book(self):
        self.assertEqual(21, self.book.getID())
        self.assertEqual('titlu', self.book.getTitle())
        self.assertEqual('descriere', self.book.getDescription())
        self.assertEqual('author', self.book.getAuthor())
        self.assertEqual(True, self.book.get_available())
        self.book.setTitle('lol')
        self.assertEqual('lol', self.book.getTitle())
        self.book.setAuthor('da')
        self.assertEqual('da', self.book.getAuthor())
        self.book.setDescription('da')
        self.assertEqual('da', self.book.getDescription())
        self.assertEqual(str(self.book), '021. lol by da\n->da\nStatus: Available\n')
        self.book.set_available(False)
        self.assertEqual(False, self.book.get_available())
        self.assertEqual(str(self.book), '021. lol by da\n->da\nStatus: Unavailable\n')
        self.assertNotEqual(self.book, self.book2)
        self.assertEqual(self.book.create_book(21, 'titlu', 'descriere', 'author'), self.book)

    def test_create_rental(self):
        self.assertEqual(21236, self.rental.getID())
        self.assertEqual(21, self.rental.getBookID())
        self.assertEqual(23, self.rental.getClientID())
        self.assertEqual(date(2017, 12, 6), self.rental.getDueDate())
        self.assertEqual(date(2017, 11, 5), self.rental.getRentedDate())
        self.assertEqual(date(2017, 12, 5), self.rental.getReturnedDate())
        self.assertEqual('Rental 21236: book: 21 rented by client 23 on 05.11.2017 and is due by 06.12.2017', str(self.rental))
        self.rental.setBookID(21)
        self.rental.setClientID(23)
        self.rental.setReturnedDate(date(2017, 12, 12))
        self.rental.setDueDate(date(2017, 11, 21))
        self.rental.setRentedDate(date(2017, 9, 23))
        self.assertEqual(len(self.rental), 80)
        self.rental.setReturnedDate(None)
        self.assertEqual(len(self.rental), 0)
        self.assertEqual(self.rental.getDelay(), (date.today()-self.rental.getDueDate()).days)
        self.assertEqual(self.rental, self.rental2)
        self.rental.setReturnedDate(date(2017, 12, 12))
        self.assertEqual(self.rental.create_rental(21, 23, 12, 5).getBookID(), 21)
        self.assertEqual(self.rental.printReturned(self.rental), 'Rental 21236: book: 21 rented by client 23 on 23.09.2017 was returned on 12.12.2017')
Пример #3
0
    def mainMenu(self):
        UI.printMenu()
        while True:
            try:
                command = input("enter command ").strip()
                if command == '1':

                    book = UI.read_book()
                    self.__Ucontroller.newOperation()
                    self.__Bcontroller.addBook(book)
                    print("book added")
                elif command == '2':
                    client = UI.read_client()
                    self.__Ucontroller.newOperation()
                    self.__Ccontroller.addClient(client)
                    print("client added")
                elif command == '3':
                    ID = self.readInt("Book ID to be removed: ")
                    self.__Ucontroller.newOperation()
                    self.__Bcontroller.removeBook(ID)
                    print("Book removed")
                elif command == '4':
                    ID = self.readInt("Client ID to be removed: ")
                    self.__Ucontroller.newOperation()
                    self.__Ccontroller.removeClient(ID)
                    print("Client removed")
                elif command == '5':
                    print("Book to be updated: ")
                    newbook = UI.read_book()
                    self.__Ucontroller.newOperation()
                    self.__Bcontroller.updateBook(newbook)
                    print("book updated")
                elif command == '6':
                    print("client to be updated: ")
                    self.__Ucontroller.newOperation()
                    newclient = UI.read_client()
                    self.__Ccontroller.updateClient(newclient)
                    print("client updated")
                elif command == '7':
                    for x in self.__Bcontroller.getAllBooks():
                        print(str(x))
                elif command == '8':
                    for x in self.__Ccontroller.getAllClients():
                        print(str(x))
                elif command == '9':
                    rental = UI.read_rental()
                    self.__Ucontroller.newOperation()
                    self.__Rcontroller.addRental(rental)
                    print(rental)
                elif command == '10':
                    for x in self.__Rcontroller.getAllRental():
                        print(str(x))
                elif command == '11':
                    rentalID = self.readInt("Enter rental ID: ")
                    self.__Rcontroller.returnBook(rentalID)
                    print(
                        Rental.printReturned(
                            self.__Rcontroller.getRental(rentalID)))
                elif command == '12':
                    substring = input("Enter keywords: ").lower()
                    for x in self.__Bcontroller.searchBook(substring):
                        print(str(x))
                elif command == '13':
                    substring = input("Enter keywords: ").lower()
                    for x in self.__Ccontroller.searchClient(substring):
                        print(str(x))
                elif command == '14':
                    for x in self.__Rcontroller.mostRentedBooks():
                        print(x)
                elif command == '15':
                    for x in self.__Rcontroller.mostActiveClients():
                        print(x)
                elif command == '16':
                    for x in self.__Rcontroller.mostRentedAuthors():
                        print(x)
                elif command == '17':
                    for x in self.__Rcontroller.lateRentals():
                        print(x)
                elif command == '18':
                    self.__Ucontroller.undo()
                elif command == '19':
                    self.__Ucontroller.redo()
                elif command == 'help':
                    UI.printMenu()
                else:
                    print(
                        "Invalid command. Type 'help' to see available commands"
                    )
            except Exception as exc:
                print(str(exc))