Пример #1
0
    def testRentBook(self):
        client1 = Client(1, "Name1")
        client2 = Client(2, "Name2")

        book1 = Book(1, "Title", "Description", "Author")
        book2 = Book(2, "Title1", "Description1", "Author1")

        clientRepo = Repository()
        bookRepo = Repository()
        functions = ClientController(clientRepo, Statistics(clientRepo))
        functiom = BookController(bookRepo, Statistics(bookRepo))

        functions.addClient(client2.getId(), client2.getName())
        functions.addClient(client1.getId(), client1.getName())

        functiom.addBook(book1.getId(), book1.getTitle(), book1.getDescription(), book1.getAuthor())
        functiom.addBook(book2.getId(), book2.getTitle(), book2.getDescription(), book2.getAuthor())
        rentalRepo = Repository()
        functionsr = RentalController(bookRepo, clientRepo, rentalRepo, Statistics(rentalRepo))

        msg1 = functionsr.rentBook(book1.getId(), client1.getId(), createDateFromString("23.11.2017"), "30.11.2017")

        self.assertTrue(len(msg1) == 0)
        self.assertTrue(functionsr.getRentals()[0].getBookId() == book1.getId())
        self.assertTrue(functionsr.getRentals()[0].getClientId() == client1.getId())

        msg2 = functionsr.rentBook(book2.getId, client2.getId(), createDateFromString("20.11.2017"), "19.11.2017")
        self.assertTrue(msg2 == "Inconsistent dates")