def test_user_init(): user1 = User("Jenna da Cruz", "testing123") assert repr(user1) == "<User jenna da cruz>" user2 = User("", " ") assert user2.user_name is None user3 = User(42, "") assert user3.user_name is None
def load_data(data_path: str, repo: MemoryRepository): reader = MovieFileCSVReader(os.path.join(data_path, 'data1000Movies.csv')) reader.read_csv_file() for actor in reader.dataset_of_actors: repo.add_actor(actor) for movie in reader.dataset_of_movies: repo.add_movie(movie) for actor in movie.actors: for colleague in movie.actors: if not actor.check_if_this_actor_worked_with( colleague) and actor != colleague: actor.add_actor_colleague(colleague) for director in reader.dataset_of_directors: repo.add_director(director) for genre in reader.dataset_of_genres: repo.add_genre(genre) user = User(user_name="Myles Kennedy", password=generate_password_hash("123")) review = Review(repo.get_movie("Inception", 2010), "Absolutely incredible movie!", 10) repo.add_review(review) user.add_review(review) user.watchlist.add_movie(repo.get_movie("The Da Vinci Code", 2006)) user.watchlist.add_movie(repo.get_movie("Moana", 2016)) repo.add_user(user)
def test_user_watch_movie(): movie1 = Movie("Princess and The Frog", 2009) movie1.runtime_minutes = 98 user1 = User("Jenna da Cruz", "testing123") user1.watch_movie(movie1) assert user1.watched_movies == [movie1] assert user1.time_spent_watching_movies_minutes is 98
def test_user_time_spent_watching_tv_shows_property(): tv_show1 = TV_Show("Sailor Moon: Crystal", 2014) tv_show1.number_of_episode = 30 tv_show1.runtime_minutes = 23 user1 = User("Jenna da Cruz", "testing123") user1.watch_tv_show(tv_show1) assert user1.time_spent_watching_tv_shows_minutes is 690
def test_loading_of_users(empty_session): users = list() users.append(("Andrew", "1234")) users.append(("Cindy", "1111")) insert_users(empty_session, users) expected = [ User("Andrew", "1234"), User("Cindy", "999") ] assert empty_session.query(User).all() == expected
def test_user_methods(): user1 = User('Martin', 'pw12345') user2 = User('Ian', 'pw67890') user3 = User('Daniel', 'pw87465') user4 = User('Martin', 'pw1255') assert user1.__eq__(user2) == False assert user1.__eq__(user1) == True assert user1.__eq__(user4) == True assert user3.__lt__(user1) == True assert user3.__lt__(user3) == False assert user1.__lt__(user3) == False
def repository(): repo = MemoryRepository() user1 = User("Myles Kennedy", "123") user2 = User("Mark Tremonti", "456") director1 = Director("Taika Waititi") director2 = Director("Steven Speilberg") actor1 = Actor("Chris Pratt") actor2 = Actor("Emma Watson") genre1 = Genre("Comedy") genre2 = Genre("Animation") movie1 = Movie("Moana", 2016) movie2 = Movie("Ice Age", 2002) movie1.director = director1 movie2.director = director2 movie1.add_actor(actor1) movie2.add_actor(actor2) movie1.add_genre(genre1) movie2.add_genre(genre2) review1 = Review(movie1, "very nice", 9) review2 = Review(movie2, "incredible", 10) user1.add_review(review1) user2.add_review(review2) repo.add_movie(movie1) repo.add_movie(movie2) repo.add_director(director1) repo.add_director(director2) repo.add_actor(actor1) repo.add_actor(actor2) repo.add_genre(genre1) repo.add_genre(genre2) repo.add_review(review1) repo.add_review(review2) repo.add_user(user1) repo.add_user(user2) return repo
def test_start_watching(simulation): simulation.movie.runtime_minutes = 10 user1 = User("Myles Kennedy", "abcde") user2 = User("Mark Tremonti", "fghij") simulation.add_user(user1) simulation.add_user(user2) assert simulation.movie not in user1.watched_movies assert user1.time_spent_watching_movies_minutes == 0 assert simulation.movie not in user2.watched_movies assert user2.time_spent_watching_movies_minutes == 0 simulation.start_watching() assert simulation.movie in user1.watched_movies assert user1.time_spent_watching_movies_minutes == 10 assert simulation.movie in user2.watched_movies assert user2.time_spent_watching_movies_minutes == 10
def test_start_watching_with_no_movie(simulation): sim2 = MovieWatchingSimulation(42) assert sim2.movie is None user1 = User("Myles Kennedy", "abcde") user2 = User("Mark Tremonti", "fghij") sim2.add_user(user1) sim2.add_user(user2) assert len(user1.watched_movies) == 0 assert user1.time_spent_watching_movies_minutes == 0 assert len(user2.watched_movies) == 0 assert user2.time_spent_watching_movies_minutes == 0 sim2.start_watching() assert len(user1.watched_movies) == 0 assert user1.time_spent_watching_movies_minutes == 0 assert len(user2.watched_movies) == 0 assert user2.time_spent_watching_movies_minutes == 0
def test_write_review_with_no_movie(simulation): sim2 = MovieWatchingSimulation(42) assert sim2.movie is None user1 = User("Myles Kennedy", "abcde") sim2.add_user(user1) sim2.write_review(user1, "Great movie", 7) assert len(user1.reviews) == 0
def test_write_review(simulation): user1 = User("Myles Kennedy", "abcde") simulation.add_user(user1) simulation.write_review(user1, "Great movie", 7) assert user1.reviews[0].movie == Movie("Moana", 2016) assert user1.reviews[0].review_text == "Great movie" assert user1.reviews[0].rating == 7
def test_saving_of_users_with_common_username(empty_session): insert_user(empty_session, ("Andrew", "1234")) empty_session.commit() with pytest.raises(IntegrityError): user = User("Andrew", "111") empty_session.add(user) empty_session.commit()
def load_users(data_path: str, repo: MemoryRepository): users = dict() for data_row in read_csv_file(os.path.join(data_path, 'users.csv')): user = User(username=data_row[1], password=generate_password_hash(data_row[2])) repo.add_user(user) users[data_row[0]] = user return users
def test_cannot_add_review_for_non_existent_movie(in_memory_repo): movie_id = 12 review_text = "Hi this is my review" rating = 9 username = "******" password = "******" user = User(username, password) in_memory_repo.add_user(user) with pytest.raises(movies_services.NonExistentMovieException): movies_services.add_review(movie_id, review_text, rating, username, in_memory_repo)
def test_can_add_review(in_memory_repo): movie_id = 1 movie = in_memory_repo.get_movie_by_id(1) review_text = "Hi this is my review" rating = 9 username = "******" password = "******" user = User(username, password) in_memory_repo.add_user(user) movies_services.add_review(movie_id, review_text, rating, username, in_memory_repo) assert Review(username, movie, review_text, rating) in movie.reviews
def add_user(username: str, password: str, repo: AbstractRepository): # Check that the given username is available. user = repo.get_user(username) if user is not None: raise NameNotUniqueException # Encrypt password so that the database doesn't store passwords 'in the clear'. password_hash = generate_password_hash(password) # Create and store the new User, with password encrypted. user = User(username, password_hash) repo.add_user(user)
def test_get_reviews_for_movie(in_memory_repo): movie_id = 1 movie = in_memory_repo.get_movie_by_id(1) review_text = "Hi this is my review" rating = 9 username = "******" password = "******" user = User(username, password) in_memory_repo.add_user(user) movies_services.add_review(movie_id, review_text, rating, username, in_memory_repo) review_dict_list = movies_services.get_reviews_for_movie( movie_id, in_memory_repo) assert len(review_dict_list) == 1 assert review_dict_list[0]["movie"] == movie
def test_add_and_get_users(repository): assert repository.get_users() == [] repository.add_user(User("Myles Kennedy", "123")) repository.add_user(User("Mark Tremonti", "456")) repository.add_user(User("Mark Tremonti", "456")) assert repository.get_user("Myles Kennedy") == User("Myles Kennedy", "123") assert repository.get_user("Scott Phillips") is None assert repository.get_users() == [ User("Myles Kennedy", "123"), User("Mark Tremonti", "456") ]
def test_add_and_get_users(session_factory): repository = SqlAlchemyRepository(session_factory) assert repository.get_users() == [] repository.add_user(User("Brian Marshall", "123")) repository.add_user(User("Mark Tremonti", "456")) repository.add_user(User("Mark Tremonti", "456")) assert repository.get_user("Brian Marshall") == User( "Brian Marshall", "123") assert repository.get_user("Scott Phillips") is None assert repository.get_users() == [ User("Brian Marshall", "123"), User("Mark Tremonti", "456") ]
def test_user_watched_tv_shows_property(): tv_show1 = TV_Show("Sailor Moon: Crystal", 2014) user1 = User("Jenna da Cruz", "testing123") user1.watch_tv_show(tv_show1) assert user1.watched_tv_shows == [tv_show1]
def test_user_tv_show_add_review(): tv_show1 = TV_Show("Sailor Moon: Crystal", 2014) review1 = TV_Show_Review(tv_show1, "I really liked it", 9) user1 = User("Jenna da Cruz", "testing123") user1.add_tv_review(review1) assert user1.tv_show_reviews == [review1]
def test_user_review_property(): movie1 = Movie("Princess and The Frog", 2009) user1 = User("Jenna da Cruz", "testing123") review1 = Review(movie1, "I loved it", 10) user1.add_review(review1) assert user1.reviews == [review1]
def test_user_watched_movies_property(): movie1 = Movie("Princess and The Frog", 2009) user1 = User("Jenna da Cruz", "testing123") user1.watch_movie(movie1) assert user1.watched_movies == [movie1]
def test_user_password_property(): user1 = User("Jenna da Cruz", "testing123") assert user1.password == "testing123"
def test_user_user_name_property(): user1 = User("Jenna da Cruz", "testing123") assert user1.user_name == "jenna da cruz"
def test_user_false_lt_function(): user1 = User("Jenna da Cruz", "testing123") user2 = User("Jessica da Cruz", "testing1234") assert user2.__lt__(user1) is False
def test_user_lt_function(): user1 = User("Jenna da Cruz", "testing123") user2 = User("Jessica da Cruz", "testing1234") assert user1.__lt__(user2) is True
def test_user_eq_function(): user1 = User("Jenna da Cruz", "testing123") user2 = User("Jenna da Cruz", "testing 123") assert user1.__eq__(user2) is True
def test_user_tv_show_review_property(): tv_show1 = TV_Show("Sailor Moon: Crystal", 2014) user1 = User("Jenna da Cruz", "testing123") review1 = TV_Show_Review(tv_show1, "I loved it", 10) user1.add_tv_review(review1) assert user1.tv_show_reviews == [review1]
def test_user_add_review(): movie1 = Movie("Princess and The Frog", 2009) review1 = Review(movie1, "I really liked it", 9) user1 = User("Jenna da Cruz", "testing123") user1.add_review(review1) assert user1.reviews == [review1]