def setUp(self): self.movieRepo = MovieRepo() self.movieRepo.addMovie(MovieDAO("Titanic", "lovely", "Romance")) self.clientRepo = ClientRepo() self.clientRepo.addClient(ClientDAO("dani")) self.rental = RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo)
def test_updateRental(self): rental = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) self.rentalBinaryRepository.addRental(rental) self.rentalBinaryRepository.updateRentalWithId(0, RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2021))) testRental1 = RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2021)) testRental1.setRentalId(0) self.assertEqual(self.rentalBinaryRepository.getList(), [testRental1])
def setUp(self): self.movieRepo = MovieRepo() self.movieRepo.addMovie(MovieDAO("Titanic", "lovely", "Romance")) self.movieRepo.addMovie(MovieDAO("Avatar", "lovely1", "Romance1")) self.movieRepo.addMovie(MovieDAO("TestMovie", "lovely1", "Romance1")) self.movieRepo.addMovie(MovieDAO("Titanic", "lovely", "Romance")) self.movieRepo.addMovie(MovieDAO("Avatar", "lovely1", "Romance1")) self.movieRepo.addMovie(MovieDAO("TestMovie", "lovely1", "Romance1")) self.clientRepo = ClientRepo() self.clientRepo.addClient(ClientDAO("dani")) self.clientRepo.addClient(ClientDAO("ancu")) self.clientRepo.addClient(ClientDAO("dani1")) self.clientRepo.addClient(ClientDAO("ancu1")) self.clientRepo.addClient(ClientDAO("dani2")) self.clientRepo.addClient(ClientDAO("ancu2")) self.rentalRepo = RentalRepo() self.rentalRepo.addRental( RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo)) self.rentalRepo.addRental( RentalDAO(1, 1, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo)) self.printer = Printer() self.constants = Constants() self.rentalController = RentalController(self.rentalRepo)
def test_addRental(self): rental0 = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) rental0.setReturnedDate(Date(5, 7, 55555)) self.rentalBinaryRepository.addRental(rental0) rental = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) rental.setRentalId(2) self.rentalBinaryRepository.addRentalWithId(rental) rental2 = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) rental2.setRentalId(1) rental2.setReturnedDate(Date(5, 7, 55555)) self.rentalBinaryRepository.addRentalWithId(rental2) self.assertEqual(len(self.rentalBinaryRepository.getList()), 3) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(0)).getId(), 0) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(0)).getMovieId(), 2) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(0)).getClientId(), 1) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(0)).getRentedDate(), Date(5, 4, 2018)) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(0)).getDueDate(), Date(7, 9, 2020)) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(0)).getReturnedDate(), Date(5, 7, 55555)) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(2)).getId(), 2) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(2)).getMovieId(), 2) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(2)).getClientId(), 1) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(2)).getRentedDate(), Date(5, 4, 2018)) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(2)).getDueDate(), Date(7, 9, 2020)) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(1)).getId(), 1) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(1)).getMovieId(), 2) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(1)).getClientId(), 1) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(1)).getRentedDate(), Date(5, 4, 2018)) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(1)).getDueDate(), Date(7, 9, 2020)) self.assertEqual((self.rentalBinaryRepository.getRentalWithId(1)).getReturnedDate(), Date(5, 7, 55555))
def __loadRepo(self): self.__loadFileReadMode() for line in self.__file: splitLine = line.split() rentalToAdd = RentalDAO( int(splitLine[1]), int(splitLine[2]), Date(int(splitLine[3]), int(splitLine[4]), int(splitLine[5])), Date(int(splitLine[6]), int(splitLine[7]), int(splitLine[8]))) rentalToAdd.setRentalId(int(splitLine[0])) if len(splitLine) >= 10: rentalToAdd.setReturnedDate( Date(int(splitLine[9]), int(splitLine[10]), int(splitLine[11]))) super().addRentalWithId(rentalToAdd) self.__closeFile()
def test_undoRent(self): self.undoRunner.addCommandToUndo(["rent", "1", "1", "1", "1", "2555"], self.rentalController, self.stack, "rental", self.commandsStack) self.rentalController.rentMovieByClientUntilDate(1, 1, Date(1, 1, 2555), self.movieController.getRepo(), self.clientController.getRepo()) self.assertEqual(len(self.rentalController.getRentalList()), 12) self.undoRunner.undo(self.clientController, self.movieController, self.rentalController, self.stack) self.assertEqual(len(self.rentalController.getRentalList()), 11)
def test_getList(self): rental1 = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) rental2 = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) rental3 = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) self.rentalBinaryRepository.addRental(rental1) self.rentalBinaryRepository.addRental(rental2) self.rentalBinaryRepository.addRental(rental3) self.assertEqual(self.rentalBinaryRepository.getList(), [rental1, rental2, rental3])
class TestDate(TestCase): def setUp(self): self.date = Date(5, 7, 2018) def tearDown(self): self.date = None def test_init(self): self.assertEqual(self.date.day, 5) self.assertEqual(self.date.month, 7) self.assertEqual(self.date.year, 2018) with self.assertRaises(InvalidDateFormatException): testDate = Date("sa", 5, 25) with self.assertRaises(InvalidDateFormatException): testDate = Date(2, [], 6) with self.assertRaises(InvalidDateFormatException): testDate = Date(1, 9, -75.5) with self.assertRaises(InvalidDateFormatException): testDate = Date(100, 6, 7) with self.assertRaises(InvalidDateFormatException): testDate = Date(2, 100, 7) with self.assertRaises(InvalidDateFormatException): testDate = Date(5, 6, -7) def test_equals(self): self.assertTrue(self.date == Date(5, 7, 2018)) def test_comparison(self): self.assertTrue(self.date.isBeforeDate(Date(6, 7, 2018))) self.assertTrue(self.date.isBeforeDate(Date(5, 8, 2018))) self.assertTrue(self.date.isBeforeDate(Date(5, 7, 2019))) self.assertFalse(self.date.isBeforeDate(Date(4, 7, 2018))) self.assertFalse(self.date.isBeforeDate(Date(5, 7, 202))) def test_dateDifference(self): date1 = Date(11, 7, 2015) date2 = Date(8, 7, 2015) self.assertEqual(date1.daysUntilDate(date2), 3)
def test_hasClientWithId(self): rental1 = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) rental2 = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) rental3 = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) self.rentalFileRepository.addRental(rental1) self.rentalFileRepository.addRental(rental2) self.rentalFileRepository.addRental(rental3) self.assertEqual(self.rentalFileRepository.hasRentalWithId(1), True) self.assertEqual(self.rentalFileRepository.hasRentalWithId(4), False)
def test_updateRental(self): self.rentalRepo.updateRentalWithId(0, RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2021), self.movieRepo, self.clientRepo)) testRental1 = RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2021), self.movieRepo, self.clientRepo) testRental1.setRentalId(0) testRental2 = RentalDAO(1, 1, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo) testRental2.setRentalId(1) testRentalList = [testRental1, testRental2] self.assertEqual(self.rentalRepo.getList(), testRentalList)
def test_addRental(self): self.rentalRepo.addRental(RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo)) self.assertEqual((self.rentalRepo.getList()[0]).getId(), 0) self.assertEqual((self.rentalRepo.getList()[0]).getClientId(), 0) self.assertEqual((self.rentalRepo.getList()[0]).getMovieId(), 0) self.assertEqual((self.rentalRepo.getList()[0]).getRentedDate(), Date(5, 4, 2018)) self.assertEqual((self.rentalRepo.getList()[0]).getDueDate(), Date(7, 9, 2020)) self.assertEqual((self.rentalRepo.getList()[2]).getId(), 2) self.assertEqual((self.rentalRepo.getList()[2]).getMovieId(), 2) self.assertEqual((self.rentalRepo.getList()[2]).getClientId(), 1) self.assertEqual((self.rentalRepo.getList()[2]).getRentedDate(), Date(5, 4, 2018)) self.assertEqual((self.rentalRepo.getList()[2]).getDueDate(), Date(7, 9, 2020))
def __rentMovie(self, optionInputWordList): if len(optionInputWordList) == 6: if optionInputWordList[1].isdigit(): if self.clientController.hasClientWithId(int(optionInputWordList[1])): if optionInputWordList[2].isdigit(): if self.movieController.hasMovieWithId(int(optionInputWordList[2])): if optionInputWordList[3].isdigit() and optionInputWordList[4].isdigit() and \ optionInputWordList[5].isdigit(): try: dueDate = Date(int(optionInputWordList[3]), int(optionInputWordList[4]), int(optionInputWordList[5])) except InvalidDateFormatException: print("Invalid date format") else: try: self.undoRunner.addCommandToUndo(optionInputWordList, self.rentalController, self.undoStack, "rental", self.commandsStack) self.__doRent(dueDate, optionInputWordList) except DatesNotOrderedException: print("The due date cannot be before the rental date") self.__popUndoStacks() except ClientHasMoviesNotReturnedException: print("Client #", optionInputWordList[1], "has passed due date for movies") self.__popUndoStacks() except MovieNotAvailableException: print("Movie #", optionInputWordList[2], "is not available") self.__popUndoStacks() else: print("Movie #", optionInputWordList[2], "successfully rented by client #", optionInputWordList[1], "until", str(dueDate)) else: print("wrong input") else: print("Movie with id", optionInputWordList[2], "not found") else: print("wrong input") else: print("Client with id", optionInputWordList[1], "not found") else: print("wrong input") else: print("wrong input")
def test_return(self): printer = Printer() self.rentalController.getRepo().addRental( RentalDAO(3, 4, Date(5, 4, 2012), Date(7, 9, 2013), self.movieRepo, self.clientRepo)) printer.printList(self.rentalController.getRentalList()) with self.assertRaises(MovieNotCurrentlyRentedByClientException): self.rentalController.returnMovieByClient(2, 5) self.rentalController.returnMovieByClient(1, 1) rentalTest1 = RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo) rentalTest1.setRentalId(0) rentalTest2 = RentalDAO(1, 1, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo) rentalTest2.setRentalId(1) constants = Constants() rentalTest2.setReturnedDate(constants.currentDay()) rentalTest3 = RentalDAO(3, 4, Date(5, 4, 2012), Date(7, 9, 2013), self.movieRepo, self.clientRepo) rentalTest3.setRentalId(2) self.assertEqual(self.rentalController.getRentalList(), [rentalTest1, rentalTest2, rentalTest3])
def test_init(self): self.assertEqual(self.date.day, 5) self.assertEqual(self.date.month, 7) self.assertEqual(self.date.year, 2018) with self.assertRaises(InvalidDateFormatException): testDate = Date("sa", 5, 25) with self.assertRaises(InvalidDateFormatException): testDate = Date(2, [], 6) with self.assertRaises(InvalidDateFormatException): testDate = Date(1, 9, -75.5) with self.assertRaises(InvalidDateFormatException): testDate = Date(100, 6, 7) with self.assertRaises(InvalidDateFormatException): testDate = Date(2, 100, 7) with self.assertRaises(InvalidDateFormatException): testDate = Date(5, 6, -7)
def redo(self, commandToRedo, clientController, movieController, rentalController): redoActionRunner = RedoActionRunner() if commandToRedo[0] == "rent": dueDate = Date(int(commandToRedo[3]), int(commandToRedo[4]), int(commandToRedo[5])) redoActionRunner.rent(dueDate, commandToRedo, rentalController, clientController, movieController) elif commandToRedo[0] == "return": redoActionRunner.doReturn(commandToRedo, rentalController) elif commandToRedo[0] == "add" and len(commandToRedo) == 2: redoActionRunner.addClient(commandToRedo, clientController) elif commandToRedo[0] == "remove" and commandToRedo[2] == "client": redoActionRunner.removeClient(commandToRedo, clientController, rentalController) elif commandToRedo[0] == "update" and len(commandToRedo) == 3: redoActionRunner.updateClient(commandToRedo, clientController) elif commandToRedo[0] == "add" and len(commandToRedo) == 4: redoActionRunner.addMovie(commandToRedo, movieController) elif commandToRedo[0] == "remove" and commandToRedo[2] == "movie": redoActionRunner.removeMovie(commandToRedo, movieController, rentalController) elif commandToRedo[0] == "update" and len(commandToRedo) == 5: redoActionRunner.updateMovie(commandToRedo, movieController)
def test_setReturnedDateSecondTime(self): self.rental.setReturnedDate(Date(22, 4, 1996)) with self.assertRaises(AlreadySetException): self.rental.setReturnedDate(Date(22, 4, 1996))
def test_setReturnedDate(self): with self.assertRaises(ValueError): self.rental.setReturnedDate("dfsaasd") self.rental.setReturnedDate(Date(22, 4, 1996)) self.assertEqual(self.rental.getReturnedDate(), Date(22, 4, 1996))
def test_init(self): self.assertEqual(self.rental.getMovieId(), 0) self.assertEqual(self.rental.getClientId(), 0) self.assertEqual(self.rental.getRentedDate(), Date(5, 4, 2018)) self.assertEqual(self.rental.getDueDate(), Date(7, 9, 2020)) self.assertRaises(TypeError, lambda: self.rental.getId(), 'default rental id not None') self.assertRaises(TypeError, lambda: self.rental.getReturnedDate(), 'default returned date not None') with self.assertRaises(ValueError): testRental = RentalDAO(0, "s", Date(22, 4, 1995), Date(22, 4, 1996), self.movieRepo, self.clientRepo) with self.assertRaises(ValueError): testRental = RentalDAO(0, -5, Date(22, 4, 1995), Date(22, 4, 1996), self.movieRepo, self.clientRepo) with self.assertRaises(ValueError): testRental = RentalDAO([], 0, Date(22, 4, 1995), Date(22, 4, 1996), self.movieRepo, self.clientRepo) with self.assertRaises(ValueError): testRental = RentalDAO(-99, 0, Date(22, 4, 1995), Date(22, 4, 1996), self.movieRepo, self.clientRepo) with self.assertRaises(ValueError): testRental = RentalDAO(0, 0, 9, Date(22, 4, 1996), self.movieRepo, self.clientRepo) with self.assertRaises(ValueError): testRental = RentalDAO(0, 0, Date(22, 4, 1995), "date", self.movieRepo, self.clientRepo) with self.assertRaises(DatesNotOrderedException): testRental = RentalDAO(0, 0, Date(22, 4, 1995), Date(22, 4, 1994), self.movieRepo, self.clientRepo) with self.assertRaises(ObjectNotInCollectionException): testRental = RentalDAO(0, 1, Date(22, 4, 1995), Date(22, 4, 1996), self.movieRepo, self.clientRepo) with self.assertRaises(ObjectNotInCollectionException): testRental = RentalDAO(1, 0, Date(22, 4, 1995), Date(22, 4, 1996), self.movieRepo, self.clientRepo)
def currentDay(self): """ :return: current day in own Date format (day, month, year) """ return Date(self.__now.day, self.__now.month, self.__now.year)
def setUp(self): self.date = Date(5, 7, 2018)
def test_dateDifference(self): date1 = Date(11, 7, 2015) date2 = Date(8, 7, 2015) self.assertEqual(date1.daysUntilDate(date2), 3)
def populateWithFew(self, movieRepo, clientRepo): self.addRental( RentalDAO(0, 0, Date(12, 5, 2011), Date(13, 6, 2012), movieRepo, clientRepo)) self.addRental( RentalDAO(1, 1, Date(12, 5, 2012), Date(13, 6, 2019), movieRepo, clientRepo)) self.__rentalList[1].setReturnedDate(Date(12, 6, 2013)) self.addRental( RentalDAO(2, 2, Date(12, 5, 2013), Date(13, 6, 2013), movieRepo, clientRepo)) self.__rentalList[2].setReturnedDate(Date(12, 6, 2014)) self.addRental( RentalDAO(3, 3, Date(12, 5, 2014), Date(13, 6, 2014), movieRepo, clientRepo)) self.__rentalList[3].setReturnedDate(Date(12, 6, 2015)) self.addRental( RentalDAO(4, 4, Date(12, 5, 2015), Date(13, 6, 2015), movieRepo, clientRepo)) self.__rentalList[4].setReturnedDate(Date(12, 6, 2016)) self.addRental( RentalDAO(5, 5, Date(12, 5, 2016), Date(13, 6, 2016), movieRepo, clientRepo)) self.__rentalList[5].setReturnedDate(Date(12, 6, 2017)) self.addRental( RentalDAO(6, 6, Date(12, 5, 2001), Date(13, 6, 2001), movieRepo, clientRepo)) self.__rentalList[6].setReturnedDate(Date(12, 6, 2002)) self.addRental( RentalDAO(7, 7, Date(12, 5, 2002), Date(13, 6, 2002), movieRepo, clientRepo)) self.__rentalList[7].setReturnedDate(Date(12, 6, 2003)) self.addRental( RentalDAO(8, 8, Date(12, 5, 2003), Date(13, 6, 2003), movieRepo, clientRepo)) self.__rentalList[8].setReturnedDate(Date(12, 6, 2004)) self.addRental( RentalDAO(9, 9, Date(12, 5, 2004), Date(13, 6, 2004), movieRepo, clientRepo)) self.addRental( RentalDAO(10, 10, Date(12, 5, 2000), Date(13, 6, 2000), movieRepo, clientRepo)) self.__rentalList[10].setReturnedDate(Date(12, 6, 2006))
def test_equals(self): self.assertTrue(self.date == Date(5, 7, 2018))
def test_removeRental(self): rental = RentalDAO(1, 2, Date(5, 4, 2018), Date(7, 9, 2020)) rental.setRentalId(2) self.rentalFileRepository.addRentalWithId(rental) self.rentalFileRepository.removeRentalWithId(2) self.assertEqual(len(self.rentalFileRepository.getList()), 0)
def test_removeRental(self): self.rentalRepo.removeRentalWithId(1) self.assertEqual(len(self.rentalRepo.getList()), 1) testRental1 = RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo) testRental1.setRentalId(0) self.assertEqual(self.rentalRepo.getList(), [testRental1])
def test_comparison(self): self.assertTrue(self.date.isBeforeDate(Date(6, 7, 2018))) self.assertTrue(self.date.isBeforeDate(Date(5, 8, 2018))) self.assertTrue(self.date.isBeforeDate(Date(5, 7, 2019))) self.assertFalse(self.date.isBeforeDate(Date(4, 7, 2018))) self.assertFalse(self.date.isBeforeDate(Date(5, 7, 202)))
def test_rent(self): printer = Printer() with self.assertRaises(DatesNotOrderedException): self.rentalController.rentMovieByClientUntilDate( 0, 0, Date(1, 1, 1999), self.movieRepo, self.clientRepo) self.rentalController.getRepo().addRental( RentalDAO(3, 4, Date(5, 4, 2012), Date(7, 9, 2013), self.movieRepo, self.clientRepo)) printer.printList(self.rentalController.getRepo().getList()) with self.assertRaises(ClientHasMoviesNotReturnedException): self.rentalController.rentMovieByClientUntilDate( 3, 3, Date(5, 5, 2025), self.movieRepo, self.clientRepo) with self.assertRaises(MovieNotAvailableException): self.rentalController.rentMovieByClientUntilDate( 0, 4, Date(5, 5, 2025), self.movieRepo, self.clientRepo) self.rentalController.rentMovieByClientUntilDate( 5, 5, Date(5, 5, 2025), self.movieRepo, self.clientRepo) # printer.printList(self.rentalController.getRepo().getList()) rentalTest1 = RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo) rentalTest1.setRentalId(0) rentalTest2 = RentalDAO(1, 1, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo) rentalTest2.setRentalId(1) rentalTest3 = RentalDAO(3, 4, Date(5, 4, 2012), Date(7, 9, 2013), self.movieRepo, self.clientRepo) rentalTest3.setRentalId(2) rentalTest4 = RentalDAO(5, 5, self.constants.currentDay(), Date(5, 5, 2025), self.movieRepo, self.clientRepo) rentalTest4.setRentalId(3) self.assertEqual(self.rentalController.getRentalList(), [rentalTest1, rentalTest2, rentalTest3, rentalTest4]) with self.assertRaises(MovieNotAvailableException): self.rentalController.rentMovieByClientUntilDate( 5, 5, Date(5, 5, 2025), self.movieRepo, self.clientRepo)