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_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])
class TestRental(TestCase): 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 tearDown(self): self.rental = None self.clientRepo = None self.movieRepo = None 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 test_setWrongId(self): self.assertRaises(ValueError, lambda: self.rental.setRentalId(-3)) self.assertRaises(ValueError, lambda: self.rental.setRentalId(5.5)) self.assertRaises(ValueError, lambda: self.rental.setRentalId("dasas")) self.assertRaises(ValueError, lambda: self.rental.setRentalId([])) self.assertRaises(ValueError, lambda: self.rental.setRentalId({})) self.assertRaises(ValueError, lambda: self.rental.setRentalId((5, 3))) def test_setRentalIdSecondTime(self): self.rental.setRentalId(5) with self.assertRaises(AlreadySetException): self.rental.setRentalId(9) def test_setRentalId(self): with self.assertRaises(ValueError): self.rental.setRentalId(-9) with self.assertRaises(ValueError): self.rental.setRentalId("dsaa") self.rental.setRentalId(5) self.assertEqual(self.rental.getId(), 5, "rental id set wrong") 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_setReturnedDateSecondTime(self): self.rental.setReturnedDate(Date(22, 4, 1996)) with self.assertRaises(AlreadySetException): self.rental.setReturnedDate(Date(22, 4, 1996))