def test_no_first_movie_in_watchlist(self): watchlist.add_movie(Movie("Moana", 2016)) assert watchlist.first_movie_in_watchlist() == Movie( "Moana", 2016) #with_first_movie watchlist.remove_movie(Movie("Moana", 2016)) assert watchlist.first_movie_in_watchlist( ) == None #with_no_first_movie
def test_select_movie_to_watch(self): watchlist.add_movie(Movie("Moana", 2016)) assert watchlist.first_movie_in_watchlist() == Movie("Moana", 2016) assert watchlist.select_movie_to_watch(0) == Movie( "Moana", 2016) #when movie in watchlist assert watchlist.select_movie_to_watch( watchlist.size() + 2) == None #when movie not in watchlist
def _determine_class_type(self, attributes): entity = None if self._file_name == "data_files/client.json": entity = Client(int(attributes["_id"]), attributes["_name"]) elif self._file_name == "data_files/movie.json": entity = Movie(int(attributes["_id"]), attributes["_title"], attributes["_description"], attributes["_genre"]) elif self._file_name == "data_files/rental.json": entity = Rental(int(attributes["_client_id"]), int(attributes["_movie_id"]), attributes["_rented_date"], attributes["_due_date"], attributes["_returned_date"]) return entity
def test_iter_and_next(self): watchlist1 = WatchList() watchlist1.add_movie(Movie("Moana", 2016)) watchlist1.add_movie(Movie("Ice Age", 2002)) watchlist1.add_movie(Movie("Guardians of the Galaxy", 2012)) it1 = iter(watchlist1) self.assertEqual(next(it1), Movie("Moana", 2016)) self.assertEqual(next(it1), Movie("Ice Age", 2002)) self.assertEqual(next(it1), Movie("Guardians of the Galaxy", 2012)) with self.assertRaises(StopIteration): next(it1)
def add_movie(self, the_id, title, description, genre, from_undo=False): ''' Creates a movie object that will be added to the list of movies from the repository :param from_undo: False if the function eas not called from the undo option, True otherwise :param the_id: the movie id :param title: the movie title :param description: the movie description :param genre: the movie genre ''' if self.find_by_id(the_id) is not None: raise IdError("Id already exists !") self._repository.add(Movie(the_id, title, description, genre)) if not from_undo: function = FunctionCall(self.add_movie, the_id, title, description, genre, True) reverse_function = FunctionCall(self.delete_movie, the_id, True) operation = Operation(function, reverse_function) self._undo_service.record_operation(operation)
def _determine_class_type(self, attributes): entity = None if self._file_name == "data_files/client_text.txt": entity = Client(int(attributes["clientId"]), attributes["clientName"]) elif self._file_name == "data_files/movie_text.txt": entity = Movie(int(attributes["movieId"]), attributes["title"], attributes["description"], attributes["genre"]) elif self._file_name == "data_files/rental_text.txt": rented_date = datetime.strptime(attributes["rentedDate"], "%Y-%M-%d").date() due_date = datetime.strptime(attributes["dueDate"], "%Y-%M-%d").date() returned_date = datetime.strptime(attributes["returnedDate"], "%Y-%M-%d").date() entity = Rental(int(attributes["clientId"]), int(attributes["movieId"]), rented_date, due_date, returned_date) return entity
def test_create_movie(self): m = Movie(1, "Titanic", "Cry", "Drama") self.assertEqual(m.genre,"Drama") the_id = -1 with self.assertRaises(ValueError): Mv.validate_id(the_id) title = "B" with self.assertRaises(ValueError): Mv.validate_info(title) m.id = 2 self.assertEqual(m.id, 2) m.title = "Notebook" m.description = "Great movie" m.genre = "Romance" self.assertEqual(m.title, "Notebook") self.assertEqual(m.description, "Great movie") self.assertEqual(m.genre, "Romance")
def test_remove_movie_not_in_watchlist(self): watchlist.add_movie(Movie("Moana", 2016)) assert watchlist.size() == 1 watchlist.remove_movie(Movie("Parasite", 2019)) assert watchlist.size() == 1
def test_add_existing_movie_in_watchlist(self): watchlist.add_movie(Movie("Moana", 2016)) #add_new_movie_in_watchlist assert watchlist.size() == 1 watchlist.add_movie(Movie("Moana", 2016)) #add_existing_movie_in_watchlist assert watchlist.size() == 1
def test_size(self): watchlist.add_movie(Movie("Moana", 2016)) watchlist.add_movie(Movie("Ice Age", 2002)) watchlist.add_movie(Movie("Guardians of the Galaxy", 2012)) assert watchlist.size() == 3