def test_repo_movie(self): repo = Repo_movie() assert (repo.number_of_elements() == 0) repo.add(self.__movie) assert (repo.number_of_elements() == 1) keymovie = Movie(self.__movie.get_movieid(), None, None, None) findmovie = repo.search(keymovie) assert (findmovie.get_title() == self.__movie.get_title()) self.__movie_dif_title_same_id = Movie( 1, "Home Alone", "The eight year old Kevin McCaliister is mistakenly left behind by him family.", "comedy film") try: repo.add(self.__movie_dif_title_same_id) assert (False) except RepoError as re: assert (str(re) == "Existing id!\n") self.__inexisting_student = Movie( 21, "Home Alone", "The eight year old Kevin McCaliister is mistakenly left behind by him family.", "comedy film") try: repo.search(self.__inexisting_student) assert (False) except RepoError as re: assert (str(re) == "Inexisting id!\n") movie = Movie(None, None, None, None) movies = repo.get_all() self.__repo = repo
def test_validator_movie(self): validMovie = Validator_movie() self.__movie = Movie( 1, "The Lord of the Rings", "The story of the hobbit Frodo Baggins in a fictional word.", "epic fantasy adventure film") validMovie.validate_movie(self.__movie) self.__movie2 = Movie( -2, "Home Alone", "The eight year old Kevin McCaliister is mistakenly left behind by him family.", "comedy film") try: validMovie.validate_movie(self.__movie2) assert (False) except ValidError as val: assert (str(val) == "Invalid id!\n") self.__movie3 = Movie(1, "The Lord of the Rings", "", "epic fantasy adventure film") try: validMovie.validate_movie(self.__movie3) assert (False) except ValidError as val: assert (str(val) == "Invalid description!\n") self.__movie4 = Movie( 1, "The Lord of the Rings", "The story of the hobbit Frodo Baggins in a fictional word.", "") try: validMovie.validate_movie(self.__movie4) assert (False) except ValidError as val: assert (str(val) == "Invalid genre!\n") self.__validMovie = validMovie
def testMovie(self): self.assertTrue(self.mov == Movie( 1, "Bla Bla", "Don't watch it with your mother.", "Drama")) self.assertTrue(self.mov2 == Movie(2, "Bla Bla", "Dont", "Action")) self.assertTrue( self.mov.description == "Don't watch it with your mother.") self.assertTrue(self.mov.id == 1) self.assertTrue(self.mov2.genre == "Action")
def update_movie_element(self,movied,title,description,genre): """ this function update a movie element then the movie element is verificated if it is a good one then it is updated otherwise an error is displayed """ movie=Movie(movied,title,description,genre) self.__valid.validate_movie(movie) movie3=Movie(movied,title,description,genre) movie2=self.__repo.search(movie3) self.__repo.update(movie)
def add_rent(self, rentid, movieid, clientid, rented_date, due_date, returned_date): rent = Rent(rentid, movieid, clientid, rented_date, due_date, returned_date) clientidd = Client(clientid, None) self.__repoClient.search(clientidd) movieid = Movie(movieid, None, None, None) self.__repoMovie.search(movieid) clients = [] l = self.__repoRent.get_all() for i in range(len(l)): if l[i].get_clientid() == rent.get_clientid(): clients.append(l[i]) movies = [] l = self.__repoRent.get_all() for i in range(len(l)): if l[i].get_movieid() == rent.get_movieid(): movies.append(l[i]) self.__validRent.validate_rent(rent, movies, clients) self.__repoRent.add(rent) rent = copy.deepcopy(rent) action = UndoAction(self.__repoRent.remove, self.__repoRent.add, rent, None) self.__undoActions.push(action) self.__redoActions.clear()
def moviesInitialize(self): movieRepo = Repository() movieTitles = [ "The Godfather", "The Shawshank Redemption", "Schindler's List", "Raging Bull", "Casablanca", "Citizen Kane", "Gone with the Wind", "The Wizard of Oz ", "One Flew Over the Cuckoo's Nest" ] descriptionList = [ "Sure! Why not?", "Yea boi", "Best movie.", "Don't watch it with your mother", "18+", "1/10", "Do not recommend", "5/10", "Cry by yourself" ] genreMovies = ["Drama", "Comedy", "Horror", "Action", "SF"] i = 0 while i <= 100: movieRepo.add( Movie( ((i * 5 + 1 + i % 2 + 3) // 2), random.choice(movieTitles), random.choice(descriptionList), random.choice(genreMovies))) #print(movieRepo._list[i]) i += 1 return movieRepo
def search_movie_by_id(self, movid): """ this function search a movie element if the movie element exists then it is returned otherwise an error message is displayed """ movie = Movie(movid, None, None, None) return self.__repo.search(movie)
def remove_movie_element(self,idmovie): """ this function remove a movie element then the movie element is verificated if it is a good one then it is removed from list otherwise an error is displayed """ movie=Movie(idmovie,None,None,None) movie2=self.__repo.search(movie) self.__repo.remove(movie)
def add_movie_element(self,movie_id,title,description,genre): """ this function create a movie element then the movie element is verificated if it is a good one then it is added to list otherwise an error is displayed """ movie=Movie(movie_id,title,description,genre) self.__valid.validate_movie(movie) self.__repo.add(movie)
def random_movie(self,x): t=["The Hobbit","Avengers","Robinson Crusoe","Spider-Man","Divergent","A Star is born","The Maze Runner"] d=["amazing","awesome","captivating","boring","interesting"] g=["adventure movie","sf movie","romantic movie","horror movie","dystopian world"] for i in range(x): movie_id=random.randint(1,1000) title=t[random.randint(0,int(len(t))-1)] description=d[random.randint(0,int(len(d))-1)] genre=g[random.randint(0,int(len(g))-1)] movie=Movie(movie_id,title,description,genre) self.__repo.add(movie)
def remove_movie_element(self, idmovie): """ this function remove a movie element then the movie element is verificated if it is a good one then it is removed from list otherwise an error is displayed """ movie = Movie(idmovie, None, None, None) movie2 = self.__repo.search(movie) self.__repo.remove(movie) action = UndoAction(self.__repo.add, self.__repo.remove, movie2, None) self.__undoActions.push(action) self.__redoActions.clear()
def add_movie_element(self, movie_id, title, description, genre): """ this function create a movie element then the movie element is verificated if it is a good one then it is added to list otherwise an error is displayed """ movie = Movie(movie_id, title, description, genre) self.__valid.validate_movie(movie) self.__repo.add(movie) action = UndoAction(self.__repo.remove, self.__repo.add, movie, None) self.__undoActions.push(action) self.__redoActions.clear()
class Test(object): def __int__(self): pass def test_create_movie(self): movie = Movie( 1, "The Lord of the Rings", "The story of the hobbit Frodo Baggins in a fictional word.", "epic fantasy adventure film") assert (movie.get_movieid() == 1) assert (movie.get_title() == "The Lord of the Rings") assert (movie.get_description() == "The story of the hobbit Frodo Baggins in a fictional word.") assert (movie.get_genre() == "epic fantasy adventure film") movie.set_movieid(3) assert (movie.get_movieid() == 3) movie.set_title("Avengers") assert (movie.get_title() == "Avengers") movie.set_description( "The members of the Avengers attempt to reverse the damage caused by Thanos." ) assert ( movie.get_description() == "The members of the Avengers attempt to reverse the damage caused by Thanos." ) movie.set_genre("superhero film") assert (movie.get_genre() == "superhero film") self.__movie = movie def test_validator_movie(self): validMovie = Validator_movie() self.__movie = Movie( 1, "The Lord of the Rings", "The story of the hobbit Frodo Baggins in a fictional word.", "epic fantasy adventure film") validMovie.validate_movie(self.__movie) self.__movie2 = Movie( -2, "Home Alone", "The eight year old Kevin McCaliister is mistakenly left behind by him family.", "comedy film") try: validMovie.validate_movie(self.__movie2) assert (False) except ValidError as val: assert (str(val) == "Invalid id!\n") self.__movie3 = Movie(1, "The Lord of the Rings", "", "epic fantasy adventure film") try: validMovie.validate_movie(self.__movie3) assert (False) except ValidError as val: assert (str(val) == "Invalid description!\n") self.__movie4 = Movie( 1, "The Lord of the Rings", "The story of the hobbit Frodo Baggins in a fictional word.", "") try: validMovie.validate_movie(self.__movie4) assert (False) except ValidError as val: assert (str(val) == "Invalid genre!\n") self.__validMovie = validMovie def test_repo_movie(self): repo = Repo_movie() assert (repo.number_of_elements() == 0) repo.add(self.__movie) assert (repo.number_of_elements() == 1) keymovie = Movie(self.__movie.get_movieid(), None, None, None) findmovie = repo.search(keymovie) assert (findmovie.get_title() == self.__movie.get_title()) self.__movie_dif_title_same_id = Movie( 1, "Home Alone", "The eight year old Kevin McCaliister is mistakenly left behind by him family.", "comedy film") try: repo.add(self.__movie_dif_title_same_id) assert (False) except RepoError as re: assert (str(re) == "Existing id!\n") self.__inexisting_student = Movie( 21, "Home Alone", "The eight year old Kevin McCaliister is mistakenly left behind by him family.", "comedy film") try: repo.search(self.__inexisting_student) assert (False) except RepoError as re: assert (str(re) == "Inexisting id!\n") movie = Movie(None, None, None, None) movies = repo.get_all() self.__repo = repo def test_service_movie(self): repoMovie = Repo_movie() validMovie = Validator_movie() self.__serv = Construct_Movie(validMovie, repoMovie) assert (self.__serv.all_movies() == 0) self.__serv.add_movie_element( 1, "The Lord of the Rings", "The story of the hobbit Frodo Baggins in a fictional word.", "epic fantasy adventure film") assert (self.__serv.all_movies() == 1) movie = self.__serv.search_movie_by_id(1) assert (movie.get_title() == "The Lord of the Rings") assert (movie.get_description() == "The story of the hobbit Frodo Baggins in a fictional word.") assert (movie.get_genre() == "epic fantasy adventure film") try: self.__serv.add_movie_element(-2, "", "Description", "action") assert (False) except ValidError as val: assert (str(val) == "Invalid id!\nInvalid title!\n") try: self.__serv.add_movie_element(1, "Zlatan", "The story of Zlatan.", "action film") assert (False) except RepoError as re: assert (str(re) == "Existing id!\n") try: self.__serv.update_movie_element(2, "Zlatan", "The story of Zlatan.", "action film") assert (False) except RepoError as re: assert (str(re) == "Inexisting id!\n") self.__serv.update_movie_element(1, "Zlatan", "The story of Zlatan.", "action film") assert (self.__serv.all_movies() == 1) movie = self.__serv.search_movie_by_id(1) assert (movie.get_title() == "Zlatan") assert (movie.get_description() == "The story of Zlatan.") assert (movie.get_genre() == "action film") self.__serv.remove_movie_element(1) assert (self.__serv.all_movies() == 0) try: self.__serv.remove_movie_element(1) assert (False) except RepoError as re: assert (str(re) == "Inexisting id!\n") def test_create_client(self): client_id = 22 name = "Dan" client = Client(client_id, name) assert (client.get_clientid() == 22) assert (client.get_name() == "Dan") client.set_clientid(21) assert (client.get_clientid() == 21) client.set_name("Flavius") assert (client.get_name() == "Flavius") self.__client = client def test_validator_client(self): validatorClient = Validator_client() validatorClient.validate_client(self.__client) self.__clientid = Client(-23, "Dan") self.__clientname = Client(23, "") self.__client = Client(-23, "") try: validatorClient.validate_client(self.__clientid) assert (False) except ValidError as val: assert (str(val) == "Invalid id!\n") try: validatorClient.validate_client(self.__clientname) assert (False) except ValidError as val: assert (str(val) == "Invalid name!\n") try: validatorClient.validate_client(self.__client) assert (False) except ValidError as val: assert (str(val) == "Invalid id!\nInvalid name!\n") def test_repo_client(self): repo = Repo_movie() assert (repo.number_of_elements() == 0) self.__client = Client(22, "Dan") repo.add(self.__client) assert (repo.number_of_elements() == 1) keyClient = Client(self.__client.get_clientid(), None) foundClient = repo.search(keyClient) assert (foundClient.get_name() == self.__client.get_name()) self.__clientSameid = Client(22, "Alex") try: repo.add(self.__clientSameid) assert (False) except RepoError as re: assert (str(re) == "Existing id!\n") self.__clientDifferentid = Client(10, "Alex") try: repo.search(self.__clientDifferentid) assert (False) except RepoError as re: assert (str(re) == "Inexisting id!\n") def test_service_client(self): validatorClient = Validator_client() repoClient = Repo_movie() self.__service = Construct_Client(validatorClient, repoClient) assert (self.__service.no_of_clients() == 0) clientid = 24 name = "Izabella" self.__service.add_client_element(clientid, name) assert (self.__service.no_of_clients() == 1) foundClient = self.__service.search_client_by_id(24) assert (foundClient.get_name() == "Izabella") try: self.__service.add_client_element(-33, "") assert (False) except ValidError as ve: assert (str(ve) == "Invalid id!\nInvalid name!\n") try: self.__service.add_client_element(24, "Alex") assert (False) except RepoError as re: assert (str(re) == "Existing id!\n") try: self.__service.update_client_element(2, "Claudiu") assert (False) except RepoError as re: assert (str(re) == "Inexisting id!\n") self.__service.update_client_element(24, "Dan") assert (self.__service.no_of_clients() == 1) client = self.__service.search_client_by_id(24) assert (client.get_name() == "Dan") try: self.__service.remove_client_element(2) assert (False) except RepoError as re: assert (str(re) == "Inexisting id!\n") self.__service.remove_client_element(24) assert (self.__service.no_of_clients() == 0) def run_all_tests(self): self.test_create_movie() self.test_validator_movie() self.test_repo_movie() self.test_service_movie() self.test_create_client() self.test_validator_client() self.test_repo_client() self.test_service_client()
def test_create_movie(self): movie = Movie( 1, "The Lord of the Rings", "The story of the hobbit Frodo Baggins in a fictional word.", "epic fantasy adventure film") assert (movie.get_movieid() == 1) assert (movie.get_title() == "The Lord of the Rings") assert (movie.get_description() == "The story of the hobbit Frodo Baggins in a fictional word.") assert (movie.get_genre() == "epic fantasy adventure film") movie.set_movieid(3) assert (movie.get_movieid() == 3) movie.set_title("Avengers") assert (movie.get_title() == "Avengers") movie.set_description( "The members of the Avengers attempt to reverse the damage caused by Thanos." ) assert ( movie.get_description() == "The members of the Avengers attempt to reverse the damage caused by Thanos." ) movie.set_genre("superhero film") assert (movie.get_genre() == "superhero film") self.__movie = movie
def initialize(self): self.mov = Movie(1, "Bla Bla", "Don't watch it with your mother.", "Drama") self.mov2 = Movie(2, "Bla Bla", "Dont", "Action")