Пример #1
0
    def testDomainRental(self):
        rental = Rental(Rental.getNextId(), 2, 3, createDateFromString("11.12.2017"),
                        createDateFromString("20.12.2017"), None)
        self.assertTrue(rental.getBookId() == 2)
        self.assertTrue(rental.getClientId() == 3)
        self.assertTrue(rental.getRentedDate() == date(2017, 12, 11))
        self.assertTrue(rental.getDueDate() == date(2017, 12, 20))
        self.assertTrue(rental.getReturnDate() is None)

        rental.setReturnDate(date(2017, 12, 15))
        x = str(rental)
        self.assertTrue(rental.getReturnDate() == date(2017, 12, 15))
Пример #2
0
    def rentBook(self, bookId, clientId, currentDate, dueDate):
        """
        
        :param currentDate:
        :param bookId: int
        :param clientId: int
        :param dueDate: date
        :return: a list of errors if any
        """
        rentedDate = currentDate
        dueDate = createDateFromString(dueDate)
        # returnedDate = createDateFromString(returnedDate)

        if bookId == -1 or clientId == -1 or currentDate is None:
            return "Invalid input"

        if rentedDate is None or dueDate is None:
            return "Invalid date(s)"

        if rentedDate > dueDate:
            return "Inconsistent dates"

        if self.__isBookRented(bookId):
            return "Book already rented"

        try:
            book = self.__bookRepo.getById(bookId)
            client = self.__clientRepo.getById(clientId)
        except Exception as re:
            return str(re)

        rental = Rental(Rental.getNextId(), book.getId(), client.getId(), rentedDate, dueDate, None)
        self.__rentalRepo.add(rental)
        self.__bookRepo.getById(bookId).setRented(True)

        self.__stats.addBookToStats(self.__bookRepo.getById(bookId))

        return ""