def test_removeRent(self):
     self._repo.addRent(rent(1, 1, 1, 0, 0, 0))
     self.assertEqual(len(self._repo), 1)
     self._repo.addRent(rent(2, 1, 1, 0, 0, 0))
     self.assertEqual(len(self._repo), 2)
     self._repo.removeRent(1)
     self.assertEqual(len(self._repo), 1)
 def test_findIdRent(self):
     self._repo.addRent(rent(1, 2, 1, 0, 0, 0))
     assert self._repo.findIdRent(1) == 0
     self._repo.addRent(rent(2, 43, 1, 0, 0, 0))
     self._repo.addRent(rent(3, 54, 1, 0, 0, 0))
     assert self._repo.findIdRent(2) == 1
     assert self._repo.findIdRent(3) == 2
 def test_findIdClient(self):
     self._repo.addRent(rent(1, 2, 1, 0, 0, 0))
     assert self._repo.findIdClient(1) == 0
     self._repo.addRent(rent(2, 43, 342, 0, 0, 0))
     self._repo.addRent(rent(3, 54, 32, 0, 0, 0))
     assert self._repo.findIdClient(342) == 1
     assert self._repo.findIdClient(32) == 2
 def __loadFromFile(self):
     try:
         f = open(self.__fName, "r")
         line = f.readline().strip()
         while line != "":
             attrs = line.split(",")
             rent_date = attrs[3].split('-')
             due_date = attrs[4].split('-')
             ret_date = attrs[5]
             if ret_date != '0':
                 ret_date = ret_date.split('-')
                 ret_date = datetime.date(int(ret_date[0]),
                                          int(ret_date[1]),
                                          int(ret_date[2]))
             rent_date = datetime.date(int(rent_date[0]), int(rent_date[1]),
                                       int(rent_date[2]))
             due_date = datetime.date(int(due_date[0]), int(due_date[1]),
                                      int(due_date[2]))
             rents = rent(int(attrs[0]), int(attrs[1]), int(attrs[2]),
                          rent_date, due_date, ret_date)
             rentRep.addRent(self, rents)
             line = f.readline().strip()
     except IOError:
         raise RepositoryException("Error saving file")
     finally:
         f.close()
 def removeRent(self, id, recordForUndo=True):
     rento = self.__repo.getRentById(id)
     self.__repo.removeRent(id)
     if recordForUndo == False:
         return
     undo = FunctionCall(
         self.addRent,
         rent(rento.get_id(), rento.get_bookId(), rento.get_client(),
              rento.getRent(), rento.getDue(), rento.getRet()), False)
     redo = FunctionCall(self.removeRent, id, False)
     operation = [Operation(redo, undo)]
     self._undoController.recordOperation(operation)
 def addRent(self, item, recordForUndo=True):
     self.__repo.addRent(item)
     if recordForUndo == False:
         return
     undo = FunctionCall(self.removeRent, self.findIdRent(item.get_id()),
                         False)
     redo = FunctionCall(
         self.addRent,
         rent(item.get_id(), item.get_bookId(), item.get_client(),
              item.getRent(), item.getDue(), item.getRet()), False)
     operation = [Operation(redo, undo)]
     self._undoController.recordOperation(operation)
