diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index c033af09f..06ea87148 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() + def test_create_successful_movie(): # Arrange movie_title = MOVIE_TITLE_1 @@ -15,11 +15,11 @@ def test_create_successful_movie(): new_movie = create_movie(movie_title, genre, rating) # Assert - assert new_movie["title"] is MOVIE_TITLE_1 - assert new_movie["genre"] is GENRE_1 + assert new_movie["title"] == MOVIE_TITLE_1 + assert new_movie["genre"] == GENRE_1 assert new_movie["rating"] == pytest.approx(RATING_1) -@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() + 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() + 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 = { @@ -75,11 +75,11 @@ def test_adds_movie_to_user_watched(): # Assert assert len(updated_data["watched"]) is 1 - assert updated_data["watched"][0]["title"] is MOVIE_TITLE_1 - assert updated_data["watched"][0]["genre"] is GENRE_1 - assert updated_data["watched"][0]["rating"] is RATING_1 + 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 -@pytest.mark.skip() +#@pytest.mark.skip() def test_adds_movie_to_user_watchlist(): # Arrange movie = { @@ -96,11 +96,11 @@ def test_adds_movie_to_user_watchlist(): # Assert assert len(updated_data["watchlist"]) is 1 - assert updated_data["watchlist"][0]["title"] is MOVIE_TITLE_1 - assert updated_data["watchlist"][0]["genre"] is GENRE_1 - assert updated_data["watchlist"][0]["rating"] is RATING_1 + assert updated_data["watchlist"][0]["title"] == MOVIE_TITLE_1 + 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 = { @@ -118,12 +118,15 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert assert len(updated_data["watchlist"]) is 0 assert len(updated_data["watched"]) is 1 - + # ******************************************************************************************* + 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 movie_to_watch = HORROR_1 @@ -140,13 +143,15 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) is 1 - assert len(updated_data["watched"]) is 2 - + assert len(updated_data["watched"]) == 2 + # ******************************************************************************************* + assert updated_data["watched"][1] == HORROR_1 + # ******************************************************************************************* # ****** 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 movie_to_watch = HORROR_1 diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 3a588299e..36b504008 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 7c42a63c4..d7e92b73d 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(): # Arrange 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,7 +43,7 @@ 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() @@ -54,12 +54,15 @@ def test_friends_unique_movies_not_duplicated(): # Arrange 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 # ************************************************************************************************* # ****** 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 72888410f..8bb8958d4 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() @@ -16,7 +16,7 @@ def test_get_available_friend_rec(): assert FANTASY_4b in recommendations assert amandas_data == clean_wave_4_data() -@pytest.mark.skip() +#@pytest.mark.skip() def test_no_available_friend_recs(): # Arrange amandas_data = { diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index 8ce5b57db..66af5e88b 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +#@pytest.mark.skip() def test_new_genre_rec(): # Arrange sonyas_data = clean_wave_5_data() @@ -17,7 +17,7 @@ def test_new_genre_rec(): assert FANTASY_4b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() +#@pytest.mark.skip() def test_new_genre_rec_from_empty_watched(): # Arrange sonyas_data = { @@ -38,7 +38,7 @@ def test_new_genre_rec_from_empty_watched(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +#@pytest.mark.skip() def test_new_genre_rec_from_empty_friends(): # Arrange sonyas_data = { @@ -52,12 +52,19 @@ def test_new_genre_rec_from_empty_friends(): } ] } + # ********************************************************************* + #Act + genre_recomend = get_new_rec_by_genre(sonyas_data) + #Assert + + assert len(genre_recomend)==0 + assert genre_recomend == [] # ********************************************************************* # ****** Complete the Act and Assert Portions of theis tests ********** # ********************************************************************* -@pytest.mark.skip() +#@pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange sonyas_data = clean_wave_5_data() @@ -71,7 +78,7 @@ def test_unique_rec_from_favorites(): assert INTRIGUE_2b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() +#@pytest.mark.skip() def test_unique_from_empty_favorites(): # Arrange sonyas_data = { @@ -83,7 +90,8 @@ def test_unique_from_empty_favorites(): { "watched": [INTRIGUE_2b,HORROR_1b] } - ] + ]#, +# "subscriptions":[] } # Act @@ -92,7 +100,7 @@ def test_unique_from_empty_favorites(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +#@pytest.mark.skip() def test_new_rec_from_empty_friends(): # Arrange sonyas_data = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..8a773e963 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,23 +1,134 @@ # ------------- WAVE 1 -------------------- +import pdb def create_movie(title, genre, rating): - pass + new_movie = {"title": title, + "genre": genre, + "rating": rating + } + if title is None or genre is None or rating is None: + return None + 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): + for movie in user_data["watchlist"]: + if movie["title"] == title: + user_data["watchlist"].remove(movie) + user_data["watched"].append(movie) + + return user_data # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + rating_list=[] + if user_data["watched"] == []: + return 0 + else: + for movie in user_data["watched"]: + rating_list.append(movie["rating"]) + return sum(rating_list)/len(rating_list) + +def get_most_watched_genre(user_data): + genre_count={} + if user_data["watched"] == []: + return None + else: + for movie in user_data["watched"]: + if movie["genre"] not in genre_count.keys(): + genre_count[movie["genre"]]=1 + else: + genre_count[movie["genre"]]+=1 + inverse = [(value, key) for key, value in genre_count.items()] + return max(inverse)[1] + # took this line from https://stackoverflow.com/questions/268272/getting-key-with-maximum-value-in-dictionary / + # # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +def get_unique_watched(user_data): + unique_watched = [] + all_watched = set() + + for friend in user_data["friends"]: + for movie in friend["watched"]: + all_watched.add(movie["title"]) + + for movie in user_data["watched"]: + if movie["title"] not in all_watched: + unique_watched.append(movie) + + return unique_watched +def get_friends_unique_watched(user_data): + watched_friends = [] + unique_watched_friends =[] + + for friend in user_data["friends"]: + for movie in friend["watched"]: + watched_friends.append(movie) + for movie in watched_friends: + if movie not in user_data["watched"] and movie not in unique_watched_friends: + unique_watched_friends.append(movie) + + return unique_watched_friends + + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + rec_movies=[] + if user_data["watched"]==[]: + return [] + for friend in user_data["friends"]: + for movie in friend["watched"]: + if movie not in user_data["watched"] and movie["host"] in user_data["subscriptions"]: + rec_movies.append(movie) + return rec_movies + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + + rec_movies = get_available_recs(user_data) + genre = get_most_watched_genre(user_data) + rec_movies_genre = [] + + for movie in rec_movies: + if movie["genre"] == genre: + rec_movies_genre.append(movie) + return rec_movies_genre + +def get_rec_from_favorites(user_data): + rec_movies_user = [] + favorites = [] + watched_by_friends=[] + for movie in user_data["favorites"]: + favorites.append(movie) + for friend in user_data["friends"]: + for movie in friend["watched"]: + watched_by_friends.append(movie) + for movie in watched_by_friends: + if movie in favorites: + favorites.remove(movie) + return favorites