def testSearchClient(self): self.clients = Repository() self.service = Service(self.clients, [], Repository()) self.service.addClient(["John"]) self.service.addClient(["Mike"]) self.service.addClient(["zmaili"]) self.service.addClient(["Johnny"]) result = self.service.searchClients([2, True]) self.assertEqual(result, [self.clients[2]]) self.assertEqual(len(self.clients), 4) self.assertEqual(self.clients[2], Client(2, "Mike")) result = self.service.searchClients(["john", False]) self.assertEqual(result, [self.clients[1], self.clients[4]]) self.assertEqual(len(self.clients), 4) self.assertEqual(self.clients[1], Client(1, "John")) self.assertEqual(self.clients[4], Client(4, "Johnny")) result = self.service.searchClients(["luca", False]) self.assertEqual(result, []) self.assertEqual(len(self.clients), 4) self.assertRaises(EmptyError, self.service.searchClients, ["john", True]) self.service.removeClient([2]) self.assertRaises(EmptyError, self.service.searchClients, [2, True]) result = self.service.searchClients([3, True]) self.assertEqual(result, [self.clients[3]]) self.assertEqual(len(self.clients), 3) self.assertEqual(self.clients[3], Client(3, "zmaili"))
def __init__(self, clients, movies): self.clients = clients self.movies = movies self.clientCount = len(self.clients) self.movieCount = len(self.movies) self.rentals = Repository() self.service = Service(self.clients, self.movies, self.rentals) self.val = Validator(self.clients, self.movies, self.rentals)
def __init__(self): self.__settings = Settings() if self.__settings.repoType == "memory": self.clientList = ClientListGenerator().chooseClients() self.movieList = MovieListGenerator().chooseMovies() self.rentalList = RentalListGenerator( self.clientList, self.movieList).generateList() elif self.__settings.repoType == "text": self.clientList = TextRepository(self.__settings.clients) self.movieList = TextRepository(self.__settings.movies) self.rentalList = TextRepository(self.__settings.rentals) elif self.__settings.repoType == "pickle": self.clientList = PickleRepository(self.__settings.clients) self.movieList = PickleRepository(self.__settings.movies) self.rentalList = PickleRepository(self.__settings.rentals) self.function = Service(self.clientList, self.movieList, self.rentalList) self.functionList = [ self.function.addClient, self.function.removeClient, self.function.updateClient, self.function.addMovie, self.function.removeMovie, self.function.updateMovie, self.function.getList, self.function.rentMovie, self.function.returnMovie, self.function.searchClients, self.function.searchMovies, self.function.mostActive, self.function.lateRentals, self.function.undo, self.function.redo, ] self.validate = Validator(self.clientList, self.movieList, self.rentalList) self.validatorList = [ self.validate.valAddClient, self.validate.valRemClient, self.validate.valUpdateClient, self.validate.valAddMovie, self.validate.valRemMovie, self.validate.valUpdateMovie, self.validate.valSeparator, self.validate.valRentMovie, self.validate.valReturnMovie, self.validate.valSearch, self.validate.valSearch, self.validate.valSeparator, self.validate.emptyValidator, self.validate.emptyValidator, self.validate.emptyValidator, ]
def __reset(self): self.clients = Repository() self.movies = Repository() self.rentals = Repository() self.service = Service(self.clients, self.movies, self.rentals) self.service.addClient(["John"]) self.service.addClient(["Mike"]) self.service.addClient(["Nike"]) self.service.addMovie(["Title1", "Desc1", "Genre1"]) self.service.addMovie(["Title2", "Desc2", "Genre2"]) self.service.addMovie(["Title3", "Desc3", "Genre3"])
def testUpdate(self): self.clientRepo = ClientListGenerator().chooseClients() self.lastID = self.clientRepo.ID #initially the nr of clients = ID of the last client = .ID self.service = Service(self.clientRepo, [], []) self.service.updateClient([1, "name", "Albon"]) self.service.updateClient([2, "name", "Gasly"]) self.service.updateClient([3, "name", "Kimi"]) self.service.updateClient([4, "name", "Ricciardo"]) self.service.updateClient([5, "name", "Sainz"]) self.assertEqual(len(self.clientRepo), self.lastID) self.assertEqual(self.clientRepo.ID, self.lastID) self.assertEqual(self.clientRepo[1], Client(1, "Albon")) self.assertEqual(self.clientRepo[2], Client(2, "Gasly")) self.assertEqual(self.clientRepo[3], Client(3, "Kimi")) self.assertEqual(self.clientRepo[4], Client(4, "Ricciardo")) self.assertEqual(self.clientRepo[5], Client(5, "Sainz"))
def testRent(self): self.rentals = Repository() self.service = Service(self.clients, self.movies, self.rentals) self.service.rentMovie([1, 1, date(2019, 11, 12), date(2019, 11, 15)]) self.assertTrue(self.movies[1].isRented) self.assertEqual(len(self.rentals), 1) self.assertEqual(self.rentals[1].rentDate, date(2019, 11, 12)) self.assertEqual(self.rentals[1].dueDate, date(2019, 11, 15)) self.assertEqual(self.rentals[1].clientID, 1) self.assertEqual(self.rentals[1].movieID, 1) self.service.rentMovie([2, 2, date(2019, 11, 12), date(2019, 11, 15)]) self.assertTrue(self.movies[2].isRented) self.assertEqual(len(self.rentals), 2) self.assertEqual(self.rentals[2].rentDate, date(2019, 11, 12)) self.assertEqual(self.rentals[2].dueDate, date(2019, 11, 15)) self.assertEqual(self.rentals[2].clientID, 2) self.assertEqual(self.rentals[2].movieID, 2)
def testReturn(self): self.rentals = Repository() self.service = Service(self.clients, self.movies, self.rentals) self.service.rentMovie([1, 1, date(2019, 11, 12), date(2019, 11, 15)]) self.service.rentMovie([2, 2, date(2019, 11, 12), date(2019, 11, 15)]) self.service.rentMovie([3, 3, date(2019, 11, 12), date(2019, 11, 15)]) self.service.rentMovie([4, 4, date(2019, 11, 12), date(2019, 11, 15)]) self.service.returnMovie([1, 1, 1]) self.assertFalse(self.movies[1].isRented) self.assertEqual(len(self.rentals), 4) self.assertIsNotNone(self.rentals[1].returnDate) self.service.returnMovie([3, 3, 3]) self.assertFalse(self.movies[3].isRented) self.assertEqual(len(self.rentals), 4) self.assertIsNotNone(self.rentals[3].returnDate) self.assertTrue(self.movies[2].isRented) self.assertTrue(self.movies[4].isRented)
def testSearchMovie(self): self.movies = Repository() self.service = Service([], self.movies, Repository()) self.service.addMovie(["title1", "desc1", "genre1"]) self.service.addMovie(["tiitle2", "deesc2", "geenre2"]) self.service.addMovie(["title 3", "desc 3", "genre 3"]) result = self.service.searchMovies(["title", False]) self.assertEqual(result, [self.movies[1], self.movies[3]]) self.assertEqual(len(self.movies), 3) self.assertEqual(self.movies[1], Movie(1, "title1", "desc1", "genre1")) self.assertEqual(self.movies[2], Movie(2, "tiitle2", "deesc2", "geenre2")) self.assertEqual(self.movies[3], Movie(3, "title 3", "desc 3", "genre 3")) result = self.service.searchMovies(["taitle", False]) self.assertEqual(result, []) self.assertEqual(len(self.movies), 3) self.service.removeMovie([2]) self.assertRaises(EmptyError, self.service.searchMovies, [2, True]) self.assertRaises(EmptyError, self.service.searchMovies, ["john", True]) result = self.service.searchMovies([3, True]) self.assertEqual(result, [self.movies[3]]) self.assertEqual(len(self.movies), 2) self.assertEqual(self.movies[1], Movie(1, "title1", "desc1", "genre1")) self.assertEqual(self.movies[3], Movie(3, "title 3", "desc 3", "genre 3")) result = self.service.searchMovies(["tITlE", False]) self.assertEqual(result, [self.movies[1], self.movies[3]]) self.assertEqual(len(self.movies), 2) self.assertEqual(self.movies[1], Movie(1, "title1", "desc1", "genre1")) self.assertEqual(self.movies[3], Movie(3, "title 3", "desc 3", "genre 3"))
def testAdd(self): self.movieRepo = MovieListGenerator().chooseMovies() self.movieID = self.movieRepo.ID self.service = Service([], self.movieRepo, []) self.service.addMovie(["Title1", "Desc1", "Genre1"]) self.service.addMovie(["Title2", "Desc2", "Genre2"]) self.service.addMovie(["Title3", "Desc3", "Genre3"]) self.service.addMovie(["Title4", "Desc4", "Genre4"]) self.service.addMovie(["Title5", "Desc5", "Genre5"]) self.assertEqual(len(self.movieRepo), self.movieID + 5) self.assertEqual(self.movieRepo.ID, self.movieID + 5) self.assertEqual(self.movieRepo[self.movieID + 1], Movie(self.movieID + 1, "Title1", "Desc1", "Genre1")) self.assertEqual(self.movieRepo[self.movieID + 2], Movie(self.movieID + 2, "Title2", "Desc2", "Genre2")) self.assertEqual(self.movieRepo[self.movieID + 3], Movie(self.movieID + 3, "Title3", "Desc3", "Genre3")) self.assertEqual(self.movieRepo[self.movieID + 4], Movie(self.movieID + 4, "Title4", "Desc4", "Genre4")) self.assertEqual(self.movieRepo[self.movieID + 5], Movie(self.movieID + 5, "Title5", "Desc5", "Genre5"))
def testUpdate(self): self.movieRepo = MovieListGenerator().chooseMovies() self.movieID = self.movieRepo.ID self.service = Service([], self.movieRepo, []) self.service.updateMovie([1, "title", "Title1"]) self.service.updateMovie([2, "title", "Title2"]) self.service.updateMovie([3, "title", "Title3"]) self.service.updateMovie([4, "title", "Title4"]) self.service.updateMovie([5, "title", "Title5"]) self.service.updateMovie([1, "description", "Desc1"]) self.service.updateMovie([2, "description", "Desc2"]) self.service.updateMovie([3, "description", "Desc3"]) self.service.updateMovie([4, "description", "Desc4"]) self.service.updateMovie([5, "description", "Desc5"]) self.service.updateMovie([1, "genre", "Genre1"]) self.service.updateMovie([2, "genre", "Genre2"]) self.service.updateMovie([3, "genre", "Genre3"]) self.service.updateMovie([4, "genre", "Genre4"]) self.service.updateMovie([5, "genre", "Genre5"]) self.assertEqual(len(self.movieRepo), self.movieID) self.assertEqual(self.movieRepo.ID, self.movieID) self.assertEqual(self.movieRepo[1], Movie(1, "Title1", "Desc1", "Genre1")) self.assertEqual(self.movieRepo[2], Movie(2, "Title2", "Desc2", "Genre2")) self.assertEqual(self.movieRepo[3], Movie(3, "Title3", "Desc3", "Genre3")) self.assertEqual(self.movieRepo[4], Movie(4, "Title4", "Desc4", "Genre4")) self.assertEqual(self.movieRepo[5], Movie(5, "Title5", "Desc5", "Genre5"))
def testAdd(self): self.clientRepo = ClientListGenerator().chooseClients() self.service = Service(self.clientRepo, [], []) self.lastID = self.clientRepo.ID self.service.addClient(["Hamilton"]) self.service.addClient(["Bottas"]) self.service.addClient(["Verstappen"]) self.service.addClient(["Leclerc"]) self.service.addClient(["Vettel"]) self.assertEqual(self.clientRepo.ID, self.lastID + 5) self.assertEqual(len(self.clientRepo), self.lastID + 5) self.assertEqual(self.clientRepo[self.lastID + 1], Client(self.lastID + 1, "Hamilton")) self.assertEqual(self.clientRepo[self.lastID + 2], Client(self.lastID + 2, "Bottas")) self.assertEqual(self.clientRepo[self.lastID + 3], Client(self.lastID + 3, "Verstappen")) self.assertEqual(self.clientRepo[self.lastID + 4], Client(self.lastID + 4, "Leclerc")) self.assertEqual(self.clientRepo[self.lastID + 5], Client(self.lastID + 5, "Vettel"))
class TestUndo(unittest.TestCase): clients = Repository() movies = Repository() rentals = Repository() services = Service(clients, movies, rentals) def __reset(self): self.clients.reset() self.movies.reset() self.rentals.reset() def testAddClient(self): self.__reset() self.services.addClient(["Maic"]) self.services.addClient(["Maichi"]) self.services.addClient(["Maicuta"]) self.assertEqual(len(self.clients), 3) self.services.undo([]) self.assertEqual(len(self.clients), 2) self.assertEqual(self.clients[1], Client(1, "Maic")) self.assertEqual(self.clients[2], Client(2, "Maichi")) self.services.redo([]) self.assertEqual(len(self.clients), 3) self.assertEqual(self.clients[1], Client(1, "Maic")) self.assertEqual(self.clients[2], Client(2, "Maichi")) self.assertEqual(self.clients[3], Client(3, "Maicuta")) self.assertRaises(UndoError, self.services.redo, []) self.services.undo([]) self.assertEqual(len(self.clients), 2) self.assertEqual(self.clients[1], Client(1, "Maic")) self.assertEqual(self.clients[2], Client(2, "Maichi")) self.services.addClient(["Maicq"]) self.assertRaises(UndoError, self.services.redo, []) self.services.undo([]) self.assertEqual(len(self.clients), 2) self.assertEqual(self.clients[1], Client(1, "Maic")) self.assertEqual(self.clients[2], Client(2, "Maichi")) self.services.undo([]) self.assertEqual(len(self.clients), 1) self.assertEqual(self.clients[1], Client(1, "Maic")) self.services.undo([]) self.assertEqual(len(self.clients), 0) self.assertRaises(UndoError, self.services.undo, []) def testRemoveClient(self): self.__reset() self.services.addClient(["Maic"]) self.services.addClient(["Maichi"]) self.services.addClient(["Maicuta"]) self.services.addMovie(["title", "desc", "genre"]) self.services.rentMovie([2, 1, date(2019, 11, 20), date(2019, 11, 29)]) self.services.returnMovie([2, 1, 1]) self.assertEqual(len(self.clients), 3) self.assertEqual(len(self.movies), 1) self.assertEqual(len(self.rentals), 1) self.services.removeClient([2]) self.assertEqual(len(self.clients), 2) self.assertEqual(len(self.movies), 1) self.assertEqual(len(self.rentals), 0) self.assertEqual(self.clients[1], Client(1, "Maic")) self.assertEqual(self.clients[3], Client(3, "Maicuta")) self.services.undo([]) self.assertEqual(len(self.clients), 3) self.assertEqual(len(self.movies), 1) self.assertEqual(len(self.rentals), 1) self.assertEqual(self.clients[1], Client(1, "Maic")) self.assertEqual(self.clients[2], Client(2, "Maichi")) self.assertEqual(self.clients[3], Client(3, "Maicuta")) self.services.redo([]) self.assertEqual(len(self.clients), 2) self.assertEqual(len(self.movies), 1) self.assertEqual(len(self.rentals), 0) self.assertEqual(self.clients[1], Client(1, "Maic")) self.assertEqual(self.clients[3], Client(3, "Maicuta")) self.assertRaises(UndoError, self.services.redo, []) self.services.undo([]) self.assertEqual(len(self.clients), 3) self.assertEqual(len(self.movies), 1) self.assertEqual(len(self.rentals), 1) self.assertEqual(self.clients[1], Client(1, "Maic")) self.assertEqual(self.clients[2], Client(2, "Maichi")) self.assertEqual(self.clients[3], Client(3, "Maicuta")) self.services.removeClient([1]) self.assertEqual(len(self.clients), 2) self.assertEqual(len(self.movies), 1) self.assertEqual(len(self.rentals), 1) self.assertEqual(self.clients[2], Client(2, "Maichi")) self.assertEqual(self.clients[3], Client(3, "Maicuta")) self.assertRaises(UndoError, self.services.redo, []) self.services.undo([]) self.assertEqual(len(self.clients), 3) self.assertEqual(len(self.movies), 1) self.assertEqual(len(self.rentals), 1) self.assertEqual(self.clients[1], Client(1, "Maic")) self.assertEqual(self.clients[2], Client(2, "Maichi")) self.assertEqual(self.clients[3], Client(3, "Maicuta")) self.services.redo([]) self.assertEqual(len(self.clients), 2) self.assertEqual(len(self.movies), 1) self.assertEqual(len(self.rentals), 1) self.assertEqual(self.clients[2], Client(2, "Maichi")) self.assertEqual(self.clients[3], Client(3, "Maicuta")) def testUpdateClient(self): self.__reset() self.services.addClient(["John"]) self.assertEqual(self.clients[1].name, "John") self.services.updateClient([1, "name", "Vasile"]) self.assertEqual(self.clients[1].name, "Vasile") self.services.updateClient([1, "name", "Vasileul"]) self.assertEqual(self.clients[1].name, "Vasileul") self.services.undo([]) self.assertEqual(self.clients[1].name, "Vasile") self.services.redo([]) self.assertEqual(self.clients[1].name, "Vasileul") self.services.undo([]) self.services.undo([]) self.assertEqual(self.clients[1].name, "John") self.services.updateClient([1, "name", "Ion"]) self.assertEqual(self.clients[1].name, "Ion") self.assertRaises(UndoError, self.services.redo, []) def testAddMovie(self): self.__reset() self.assertEqual(len([]), 0) self.__reset() self.assertEqual(len([]), 0) def testRemoveMovie(self): self.__reset() self.assertEqual(len([]), 0) self.__reset() self.assertEqual(len([]), 0) def testUpdateMovie(self): self.__reset() self.assertEqual(len([]), 0) self.__reset() self.assertEqual(len([]), 0) def testRentMovie(self): self.__reset() self.assertEqual(len([]), 0) self.__reset() self.assertEqual(len([]), 0) def testReturnMovie(self): self.__reset() self.assertEqual(len([]), 0) self.__reset() self.assertEqual(len([]), 0)