Beispiel #7
0
 def mainMenu(self):
     UI.printMenu()
     while True:
         command = input(">> ").strip()
         if command == '0':
             print("exit...")
             break
         elif command == '1':
             ok = True
             id = 0
             while ok:
                 try:
                     id = int(input("Id: "))
                     if self.bookC.findIdBook(id) != -1:
                         print("We already have that id!")
                     else:
                         ok = False
                 except ValueError:
                     print("Id must be number!")
             z = UI.readBook(id)
             self.bookC.addBook(z)
         elif command == '2':
             ok = True
             id = 0
             while ok:
                 try:
                     id = int(input("Id: "))
                     if self.clientC.findIdClient(id) != -1:
                         print("We already have that id!")
                     else:
                         ok = False
                 except ValueError:
                     print("Id must be number!")
             z = UI.readClient(id)
             self.clientC.addClient(z, True)
         elif command == '3':
             ok = True
             old_id = 0
             while ok:
                 try:
                     old_id = int(input("The old id: "))
                     if self.bookC.findIdBook(old_id) == -1:
                         print("We don't have that id!")
                     else:
                         ok = False
                 except ValueError:
                     print("Id must be number!")
             z = UI.readUpBook(old_id)
             self.bookC.updateBook(z, old_id)
         elif command == '4':
             ok = True
             old_id = 0
             while ok:
                 try:
                     old_id = int(input("Id: "))
                     if self.clientC.findIdClient(old_id) == -1:
                         print("We don't have that id!")
                     else:
                         ok = False
                 except ValueError:
                     print("Id must be number!")
             z = UI.readUpClient(old_id)
             self.clientC.updateClient(z, old_id)
         elif command == '5':
             id = 0
             ok = True
             while ok:
                 try:
                     id = int(input("The id of the deleted element: "))
                     if self.bookC.findIdBook(id) == -1:
                         print("We don't have that id!")
                     else:
                         ok = False
                 except ValueError:
                     print("Id must be number!")
             self.bookC.removeBook(id)
         elif command == '6':
             id = 0
             ok = True
             while ok:
                 try:
                     id = int(input("The id of the deleted element: "))
                     if self.clientC.findIdClient(id) == -1:
                         print("We don't have that id!")
                     else:
                         ok = False
                 except ValueError:
                     print("Id must be number!")
             self.clientC.removeClient(id, True)
         elif command == '7':
             if len(self.clientC.getClient()) == 0:
                 print("We don't have any client!")
             for n in self.clientC.getClient():
                 print(str(n))
                 print("- " * 10)
         elif command == '8':
             if len(self.bookC.getBook()) == 0:
                 print("We don't have any book available!")
             for n in self.bookC.getBook():
                 print(str(n))
                 print("- " * 10)
         elif command == '9':
             clientId = 0
             ok = True
             id = 0
             while ok:
                 try:
                     clientId = int(input("Your id: "))
                     if self.clientC.findIdClient(clientId) == -1:
                         print("We don't have that id!")
                     else:
                         ok = False
                 except ValueError:
                     print("Id must be number!")
             ok = True
             while ok:
                 try:
                     id = int(
                         input("The id of the book you want to rent: "))
                     if self.bookC.findIdBook(id) == -1:
                         print("We don't have that book!")
                     else:
                         ok = False
                 except ValueError:
                     print("Id must be number!")
             z = UI.readRent(id, clientId)
             ln = len(self.rentC.getRent())
             today = time.strftime("%d/%m/%Y").split('/')
             d2 = datetime.date(int(today[2]), int(today[1]), int(today[0]))
             k = rent(ln + 1, z[0], z[1], d2,
                      datetime.date(z[4], z[3], z[2]), 0)
             self.rentC.addRent(k)
         elif command == '10':
             ok = True
             id = 0
             rentId = 0
             while ok:
                 try:
                     id = int(input("Book id: "))
                     rentId = self.rentC.findIdRentBook(id)
                     if rentId == -1:
                         print("We don't have that id!")
                     else:
                         ok = False
                 except ValueError:
                     print("Id must be number!")
             today = time.strftime("%d/%m/%Y")
             self.rentC.updateRent(rentId, today)
         elif command == '11':
             if len(self.rentC.getRent()) == 0:
                 print("We don't have any rents!")
             for n in self.rentC.getRent():
                 print(str(n))
                 print("- " * 10)
         elif command == '12':
             val = input("What do you want: ")
             list = self.bookC.searchBook(val)
             for i in list:
                 print(i)
                 print("- " * 10)
         elif command == '13':
             val = input("What do you want: ")
             list = self.clientC.searchClient(val)
             for i in list:
                 print(i)
                 print("- " * 10)
         elif command == '14':
             case = 0
             while True:
                 print("1.Print by number of times rented")
                 print("2.Print by number of days rented")
                 case = input()
                 if case != '1' and case != '2':
                     print("Invalid input!")
                 else:
                     break
             list = self.bookC.statBook(case, self.rentC)
             for i in list:
                 print(str(i[1]))
                 if case == '1':
                     print("For", i[0], "times")
                 else:
                     print("For", i[0], "days")
                 print("- " * 10)