diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 6be6994a5..6e88643a8 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -4,7 +4,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_successful_movie(): # Arrange movie_title = MOVIE_TITLE_1 @@ -19,7 +19,7 @@ def test_create_successful_movie(): assert new_movie["genre"] == GENRE_1 assert new_movie["rating"] == pytest.approx(RATING_1) -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_title_movie(): # Arrange movie_title = None @@ -32,7 +32,7 @@ def test_create_no_title_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_genre_movie(): # Arrange movie_title = "Title A" @@ -45,7 +45,7 @@ def test_create_no_genre_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_rating_movie(): # Arrange movie_title = "Title A" @@ -58,7 +58,7 @@ def test_create_no_rating_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_user_watched(): # Arrange movie = { @@ -79,7 +79,7 @@ def test_adds_movie_to_user_watched(): assert updated_data["watched"][0]["genre"] == GENRE_1 assert updated_data["watched"][0]["rating"] == RATING_1 -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_user_watchlist(): # Arrange movie = { @@ -100,7 +100,7 @@ def test_adds_movie_to_user_watchlist(): assert updated_data["watchlist"][0]["genre"] == GENRE_1 assert updated_data["watchlist"][0]["rating"] == RATING_1 -@pytest.mark.skip() +# @pytest.mark.skip() def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -119,15 +119,22 @@ def test_moves_movie_from_watchlist_to_empty_watched(): assert len(updated_data["watchlist"]) == 0 assert len(updated_data["watched"]) == 1 - raise Exception("Test needs to be completed.") + assert updated_data["watched"][0]["title"] == MOVIE_TITLE_1 + assert updated_data["watched"][0]["genre"] == GENRE_1 + assert updated_data["watched"][0]["rating"] == RATING_1 # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange + # assign a HORR0R_1 to movie_to_watch movie_to_watch = HORROR_1 + # janes_data is a dictionary that has two key values + # watchlist + # watched + # They each have a list as the value of the keys janes_data = { "watchlist": [ FANTASY_1, @@ -143,25 +150,33 @@ def test_moves_movie_from_watchlist_to_watched(): assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 2 - raise Exception("Test needs to be completed.") + assert updated_data["watched"][1] == movie_to_watch # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_does_nothing_if_movie_not_in_watchlist(): # Arrange + # The variable movie_to_watch is assigned to HORROR_1 movie_to_watch = HORROR_1 + # the dictionary about janes_data that has two keys + # "watchlist" and "watched" janes_data = { "watchlist": [FANTASY_1], "watched": [FANTASY_2] } # Act + # name of the person janes_data and the name of the movie "Non-Existent Movie Title") updated_data = watch_movie(janes_data, "Non-Existent Movie Title") # Assert assert len(updated_data["watchlist"]) == 1 assert len(updated_data["watched"]) == 1 + + # Is this checking for none of the varaibles are iny the updated dictionary + # checks if movie_to_watch variable is not in updated_data["watchlist"] assert movie_to_watch not in updated_data["watchlist"] + # checks if movie_to_watch variable is not in updated_data["watched"] assert movie_to_watch not in updated_data["watched"] diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 3a588299e..198e395b3 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_calculates_watched_average_rating(): # Arrange janes_data = clean_wave_2_data() @@ -14,7 +14,7 @@ def test_calculates_watched_average_rating(): assert average == pytest.approx(3.58333) assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_empty_watched_average_rating_is_zero(): # Arrange janes_data = { @@ -27,7 +27,7 @@ def test_empty_watched_average_rating_is_zero(): # Assert assert average == pytest.approx(0.0) -@pytest.mark.skip() +# @pytest.mark.skip() def test_most_watched_genre(): # Arrange janes_data = clean_wave_2_data() @@ -39,7 +39,7 @@ def test_most_watched_genre(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_genre_is_None_if_empty_watched(): # Arrange janes_data = { diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 046429360..692d874ea 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_my_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -16,7 +16,7 @@ def test_my_unique_movies(): assert INTRIGUE_2 in amandas_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_my_not_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -28,7 +28,7 @@ def test_my_not_unique_movies(): # Assert assert len(amandas_unique_movies) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -43,10 +43,11 @@ def test_friends_unique_movies(): assert FANTASY_4 in friends_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = clean_wave_3_data() + # amandas_data in dictionary "friends" in first friend added a movie to watched list amandas_data["friends"][0]["watched"].append(INTRIGUE_3) # Act @@ -54,13 +55,12 @@ def test_friends_unique_movies_not_duplicated(): # Assert assert len(friends_unique_movies) == 3 + assert INTRIGUE_3 in friends_unique_movies + assert HORROR_1 in friends_unique_movies + assert FANTASY_4 in friends_unique_movies - raise Exception("Test needs to be completed.") - # ************************************************************************************************* - # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** - # ************************************************************************************************** -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_not_unique_movies(): # Arrange amandas_data = { diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 499669077..7524dc3d5 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_get_available_friend_rec(): # Arrange amandas_data = clean_wave_4_data() diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..9984e5d72 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,23 +1,144 @@ # ------------- WAVE 1 -------------------- +from distutils.file_util import move_file +from pickle import FALSE + + def create_movie(title, genre, rating): - pass + new_movie = {} + if title == None or genre == None or rating == None: + return None + else: + new_movie["title"] = title + new_movie["genre"] = genre + new_movie["rating"] = rating + + return new_movie + +def add_to_watched(user_data, movie): + user_data["watched"].append(movie) + return user_data + +def add_to_watchlist(user_data, movie): + user_data["watchlist"].append(movie) + return user_data + +def watch_movie(user_data, title): + + if user_data["watchlist"] == None: + return user_data + else: + movie_to_move = None + # dict_movie name of each dictionary in "watchlist" + for dict_movie in user_data["watchlist"]: + # if the tittle in that dictionary evaluate to the same then do the following + if title == dict_movie["title"]: + # create a new varaible it becomes none when user_data["watchlist"] is removed + movie_to_move = dict_movie + # need to add this to a diffrent dictionary + # error here because condition needs to be true + if movie_to_move: + user_data["watched"].append(movie_to_move) + user_data["watchlist"].remove(movie_to_move) + return user_data # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + + all_ratings_added = 0 + if user_data["watched"] == []: + return 0 + for movie in user_data["watched"]: + rating = 0 + rating = movie["rating"] + all_ratings_added += rating + + average_rating = all_ratings_added/len(user_data["watched"]) + return average_rating + +def get_most_watched_genre(user_data): + genres_map = {} + for movie in user_data["watched"]: + if movie["genre"] not in genres_map: + genres_map[movie["genre"]] = 1 + else: + genres_map[movie["genre"]] += 1 + + maximum_key = None + maximum_value = 0 + for genre, quanity in genres_map.items(): + if quanity > maximum_value: + maximum_value = quanity + maximum_key = genre + return maximum_key + # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- - +def get_unique_watched(user_data): + # # compare movies of friends with user + # # create a list of dictionaries of the movies that have not been seen by the friends + # # return the list of dictionaries that friends have not watched + + friends_movies = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + friends_movies.append(movie["title"]) + + movie_list = [] + for movie in user_data["watched"]: + if movie["title"] not in friends_movies: + movie_list.append(movie) + + return movie_list + +def get_friends_unique_watched(user_data): + movie_list = [] + for movie in user_data["watched"]: + movie_list.append(movie["title"]) + + friends_movies = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + if movie["title"] not in movie_list: + if movie not in friends_movies: + friends_movies.append(movie) + return friends_movies # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + # user has access to + # iterate over subscriptions access a string + movie_list = [] + for movie in user_data["watched"]: + movie_list.append(movie["title"]) + + for subscription in user_data["subscriptions"]: + pass + # each friend has watched list + + friends_movies = [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + for host in movie["host"]: + if movie["title"] not in movie_list: + if movie not in friends_movies: + if host in movie_list: + friends_movies.append(movie) + + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- + + + +